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.
📣 Related Issue
📝 Summary
사용자당 다중 공감을 허용하는 비즈니스 로직을 구현하며 데이터 모델을 M:N 구조로 설계하자, 게시글 목록 조회 시, 각 게시글마다 연관된 다수의 공감 데이터를 개별적으로 조회하는 N+1 문제가 발생하였습니다. 이로 인해 데이터 양에 비례하여 쿼리 수가 급격히 증가하고, 응답 시간이 선형적으로 늘어나는 성능 병목을 확인했습니다.
이에 따라 루프 기반의 개별 조회 방식을 In-clause를 활용한 Batch Fetching 전략으로 리팩토링하고, Java Stream API를 이용한 메모리 매핑을 적용하여 실행 시간을 최적화하였습니다.
[성능 개선 수치 (평균치 비교)]
Size 10 : (개선 전) 1604ms -> 401ms(최저 237ms) = 약 75% 감소
Size 20 : (개선 전) 2686ms -> 494ms(최저 441ms) = 약 82% 감소
+) 추가 Refactoring 사항: Post의 content 데이터 타입이 String -> varchar(255)로 255자만 들어가고 있어, 임의 TEXT 타입 지정으로 기획에서 정의한 2000자를 기입할 수 있도록 수정하였습니다.
📬 Reference
[실제 개선 전/후 측정 시간]
개선 전:
메서드 실행 시간 [getPostAll]: 1802ms
메서드 실행 시간 [getPostAll]: 1537ms
메서드 실행 시간 [getPostAll]: 1474ms
메서드 실행 시간 [getPostAll]: 2970ms (size: 20으로 시도)
메서드 실행 시간 [getPostAll]: 2500ms (size: 20으로 시도)
메서드 실행 시간 [getPostAll]: 2588ms (size: 20으로 시도)
개선 후:
메서드 실행 시간 [getPostAll]: 652ms
메서드 실행 시간 [getPostAll]: 314ms
메서드 실행 시간 [getPostAll]: 237ms
메서드 실행 시간 [getPostAll]: 578ms (size: 20으로 시도)
메서드 실행 시간 [getPostAll]: 464ms (size: 20으로 시도)
메서드 실행 시간 [getPostAll]: 441ms (size: 20으로 시도)