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?