feat: 대규모 데이터 삽입을 위한 Spring Batch Job 구현#366
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📌 관련 이슈
성능 테스트를 위한 대용량 더미 데이터 삽입 #365
🛠️ 작업 내용
현재 운영 DB의 데이터는 테이블당 최대 3,000건 수준으로, 향후 발생할 수 있는 대규모 트래픽 상황에서의 성능 병목 현상을 사전에 식별하기 어렵습니다. 이에 신뢰성 있는 성능 테스트 환경을 구축하기 위해 수백만 건의 더미 데이터를 생성하는 Spring Batch 기능을 구현했습니다.
대용량 데이터를 안정적으로 생성하고 삽입하기 위해 Spring Batch 프레임워크를 채택했습니다. 채택한 이유는 아래와 같습니다.
Chunk 지향 처리: ItemReader - ItemProcessor - ItemWriter 구조를 채택하여, 데이터를 일정 단위(Chunk)로 묶어 처리합니다. 이는 대량 데이터 삽입 시 발생할 수 있는 메모리 부족 문제를 방지하고 안정적인 트랜잭션 관리를 가능하게 합니다.
📊 더미 데이터 현황 및 용량 측정 결과
5개 테이블의 평균 Row 크기는 약 0.176KB입니다.
이전 이슈에서 공유된 EC2의 남은 용량은 2GB로,$2 \text{ GB} = 2 * 1024 * 1024 \text{ KB} = 2,097,152 \text{ KB}$
총 가용 공간:
인덱스 공간과 메모리 사용을 고려하지 않았을 때 약 천백만건의 데이터를 개발 DB서버에 넣을 수 있습니다.
🎯 리뷰 포인트
이번 PR은 개발 DB에 바로 대용량 데이터를 넣기 전에, 먼저 로컬에서 안정적으로 데이터를 생성할 수 있는 Batch 환경을 만드는 데 중점을 뒀습니다.
우선 로컬에서 N+1 같은 쿼리 문제를 찾아 최적화를 진행하고, 나중에 준비가 되면 개발 서버에 데이터를 올려서 트래픽 병목 현상이나 성능 지표를 측정할 계획입니다.
모든 개발자가 로컬 환경에서 대용량 데이터 삽입 Job을 실행할 필요는 없습니다.
이에 따라, Job 자동 실행 옵션을 기본적으로 비활성화했습니다.
로컬에서 더미 데이터 생성이 필요한 경우,
application-local.properties파일의 설정을 다음과 같이 변경하여 Job을 실행할 수 있습니다.