Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - BE 테스트 개선 Bean Lazy Initialization 도입 #664

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

nak-honest
Copy link
Member

@nak-honest nak-honest commented Mar 11, 2025

✅ 작업 내용

  • 스프링 어플리케이션 컨텍스트가 뜰 때 빈을 바로 생성하는 것이 아닌 lazy 하게 생성하도록 설정

🙈 참고 사항

기본적으로 스프링은 어플리케이션 컨텍스트가 뜰 때 모든 빈을 바로 생성합니다.

저희 테스트에서는 여러 개의 어플리케이션 컨텍스트가 뜨는데,
각 컨텍스트마다 모든 빈을 사용하지 않기 때문에 lazy 옵션을 주어 최적화 했습니다.
(해당 빈이 필요해지는 순간에 생성)

하지만 생각보다 개선이 크지는 않습니다.
제 로컬 기준 1m 32.7s -> 1m 24.3s 로 약 10% 정도 개선되었습니다.

스프링 어플리케이션 컨텍스트의 개수가 4개이고, 빈 개수 자체도 많지 않다 보니 유의미한 차이를 보이지는 않는 것 같습니다.

Copy link

Test Results

 34 files   34 suites   1m 14s ⏱️
316 tests 315 ✅ 1 💤 0 ❌
328 runs  327 ✅ 1 💤 0 ❌

Results for commit a238d00.

@nak-honest
Copy link
Member Author

깃헙 액션 도는데 3m 30s -> 3m 17s 로 이전보다 약 13s 정도 빨라졌네요!

Copy link
Contributor

@slimsha2dy slimsha2dy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈이 필요할 때 초기화해서 불필요한 초기화를 막는 설정이군뇨..
찾아보니까 큰 단점은 없는 것으로 보이는데 그럼 이 설정이 일반적으로 테스트 성능을 위해 자주 사용되는 설정인지? 궁금하긴 합니다.

@nak-honest
Copy link
Member Author

nak-honest commented Mar 19, 2025

@slimsha2dy
전에 스프링 빈 공부하다 LAZY 옵션을 알게 되면서 테스트에 쓸 수 있지 않을까 싶어서 적용해 본 것인데요!
그때 좀 찾아보니 토스에서도 테스트 최적화를 위해 사용한 사례가 있더라구요!
https://toss.tech/article/test-strategy-server

다만 토스에서는 일부 빈들이 eager하게 생성되어야 했다고 하네요.

저희는 현재 그러한 빈이 없어서 문제가 안되지만, 만약 나중에 문제가 발생하면 토스처럼 해당 빈들만 eager하게 생성하도록 설정할 수 있을 것 같습니다!!

@nak-honest nak-honest merged commit 7934ba2 into develop/be Mar 19, 2025
3 checks passed
@nak-honest nak-honest deleted the feature/be/#663 branch March 19, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants