npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

cpu-cluster

1.0.1

@yoshuawuyts

npmHomeRepoSnykSocket
Downloads:0
$ npm install cpu-cluster
DailyWeeklyMonthlyYearly

cpu-cluster stability

npm version build status test coverage downloads js-standard-style

Turn a server into a CPU bound cluster.

features:

  • create one child process per CPU core
  • share network ports
  • auto respawn when a child process dies
  • expose cluster object for low level event handlers

Installation

$ npm install cpu-cluster

Usage

const cpuCluster = require('cpu-cluster')
const http = require('http')

const cluster = cpuCluster(function () {
  http.createServer(function (req, res) {
    res.setHeader('Content-Type', 'text/plain')
    res.end('hello world')
  }).listen(8080)
})

cluster.on('connection', function (worker, addr) {
  console.log('Worker listening on ${addr.address}:${addr.port}')
})

API

cpu-cluster(opts?, server)

Create a cluster where each server is started as a separate process. Takes the following options:

  • n: amount of child process to start. Defaults to the number of CPU cores available on the machine.
  • timeout: timeout after a child process exits and a new process is started. Defaults to 100ms.

See Also

  • api/cluster

License

MIT