MarmellataDev
article thumbnail
Published 2023. 6. 1. 17:03
NodeJS - 쓰레드 풀 Node.js

쓰레드 풀(pool) 이란, 쓰레드를 모아놓은 것으로 생각하면 된다.

요청을 하면 쓰레드를 할당하여 작업을 한다.

 

 


threadpool 사용예제

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);
})

결과

3: 2149
2: 2236
1: 2284
4: 2294
5: 4258
6: 4312
7: 4520
8: 4547

PBKDF2는 미국 NIST에서 승인받은 사용자 패스워드 기반으로 키(KEY) 유도를 하기 위한 함수 이다.

사용자 패스워드에 해시함수, 솔트(Salt), 반복 횟수 등을 지정하여 패스워드에 대한 다이제스트(Digest)를 생성하는 방식

 

 

 


이벤트

on(이벤트,콜백) 이벤트 명과 이벤트 발생 시 콜백을 연결
addListener(이벤트명, 콜백) on과 동일
emit(이벤트명) 이벤트를 호출하는 메소드
once(이벤트명, 콜백) 한번 실행되는 이벤트
removeAllListener(이벤트명) 이벤트에 연결된 모든 리스너 제거
removeListener(이벤트명, 리스터) 이벤트에 연결된 리스터 하나 제거
off(이벤트명, 콜백) = removeListener
listenerCount(이벤트 명) 현재 리스너가 몇개 연결되어 있는지 확인

 

 


 

'Node.js' 카테고리의 다른 글

NodeJS - Server  (0) 2023.06.01
NodeJS - 예외 처리  (0) 2023.06.01
NodeJS - fs - 폴더생성, 파일삭제, 파일복사  (0) 2023.06.01
NodeJS - 파이프라인  (0) 2023.06.01
NodeJS - Buffer, readStream, writeStream  (0) 2023.06.01
profile

MarmellataDev

@Marmellata

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!