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
|
# http server configuration
|
||||||
server:
|
[server]
|
||||||
port: 8080
|
port = 8080
|
||||||
|
|
||||||
# graphql configuration
|
# graphql configuration
|
||||||
graphql:
|
[graphql]
|
||||||
graphiql: true
|
graphiql = true
|
||||||
|
|
||||||
# logging configuration
|
# logging configuration
|
||||||
logging:
|
[logging]
|
||||||
loglevel: debug
|
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";
|
import App from "./app";
|
||||||
|
const numCPUs = require("os").cpus().length;
|
||||||
|
import * as cluster from "cluster";
|
||||||
|
|
||||||
/**
|
if (cluster.isMaster) {
|
||||||
* Async main function wrapper.
|
|
||||||
*/
|
console.log(`[CLUSTER-M] Master ${process.pid} is running`);
|
||||||
(async () => {
|
cluster.settings.silent = true;
|
||||||
const app = new App();
|
|
||||||
await app.init();
|
cluster.on("exit", (worker, code) => {
|
||||||
app.start();
|
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 () => {
|
||||||
|
const app = new App();
|
||||||
|
await app.init();
|
||||||
|
app.start();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue