Page 119 - Nodejs 교과서 개정2판
P. 119
worker.on('error', (err) => {
throw err;
});
worker.on('exit', () => {
threads.delete(worker);
if (threads.size === 0) {
console.timeEnd('prime');
console.log(primes.length);
}
});
worker.on('message', (msg) => {
primes = primes.concat(msg);
});
}
} else {
findPrimes(workerData.start, workerData.range);
parentPort.postMessage(primes);
}
ৈؑ ѐ झۨ٘о ੌਸ աׇࢲ ܻೞѱ ೮णפ ݣ౭ झۨ٬ਸ ೡ ٸח ੌਸ աׇࢲ ܻೞب۾ ೞח ѱ ઁ
ੌ য۵णפ যځೠ ੌ ҕਬೞҊ ח ؘఠо ݆ই ੌਸ ա־ӝо য۵णפ ೯ ࣗࣻ ѐࣻܳ ҳ
ೞח স ೧ ߧਤ ࠗఠ ݅ ܳ झٜۨ٘ ੌೞѱ աׇࢲ ࣻ೯ೡ ࣻ णפ
콘솔
$ node prime-worker
prime: 1.752s
664579
ࣘبо ৈࢽ ߓ ب ࡈۄणפ ਕழ झۨ٘ܳ ৈؑ ѐ ࢎਊ೮Ҋ ೧ࢲ ৈؑ ߓ ࡈۄח Ѫ ইתפ झ
ۨ٘ܳ ࢤࢿೞҊ झۨ٘ ࢎীࢲ ాनೞח ؘ ࢚ೠ ࠺ਊ ߊࢤೞ۽ ਸ Ҋ۰೧ࢲ ݣ౭ झۨ٬ਸ ೧ঠ
פ ੜޅೞݶ ݣ౭ झۨ٬ਸ ೡ ٸ यӖ झۨ٬ࠁ ؊ ו۰ח അ࢚ب ߊࢤೡ ࣻ णפ
ীࢲח ܲ ۽ࣁझܳ ٜ݅য সೞח ߑߨਸ ঌইࠁѷणפ
DIJME@QSPDFTT
֢٘ীࢲ ܲ ۽Ӓ۔ਸ प೯ೞҊ रѢա ݺ۸যܳ ࣻ೯ೞҊ रਸ ٸ ࢎਊೞח ݽٕੑפ ݽٕਸ ా೧
ܲ য ٘ ܳ ٜݶ ॆ ܳ प೯ೞҊ ѾҞчਸ ߉ਸ ࣻ णפ ܴ DIJME@QSPDFTT ध ۽ࣁ
झ ੋ ਬח അ ֢٘ ۽ࣁझ ৻ী ࢜۽ ۽ࣁझܳ ڸਕࢲ ݺ۸ਸ ࣻ೯ೞҊ ֢٘ ۽ࣁझী Ѿҗܳ ঌ
۰ӝ ٸޙੑפ