후기
다른 사람이 만든 코드를 유지보수한다는게 정말 쉽지 않은 것 같다..
또 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

변경 후
pm2 monit

클러스트 모드를 이용하여 분산 처리 하고 나니 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' 카테고리의 다른 글
[모니터링] 프로메테우스 + 그라파나 모니터링 시스템 구축하기 (feat micrometer) (70) | 2024.02.14 |
---|---|
아파치 카프카(APACHE Kafka) 그게 도대체 뭔데 😤 카프카 기본 개념에 대해 알아보자 (93) | 2023.11.17 |
자주 사용하는 linux 필수 명령어 모음 (2) | 2023.07.23 |
github & Jenkins CI/CD 자동 빌드 배포 환경 구성하기 - 1 (9) | 2023.06.14 |