Skip to content

Commit

Permalink
🎈 TODO :: Socket.io Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
bifeldy committed Oct 12, 2023
1 parent e177355 commit 8ea478a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/fansubid/server/main.js

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ const mainModule = __non_webpack_require__.main;
const moduleFilename = (mainModule && mainModule.filename) || '';
if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
app().then(async (nestApp) => {
const port = process.env['PORT'] || 4200;
const numCPUs = Number.parseInt(process.env['MAX_CPUS']) || os.cpus().length;
const gs = nestApp.get(GlobalService);
if (numCPUs > 1) {
try {
if (cluster.isMaster) {
const nestCtx = await ctx();
nestCtx.get(ClusterMasterSlaveService).masterHandleMessages();
gs.log(`[APP_MASTER_PID] πŸ’»`, process.pid);
(await ctx()).get(ClusterMasterSlaveService).masterHandleMessages();
gs.log('[APP_MASTER_PID] πŸ’»', process.pid);
for (let i = 0; i < numCPUs - 1 /* 1 Master CPU */ ; i++) {
const worker = cluster.fork();
gs.log(`[WORKER_${i}] Spawned`, worker.id);
Expand All @@ -121,17 +121,17 @@ if (moduleFilename === __filename || moduleFilename.includes('iisnode')) {
gs.log(`${msg} Re-Spawned`, wrkr.id);
});
} else {
nestApp.listen(process.env['PORT'] || 4200, async () => {
gs.log(`[APP_SLAVE_PID] πŸ’˜`, process.pid);
nestApp.listen(port, async () => {
gs.log('[APP_SLAVE_PID] πŸ‘€', process.pid);
});
}
} catch (e) {
gs.log('[APP_WORKER] πŸ’’', e, 'error');
}
} else {
nestApp.listen(process.env['PORT'] || 4200, async () => {
gs.log(`[APP_BOOTSTRAP_PID] πŸ’˜`, process.pid);
nestApp.listen(port, async () => {
gs.log('[APP_BOOTSTRAP_PID] πŸ’˜', process.pid);
});
}
}).catch(err => console.error('[APP_CONTEXT] πŸ’’', err));
}).catch(err => console.error('[APP_CONTEXT] πŸ’£', err));
}

0 comments on commit 8ea478a

Please sign in to comment.