Cluster module과 PM2

00_8_3·2021년 3월 16일
0

Cluster

PM2란 무엇인가

PM2는 NodeJS의 애플리케이션 process 관리를 위해 사용됩니다.

  • 프로그램의 예상치 못한 종료 시 자동 재시작
  • 무중단 서비스
  • Cluster 모드
  • 모니터링

의 이점을 얻을 수 있다.

PM2 Cluster 모드

Cluster 모드에 대한 문서 설명에 따르면

  • 코드 수정 없이 NodeJS 애플리케이션을 CPU에 따라 확장 가능
  • 안정성과 성능을 향상
  • NodeJS의 Cluster module로 동작

결국엔 PM2 Cluster도 NodeJS Cluster module을 알아 봐야합니다.

PM2 cluster

NodeJS Cluster Module

Node 공식 문서의 설명에 따르면
Node cluster

A single instance of Node.js runs in a single thread. To take advantage of multi-core systems, the user will sometimes want to launch a cluster of Node.js processes to handle the load.
The cluster module allows easy creation of child processes that all share server ports.

The worker processes are spawned using the child_process.fork() method, so that they can communicate with the parent via IPC and pass server handles back and forth.

싱글 스레드로 실행 되는 NodeJS가 멀티 코어의 시스템을 이용하기 위해
클러스터를 사용 할 수 있고 모든 서버 포트를 공유하는 하위 프로세스를 생성한다.

그리고 이 하위 프로세스들은 child_process.fork() 메서드를 사용해서 생성되고 부모 자식간의 통신을 위한 IPC 채널을 갖고 있으며 생성된 각 프로세스는 자체 V8 인스턴스가 있습니다.

마침

정리하자면
PM2 cluster 모드도 결국엔 NodeJS cluster module에 의해서 작동하고
cluster module은 포트를 공유 할 수 있도록 Child 프로세스를 생성합니다.

0개의 댓글