커넥션 풀의 종류
커넥션 풀 사용 이유 : 성능
성능향상 때문에 사용하는 커넥션 풀이지만 올바르게 설정하지 않으면 성능 저하 유발
따라서 설정과 성능의 관계
를 이해하고 있어야 함
최대 커넥션 개수 = 사용 중 커넥션 + 유휴 커넥션
한 커넥션 당 쿼리 실행 시간과 목표 TPS를 알면
최대 TPS와 동시 커넥션 개수를 계산 가능하다.
가정
계산
평균 이상으로 튀는 개수나 비율 검토해야함.
풀의 모든 커넥션이 사용 중일때, 커넥션을 구하기 위해 대기하는 시간
기본값은 무려 30초. 30초는 너무 길다.(TypeORM 기준으론 10초, 기본 풀사이즈도 10)
커넥션을 유지하는 시간이다
이 값이 관련 설정보다 크면
커넥션이 살아 있는지 확인하는 주기
풀에 유지할 최소 유휴 커넥션 개수
사용하지 않고 풀에 머무를 수 있는 시간
풀에서 이 시간동안 머무른 커넥션은 종료하고 풀에서 제거된다.
maximumPoolSize : 최대 TPS 고려
connectionTimout: 일반적인 서비스에서 길면 안됨. 무응답 시간이 매우 길어짐
maxLifeTime : 일정 시간만 끝나고 커넥션이 종료되도록 처리
keepaliveTime : 끊길 만한 시간보다 짧은 주기로 검사
minimumIdle : 유휴 커넥션은 최대 연결수에서 제외하는 것을 추천함
idleTimeout : 풀로 유지하는 커넥션 시간
Summarize:
This blog article written by junior developer discusses the basics of configuring a connection pool when working with databases. It explains the different kinds of connections ( idle connections and active connections), why to use connection pools (to improve response time and increase throughput), and various parameters and settings for connection pools. It emphasizes the importance of correctly setting connection pool parameters as incorrect settings can lead to performance degradation. It also provides an example calculation of the maximum TPS with a given number of queries.
minimumIdle : 추천하지 않고, maximumPoolSize과 동일하게 설정
idleTimeout : 일반적으로는 사용하지 않는 커넥션들을 제거하여 풀의 유효한 커넥션 개수를 줄이는 역할
Summary:
This blog article provides an overview of connection pooling, including the types of connections, the benefits of using a connection pool, how to calculate the maximum TPS and connections, and the settings and performance associated with a pool. Additionally, the article provides examples of calculations and considerations when setting a connection pool, such as connection timeout, keep alive time and idle timeout.
Suggestions to Improve Article:
1. Provide a diagram or simple visual to illustrate the settings