1.0.1 • Published 9 years ago

cpu-cluster v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

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

License

MIT