Crypto
Nodejs๋ Single Thread๊ฐ ์๋๋ค.
crypto.pbkdf2๋ ๋ณ๋์ ์ฐ๋ ๋์์ ์๋ํ๋ค.
const crypto = require('crypto');
const startDate = Date.now();
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 1 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 2 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 3 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 4 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 5 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 6 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 7 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 8 : ', Date.now() - startDate);
});
crypto.pbkdf2('bugtype', 'javascript', 100000, 512, 'sha512', () => {
console.log('JOB 9 : ', Date.now() - startDate);
});
// ๊ฒฐ๊ณผ ( ํ์๋ ์ฟผ๋์ฝ์ด )
JOB 2 : 542
JOB 4 : 548
JOB 3 : 549
JOB 1 : 552
// ๋ค์ ์์
JOB 7 : 1077
JOB 5 : 1077
JOB 8 : 1077
JOB 6 : 1079
// ๋ค์ ์์
JOB 9 : 1584
ํ์๋ ์ฟผ๋์ฝ์ด์ CPU๋ฅผ ๊ฐ์ง๊ณ ์๋ค. ๊ทธ๋์ 4๊ฐ์ฉ ์์ ์ด ๋๋ค.
CPU๋น ํ๋์ Thread๋ฅผ ์ฌ์ฉํ๊ธฐ์ ๋ค์๊ณผ ๊ฐ์ ์๊ฐ์ด ๊ฑธ๋ ธ๋ค.
๊ทธ๋ฌ๋ฉด Thread์ ์ฌ์ด์ฆ๋ฅผ ๋ณ๊ฒฝํ ์ ์์๊น?
process.env.UV_THREADPOOL_SIZE = 8; // ์ ์ผ ์์ ์ ์ธ
์์ ๊ฐ์ ์ต์ ์ ์ค์ ๋ฐ๊ฟ ์ ์๋ค.
JOB 1 : 1222
JOB 7 : 1245
JOB 2 : 1247
JOB 3 : 1253
JOB 6 : 1255
JOB 4 : 1262
JOB 8 : 1265
JOB 5 : 1270
// ๋ค์ ์์
JOB 9 : 1747
๊ฒฐ๊ณผ๋ ์์ ๊ฐ๋ค. ๊ทผ๋ฐ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋ฉด ์๊ฒ ์ง๋ง, 1~4๋ฒ์ ์์ ์ด ์ฒ์๋ณด๋ค 2๋ฐฐ์ ์๊ฐ์ด ๊ฑธ๋ ธ๋ค.
์๋๋ฉด ํ๋์ CPU์์ 2๊ฐ์ Thread๊ฐ ๋์์ ์์ ์ ํ๊ฒ ๋๋๋ฐ ๊ทธ๋์ 2๋ฐฐ์ ์๊ฐ์ด ๊ฑธ๋ฆฌ๊ฒ ๋๋ค. ๊ทธ๋์ 1~8๋ฒ์ ์์ ์ ๋์์ ๋๋๊ฒ ๋๋ค.
Last updated
Was this helpful?