DB 커넥션은 애플리케이션과 데이터베이스(DB) 간의 통신 채널입니다.
한 커넥션에 이렇게 많은 리소스가 모소 됩니다. 그래서 미리 연결해 놓은 커넥션을 모아둔 Pool을 주로 사용합니다.
DB Connection Pool(커넥션 풀)은 데이터베이스와의 연결(Connection)을 미리 생성해두고 재사용하는 메커니즘입니다.
Pooling vs No Pooling 벤치마크
https://amaran-th.github.io/%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4/[DB]%20DB%20Connection%20Pool/

대충 커넥션이 많아질수록 성능차이가 많이 난다는 뜻
spring:
datasource:
hikari:
minimum-idle: 5 # 최소 유휴 커넥션 수
maximum-pool-size: 20 # 최대 커넥션 수
idle-timeout: 30000 # 30초 동안 유휴 상태면 커넥션 종료
max-lifetime: 1800000 # 커넥션 최대 수명 (30분)
connection-timeout: 2000 # 커넥션 요청 대기 시간 (2초)
const ctxUserId = ctx.userData?.id || 0;
//여기서 getConnection은 단일 커넥션이 아닌 Pool에서 가져오는 커넥션
//connection.release시 까지 커넥션을 독점합니다.
const connection = getConnection();
const queryRunner = connection.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
try {
let result = false;
const {
customerUid,
payType,
pg,
cardNumber,
cardName
} = inputIamportUsingSubscription;
// Request Billing Key
const requestFromSomewhere = await axios({
url: `https://somewhere.co.kr/subscribe/customers/${customerUid}`,
method: 'get',
headers: {
Authorization: accessToken,
'Content-Type': 'application/json'
}
});
// Validate Response
if (requestFromSomewhere.status !== 200 || requestFromSomewhere.data.code !== 0) {
throw new Error(requestFromSomewhere.message);
}
// Create New Iamport Payment Record
const newPayment = repoPayment.create();
if (customerUid) {
newPayment.customerUid = customerUid;
newPayment.paymentType = payType; // @ts-ignore
newPayment.pg = pg; // @ts-ignore
newPayment.cardNumber = cardNumber;
newPayment.cardName = cardName;
}
newPayment.user = await repoUser.findOneOrFail(ctxUserId);
const findDefaultPaymentInfo = await repoPayment
.createQueryBuilder('imp')
.where('imp.userId = :userId', { userId })
.andWhere('imp.isDefault = true')
.getOne();
newPayment.isDefault = findDefaultPaymentInfo ? false : isDefault;
// Save to DB
await queryRunner.manager.save(newPayment);
///////////////////내 첫번째 변경사항///////////////////
await Promise.all([
queryRunner.manager.save(newPayment),
queryRunner.manager.save(subscriberResolved)
]);
////////////////////////////////////////////////////////
await queryRunner.commitTransaction();
return result;
} catch (e) {
await queryRunner.rollbackTransaction();
throw new TooningServerRegisterBillingKeyError(e);
} finally {
await queryRunner.release();
}