Change the application to use the cluster api
- Use the nodejs cluster API - Use the config package for configuration - Change config type to tomlpull/2/head
parent
127f9ed045
commit
456e81192c
@ -1,11 +1,11 @@
|
||||
# http server configuration
|
||||
server:
|
||||
port: 8080
|
||||
[server]
|
||||
port = 8080
|
||||
|
||||
# graphql configuration
|
||||
graphql:
|
||||
graphiql: true
|
||||
[graphql]
|
||||
graphiql = true
|
||||
|
||||
# logging configuration
|
||||
logging:
|
||||
loglevel: debug
|
||||
[logging]
|
||||
loglevel = "debug"
|
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,35 @@
|
||||
// tslint:disable:no-console
|
||||
process.env.NODE_CONFIG_DIR = __dirname + "/../config";
|
||||
import App from "./app";
|
||||
const numCPUs = require("os").cpus().length;
|
||||
import * as cluster from "cluster";
|
||||
|
||||
/**
|
||||
if (cluster.isMaster) {
|
||||
|
||||
console.log(`[CLUSTER-M] Master ${process.pid} is running`);
|
||||
cluster.settings.silent = true;
|
||||
|
||||
cluster.on("exit", (worker, code) => {
|
||||
console.error(`[CLUSTER-M] Worker ${worker.id} died! (code: ${code})`);
|
||||
console.log("[CLUSTER-M] Starting new worker");
|
||||
cluster.fork();
|
||||
});
|
||||
cluster.on("online", (worker) => {
|
||||
worker.process.stdout.on("data", (data) => {
|
||||
process.stdout.write(`[CLUSTER-${worker.id}] ${data}`);
|
||||
});
|
||||
});
|
||||
|
||||
for (let i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Async main function wrapper.
|
||||
*/
|
||||
(async () => {
|
||||
(async () => {
|
||||
const app = new App();
|
||||
await app.init();
|
||||
app.start();
|
||||
})();
|
||||
})();
|
||||
}
|
||||
|
Loading…
Reference in New Issue