4/29 Today I Learn

장민우·2021년 4월 29일
0
post-thumbnail

오늘 학습 내용

  • readline 모듈
  • load banlancer
  • 독서- 소프트 스킬(존 손메즈)

Readline

  • readline모듈은 한 번에 한 줄씩 Readable 스트림(예 :process.stdin)에서 데이터를 읽기위한 interface를 제공.
  • 아래는 기초적인 readline모듈을 사용하는 방법이다.
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,//Readable 스트림을 읽게 해주는 프로퍼티고 이 옵션은 필수
  output: process.stdout
});

rl.question('What do you think of Node.js?', (answer) => {
  // TODO: Log the answer in a database
  console.log(`Thank you for your valuable feedback: ${answer}`);

  rl.close();
});

rl.on('close', ()=>{
  console.log('Have a great day!');
})

'What do you think of Node.js?'라는 질문이 출력되고 값을 입력하면 콜백함수의 매개변수인 answer로 값을 받을 수 있다.

이후 console.log(~~)의 값이 출력되고

close이벤트로 console.log(~~)값 출력 후 프로세스 종료.

Load Balancer

  • 여러대의 서버에게 균일하게 트래픽을 분산시켜주는 서비스
  • Scale-up : 서버 자체의 성능을 확장
  • Scale-out : 여러대의 서버를 증설하여 일처리를 분산
    => 로드밸런싱이 반드시 필요(균일하게 트래픽을 분산해줘야함)

로드밸런싱 기법

1.라운드로빈
2.가중 라운드로빈
3.IP해시
4.최소 연결 방식
5.최소 리스폰타임


참고자료

https://nodejs.org/api/readline.html#readline_event_close
https://nodejs.org/api/process.html#process_process_stdin
https://nodejs.org/api/stream.html#stream_readable_read_size
https://nodejs.org/api/stream.html#stream_readable_setencoding_encoding
https://m.post.naver.com/viewer/postView.nhn?volumeNo=27046347&memberNo=2521903
https://nesoy.github.io/articles/2018-06/Load-Balancer

0개의 댓글