Socket
Book a DemoInstallSign in
Socket

@polka/cluster

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@polka/cluster

Intialize and run a HTTP cluster

latest
Source
npmnpm
Version
1.0.0-next.0
Version published
Maintainers
1
Created
Source

@polka/cluster npm

Intialize and run a HTTP cluster; not limited to Polka!

Accepts a Polka app, a programmatic Polkadot app, or any HTTP handler and runs it as a Node.js cluster.

For more information on Node.js clustering, please read How it Works :bow:

Install

$ npm install --save @polka/cluster

Usage

const polka = require('polka');
const cluster = require('@polka/cluster');
const cors = require('cors')({ origin:true });

const { PORT=3000 } = process.env;

const app = (
  polka()
    .use(cors)
    .use('/items', require('./items'))
    .get('/alive', (req, res) => {
      res.end('OK');
    })
);

cluster(app, 4).listen(PORT);

API

cluster(handler, size)

Returns: http.Server or Object

If handler was an application, then it is returned. Otherwise a new http.Server instance is returned.

handler

Type: Function or Object

The HTTP handler function to run, which will be attached to the http.Server as its requestListener.

Similarly, handler may be an Object so long as it exposes a listen method.
This means that you may pass in entire Polka, Polkadot, or Express applications!

size

Type: Number
Default: os.cpus().length

The size of the cluster. Put differently, your application will run on <size> threads.

By default, your cluster will spawn one Worker per thread. For example, "most" modern Intel-based CPUs have two threads per CPU core, meaning that a quad-core CPU will have 8 threads... making 8 the default cluster size for this example.

Important: Your size value will not exceed the value determined by require('os').cpus().length

Support

Any issues or questions can be sent to the Polka repository.
However, please specify that your inquiry is about @polka/cluster specifically.

License

MIT © Luke Edwards

FAQs

Package last updated on 10 Mar 2019

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