Fixed some queue related stuff
This commit is contained in:
parent
85f38042b9
commit
7b64c4ca2a
1 changed files with 3 additions and 3 deletions
|
@ -48,14 +48,14 @@ if (isMainThread) {
|
||||||
measure = newMeasure;
|
measure = newMeasure;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
const MAX_WORKERS = process.env.WORKERS === "" ? parseInt(process.env.WORKERS) : os.cpus().length * 4; // Completely arbitrary, should usually be some multiple of your amount of cores
|
const MAX_WORKERS = process.env.WORKERS !== "" ? parseInt(process.env.WORKERS) : os.cpus().length * 4; // Completely arbitrary, should usually be some multiple of your amount of cores
|
||||||
let workingWorkers = 0;
|
let workingWorkers = 0;
|
||||||
|
|
||||||
const acceptJob = (uuid) => {
|
const acceptJob = (uuid) => {
|
||||||
workingWorkers++;
|
workingWorkers++;
|
||||||
|
queue.shift();
|
||||||
const worker = new Worker(__filename);
|
const worker = new Worker(__filename);
|
||||||
log(`Spawned worker ${uuid}`);
|
log(`Spawned worker ${uuid}`);
|
||||||
queue.shift();
|
|
||||||
worker.once("error", err => {
|
worker.once("error", err => {
|
||||||
console.error(`Error on worker ${uuid}:`, err);
|
console.error(`Error on worker ${uuid}:`, err);
|
||||||
socket.send(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.toString())]), jobs[uuid].port, jobs[uuid].addr);
|
socket.send(Buffer.concat([Buffer.from([0x2]), Buffer.from(uuid), Buffer.from(err.toString())]), jobs[uuid].port, jobs[uuid].addr);
|
||||||
|
@ -103,7 +103,7 @@ if (isMainThread) {
|
||||||
log(`Got request for job ${job.msg} with id ${uuid}`, job.threadNum);
|
log(`Got request for job ${job.msg} with id ${uuid}`, job.threadNum);
|
||||||
acceptJob(uuid);
|
acceptJob(uuid);
|
||||||
} else {
|
} else {
|
||||||
log(`Got request for job ${job.msg} with id ${uuid}, queued in position ${queue.indexOf(uuid) - 1}`, job.threadNum);
|
log(`Got request for job ${job.msg} with id ${uuid}, queued in position ${queue.indexOf(uuid)}`, job.threadNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
const newBuffer = Buffer.concat([Buffer.from([0x0]), Buffer.from(uuid)]);
|
const newBuffer = Buffer.concat([Buffer.from([0x0]), Buffer.from(uuid)]);
|
||||||
|
|
Loading…
Reference in a new issue