Socket
Book a DemoInstallSign in
Socket

cpu-cluster

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cpu-cluster

Turn a server into a CPU bound cluster

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

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

Keywords

cluster

FAQs

Package last updated on 08 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts