quick production test script
This commit is contained in:
parent
735ca3d8c6
commit
1e44c7db7a
7 changed files with 562 additions and 2 deletions
22
cluster-server.js
Normal file
22
cluster-server.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import cluster from 'cluster';
|
||||
import { cpus } from 'os';
|
||||
import { handler } from './build/handler.js';
|
||||
import express from 'express';
|
||||
|
||||
const numCPUs = cpus().length;
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
console.log(`Primary ${process.pid} spawning ${numCPUs} workers…`);
|
||||
for (let i = 0; i < numCPUs; i++) cluster.fork();
|
||||
cluster.on('exit', (w) => {
|
||||
console.warn(`Worker ${w.process.pid} died — restarting…`);
|
||||
cluster.fork();
|
||||
});
|
||||
} else {
|
||||
const app = express();
|
||||
app.use(handler);
|
||||
const port = process.env.PORT || 3000;
|
||||
app.listen(port, () =>
|
||||
console.log(`Worker ${process.pid} listening on ${port}`)
|
||||
);
|
||||
}
|
||||
Reference in a new issue