newman 을 이용하여 node 서버 부하 테스트 및 pm2 클러스트 모드 사용 / 커넥션 풀 사용하여 부하 예방하기 🐝

2024. 11. 12. 16:12·Develop/DevOps
반응형

 

 

후기 

다른 사람이 만든 코드를 유지보수한다는게 정말 쉽지 않은 것 같다..

또 java/spring boot 가 아닌 node/express 환경이다 보니 정이 더 안붙는... 😒



원인

특정 기간에 예약이 몰려 서버에 부하가 되는 상황 확인

 

 

테스트 방법

 

1. 포스트맨을 이용하여 예약 api 컬렉션 준비

2. node에 newman 종속성 추가 및 실행코드 작성

3. pm2 모니터링

 

 

const newman = require('newman'); // Newman 모듈
const instances = 900; 

const runNewmanInstance = () => {
    return new Promise((resolve, reject) => {
        newman.run({
            collection: require('./collection.json'), 
            reporters: 'cli',
        }, (err) => {
            if (err) reject(err);
            else resolve();
        });
    });
};

Promise.all(Array.from({ length: instances }, runNewmanInstance))
    .then(() => {
        console.log(`${instances}개의 컬렉션이 동시에 완료되었습니다.`);
    })
    .catch((error) => {
        console.error('오류 발생:', error);
    });

 


server.js 수정

{
	"apps" : [
    	{
            "name" : "서버이름",
            "script" : "src/server.js",
            "watch" : ["src"],
            "ignore_watch" : ["temp"],
            "watch_option" : {
            	"followSymlinks" : false
            },
	    "exec_mode" : "cluster",
            "instances" : "max"
        }
    ]
}

 

변경 전

pm2 monit

as is


변경 후 

pm2 monit

to be

클러스트 모드를 이용하여 분산 처리 하고 나니 was 부하는 줄일 수 있었으나

데이터베이스에 접근하는 행위가 있는 api는 계속 지연되는 현상이 생기는 것을 확인 ..😡

 

db를 접근할 때 커넥션을 다이렉트로 맺고 끊는 것을 확인 할 수 있었다..

이부분을 커넥션 풀을 설정하여 성능을 개선 하였다..

 

이후 앞전에 설명했던 로드 테스트용 스크립트로 수치를 늘렸을 때 as-is와 to-be 확연한 차이가 나는 것을 확인 😁

 


Ref.

pm2 docs

 

https://pm2.keymetrics.io/docs/usage/quick-start/

 

PM2 - Quick Start

Advanced process manager for production Node.js applications. Load balancer, logs facility, startup script, micro service management, at a glance.

pm2.keymetrics.io

 

postman docs

 

https://learning.postman.com/docs/getting-started/overview/

 

Get started in Postman | Postman Learning Center

Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

learning.postman.com

 

newman  docs

 

https://learning.postman.com/docs/collections/using-newman-cli/command-line-integration-with-newman/

 

Run and test collections from the command line using Newman CLI | Postman Learning Center

Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

learning.postman.com

 

커넥션 풀이란? 

https://ko.wikipedia.org/wiki/%EC%97%B0%EA%B2%B0_%ED%92%80

 

연결 풀 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 연결 풀[1] 또는 커넥션 풀(connection pool)은 소프트웨어 공학에서 데이터베이스로의 추가 요청이 필요할 때 연결을 재사용할 수 있도록 관리되는 데이터베이스

ko.wikipedia.org

 

반응형
저작자표시 비영리 (새창열림)

'Develop > DevOps' 카테고리의 다른 글

구 레거시 윈도우 서버 프로젝트 (IIS / ASP) 이관 도전기  (6) 2025.07.30
[nssm] 윈도우(window)에서 JAR 파일 서비스로 등록하기 🤡🍯🐝  (12) 2025.04.24
[모니터링] 프로메테우스 + 그라파나 모니터링 시스템 구축하기 (feat micrometer)  (70) 2024.02.14
아파치 카프카(APACHE Kafka) 그게 도대체 뭔데 😤 카프카 기본 개념에 대해 알아보자  (93) 2023.11.17
자주 사용하는 linux 필수 명령어 모음  (2) 2023.07.23
'Develop/DevOps' 카테고리의 다른 글
  • 구 레거시 윈도우 서버 프로젝트 (IIS / ASP) 이관 도전기
  • [nssm] 윈도우(window)에서 JAR 파일 서비스로 등록하기 🤡🍯🐝
  • [모니터링] 프로메테우스 + 그라파나 모니터링 시스템 구축하기 (feat micrometer)
  • 아파치 카프카(APACHE Kafka) 그게 도대체 뭔데 😤 카프카 기본 개념에 대해 알아보자
    반응형
  • 개발자는어디까지공부해야할까?
  • 전체
    오늘
    어제
    • 분류 전체보기 (51)
      • 인디해커 (1)
      • Develop (42)
        • Front-End (7)
        • Back-End (17)
        • Spring (1)
        • Tool (1)
        • DATABASE (1)
        • DevOps (7)
        • CS (3)
        • Trouble Shooting (5)
      • 다이소 (1)
        • 코딩테스트문제풀이 (1)
      • 변소 (7)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 깃허브(Github)
    • 개발 Feed
  • 공지사항

  • 인기 글

  • 태그

    mybatis
    React
    리액트
    jdk
    JavaScript
    backend
    thymeleaf
    node
    Java
    리그오브레전드
    op.gg
    spring
    셀레니움
    스프링부트
    lol
    개발자 면접
    롤
    SpringBoot
    백엔드 개발자 면접 단골 질문 뿌시기
    Recoil
    개발자
    자바
    spring boot
    github
    react-router-dom
    fow.kr
    백엔드
    Oracle
    @Scheduled
    타임리프 사용방법
  • 최근 댓글

  • 최근 글

  • 01-24 09:10
  • hELLO· Designed By정상우.v4.10.3
newman 을 이용하여 node 서버 부하 테스트 및 pm2 클러스트 모드 사용 / 커넥션 풀 사용하여 부하 예방하기 🐝
상단으로

티스토리툴바