perf: JDBC 배치 쓰기 핫패스의 행별 reflection 할당·청크별 타입 산출 제거#265
Open
z3rotig4r wants to merge 1 commit into
Open
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.
변경 이유
EgovJdbcBatchItemWriter(DefaultItemWriter가 jdbcDb 쓰기를 위임하는 대상)의 배치 쓰기 핫패스에 반복 reflection 비용이 두 군데 있습니다.EgovMethodMapItemPreparedStatementSetter.setValues()가 행마다new EgovReflectionSupport를 생성합니다. 이 호출은 인자만 사용하는 무상태 메서드인데도 행 수만큼 인스턴스를 할당하므로, 대용량 잡에서 불필요한 GC 부담이 됩니다.write()가 청크마다getSqlTypeArray(params, items.get(0))를 다시 계산합니다. 컬럼마다getDeclaredFieldreflection lookup이 발생하는데,params는 고정이고 item은 동질이라 매 청크의 결과가 같습니다.변경 내용
EgovReflectionSupport를 인스턴스 필드로 1회 생성해 재사용하도록 변경했습니다. 행별 할당이 N에서 1로 줄어듭니다. 해당 호출이 무상태이므로 인스턴스 공유가 안전합니다.동시성 안전
멀티스레드 Step에서 이질 클래스 청크가 동시에 처리될 때,
itemClass와sqlTypes가 어긋나는 torn-read가 생길 수 있습니다. 이를 막기 위해 클래스와 타입 배열을 불변 holder(SqlTypeCache)로 묶어 단일volatile참조로 원자 발행하고, 소비 시점에는 지역 변수로 한 번만 읽습니다.setParams()가 호출되면 캐시를 무효화합니다. 원본이 보장하던 청크 지역 변수 수준의 스레드 안전성을 유지하면서 캐시 이득을 얻습니다.동작 보존
같은 입력에 대해 PreparedStatement 세팅 순서, 인자, SQL 타입 배열이 기존과 동일합니다. 단일 스레드 동작은 바뀌지 않습니다.
테스트 방법
외부 DB 없이 Proxy 기반 PreparedStatement로 결정적 검증 4건을 추가했습니다.
setParams호출 시 캐시가 무효화되는지 확인CyclicBarrier)하는 상황에서 torn-read가 없는지 확인(수정 전 재현, 수정 후 통과)org.egovframe.rte.bat.core모듈 전체 테스트 18건 green입니다.영향 범위
EgovReflectionSupport는 변경하지 않았습니다(별도 진행 중인 작업과 분리).