feat: 기이수성적 데이터 추가 시, batch insert 적용 #69
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔧연결된 이슈
🛠️작업 내용
JdbcTemplate을 통해 batch insert를 수행하는 saveAll() 인터페이스 및 구현체 추가CompletedCoursesDao가 추가된 인터페이스를 상속받도록 수정CompletedCoursesDomain을 생성한 후, 바로 save를 호출하지 않고List에 담아두었다가 반복문이 끝난 뒤, 한 번에 저장🤷♂️PR이 필요한 이유
현재
CompletedCoursesDao의 구현체는 사용자가 업로드한 기이수 성적파일의 Row 개수만큼insert쿼리를 생성하고 있습니다.이렇게 될 경우, insert가 호출될 때마다 트랜잭션이 생성되며, 다중 요청이 발생할 경우, 하나의 스레드가 사용하는 커넥션 개수의 증가로 인해 커넥션 고갈 문제가 발생할 수 있다고 생각했습니다.
그래서
List에 담아 하나의 insert 쿼리로 처리할 수 있는 batch insert 방식을 추가하였습니다.JPA가 아닌 JDBC를 사용한 이유
안타깝게도 영속성 컨텍스트가 관리하는 엔티티의 ID 생성 방식이
IDENTITY인 경우, JPA에서 batch insert를 지원하지 않습니다. 엔티티를 1차 캐시에 저장하기 위해서는 DB에서 생성하는 ID가 필요하다 보니 batch insert의 이점을 누릴 수 없어서 지원하지 않는걸로 판단됩니다. 따라서 JDBC를 사용하는 별도의 인터페이스와 구현체를 추가하였으며, 기존에CompletedCoursesDao의 JPA 로직을 사용하는 부분은 변경되지 않았습니다. (save 메서드 제외)15 VUser 부하테스트 결과
Load Average(1분당 CPU 부하) 평균 54% 감소 (2.24 → 1.04)
DB QPS 52% 감소 (862.34QPS → 407.46QPS)
커넥션 획득 시간이 89.59% 감소(6.84ms → 0.712ms), 사용 시간이 66.03% 감소(214ms → 72.7ms)
✔️PR 체크리스트