1.0.0-next.0 • Published 2 months ago

@polka/cluster v1.0.0-next.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 months ago

@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

1.0.0-next.25

2 months ago

1.0.0-next.24

5 months ago

1.0.0-next.23

8 months ago

1.0.0-next.15

3 years ago

1.0.0-next.12

3 years ago

1.0.0-next.10

4 years ago

1.0.0-next.7

5 years ago

1.0.0-next.3

5 years ago

1.0.0-next.0

5 years ago