Skip to content

Commit 859e047

Browse files
committedFeb 15, 2025·
scaling worker
1 parent 382842b commit 859e047

File tree

3 files changed

+1397
-8
lines changed

3 files changed

+1397
-8
lines changed
 

‎worker/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { execShellCommand } from "./utils/execCommand.js";
55
import { codeRunner } from "./utils/codeRunner.js";
66
import { Worker } from 'bullmq'
77
import Logger from "@code_blaster/logger";
8+
import cluster from 'cluster'
9+
import os from 'os'
810

911
const worker = new Worker('code_submission', async (job) => {
1012
if (job.name == "code_langauge") {
@@ -49,4 +51,11 @@ const main = async () => {
4951
worker.run()
5052
}
5153

52-
main();
54+
if (cluster.isMaster) {
55+
const numCPUs = os.cpus().length;
56+
for (let i = 0; i < numCPUs; i++) {
57+
cluster.fork();
58+
}
59+
}else{
60+
main();
61+
}

0 commit comments

Comments
 (0)