@fibjs/cluster-server
Start a multi-thread server to take advantage of multi-core systems.
Install
1$ npm i @fibjs/cluster-server --save
Usage
server.js :
1
2
3
4
5
6
7
8
9
10
11const Cluster = require('@fibjs/C-server');
const path = require('path');
const server = new Cluster({
port: 8000,// server port,default to 8000
worker: path.join(__dirname, 'worker.js'), // full path to worker
numbers: 4,// default to cpu numbers
});
server.run(); // start server asynchronously
// server.close(); // close server
worker.js :
1
2
3module.exports = req => {
req.response.write('Hello, World!');
};
then you can start server:
1 fibjs server.js
Questions & Suggestions
Please open an issue here .