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) {
|
||||||
|
|
||||||
|
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 main function wrapper.
|
||||||
*/
|
*/
|
||||||
(async () => {
|
(async () => {
|
||||||
const app = new App();
|
const app = new App();
|
||||||
await app.init();
|
await app.init();
|
||||||
app.start();
|
app.start();
|
||||||
})();
|
})();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue