스레드풀

<aside> 💡 백그라운드에서는 동시에 몇 개까지 돌아갈까? → 노드에서는 4개

</aside>

백그라운드에서 돌아가는걸 확인하고싶으면 crypto 같은 복잡한 애를 실행해보는 것이 좋다.

const crypto = require('crypto');

const pass = 'pass';
const salt = 'salt';
const start = Date.now();

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('1:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('2:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('3:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('4:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('5:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('6:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('7:', Date.now() - start);
});

crypto.pbkdf2(pass, salt, 1000000, 128, 'sha512', () => {
  console.log('8:', Date.now() - start);
});

해보면

2: 2704
4: 2746
1: 2813
3: 3044
5: 4926
6: 4979
7: 4982
8: 5229

숫자 조합만 보아도 1 2 3 4 이렇게 그룹이 나뉘는 것을 볼 수 있고

실행되는 것을 보면 4개씩 실행이 되는 것을 확인하였다.

<aside> 💡 그런데 내 컴퓨터는 8코어인데 4개씩 하면 비효율적이지 않나?

</aside>

→

이를 위해 설정을 바꿔주는 것도 존재한다.