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

refactor: 알림 기능 로직 개선 및 알림 테스트 추가 #497

Merged
merged 45 commits into from
Jan 22, 2024

Conversation

Kim0914
Copy link
Collaborator

@Kim0914 Kim0914 commented Jan 22, 2024

※ 해당 PR 및 커밋은 이건회(@rawfishthelgh )와 함께 몹 프로그래밍으로 작성했습니다

🔥 연관 이슈

🚀 작업 내용

  • 알림 비동기 스레드 설정
    • AsyncConfig 클래스 내부에서 비동기를 위한 스레드 풀을 재정의 했습니다.
    • 성능 테스트 결과를 기반으로 스레드 수는 40으로 설정했습니다.
    • 100,000개 알림을 기준으로 약 400분 -> 12분 30초 까지 개선 완료했습니다.
  • 이벤트 리스너 관련 테스트 코드 몇 개를 추가했습니다.
  • AsyncConfig내에서 스레드 풀 설정 시 queueCapacity, maxPoolSize는 기본 설정으로 유지했습니다.
  • Admin 패키지에 TestController는 테스트를 위해 주석처리하고 남겨두었습니다 !

💬 리뷰 중점사항

큰 변경사항은 없고 성능 테스트와 트러블 슈팅 때문에 시간이 조금 소요되었습니다 😃

@Kim0914 Kim0914 added 🛠️ 리팩터링 리팩터링을 위한 이슈입니다 🍉 백엔드 백엔드 관련 이슈입니다 labels Jan 22, 2024
@Kim0914 Kim0914 changed the title refactor: 알림 기능 및 알림 테스트 테스트 로직 개선 refactor: 알림 기능 로직 개선 및 알림 테스트 추가 Jan 22, 2024

This comment has been minimized.

Copy link

github-actions bot commented Jan 22, 2024

Unit Test Results

  89 files  +2    89 suites  +2   15s ⏱️ ±0s
367 tests +3  367 ✔️ +3  0 💤 ±0  0 ±0 
373 runs  +3  373 ✔️ +3  0 💤 ±0  0 ±0 

Results for commit a69624d. ± Comparison against base commit d6d27d1.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@Choi-JJunho Choi-JJunho left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~
커밋 내역을 보니 많은 고생을 하셨던 모습이 보이네요 😂

궁금한점이 몇가지 있긴 하지만 크리티컬한 이슈는 아니라서 Approve 드립니다!


@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

오 비동기 설정을 별도로 분리했군요! 👍

public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(40);
executor.setThreadNamePrefix("2024-Pium-Thread: ");
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

디버깅할때 용이하겠군요 👍

Comment on lines 27 to 29
@Async
public void handleNotificationEvents(NotificationEvents notificationEvents) {
log.info("동기 알림 START, Thread: " + Thread.currentThread().getId() + " " + Thread.currentThread().getName());
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

잘 몰라서 여쭤봅니다~
@Async 가 붙어있는데도 동기적으로 동작하는건가요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

지워야 하는 메소드인데 그대로 두고 있었군요...!
지금은 @EnableAsync 설정 때문에 본 메소드도 비동기적으로 동작하게 됩니다.
그러나 결국 이벤트 내부에서는 단일 스레드가 모든 notificationEvents를 처리하고 있어 여러개의 알림을 병렬적으로 처리할 수가 없는 상황인데 위 메소드의 단점이었어요ㅠㅠ
위 메소드는 지우도록 하겠습니다!


@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
@ExtendWith(DatabaseClearExtension.class)
@RecordApplicationEvents
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

Test환경에서 이벤트를 기록하고 확인할 수도 있군요!
지식이 늘었네요 👍

@@ -42,6 +46,9 @@ class MemberServiceTest {
@Autowired
private PetPlantRepository petPlantRepository;

@Autowired
private ApplicationEvents applicationEvents;
Copy link
Collaborator

Choose a reason for hiding this comment

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

A

이 친구가 이벤트 호출 횟수를 기록해주는군요! 👍

Copy link
Collaborator

@rawfishthelgh rawfishthelgh left a comment

Choose a reason for hiding this comment

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

확인했습니다~!

@rawfishthelgh rawfishthelgh merged commit 0f13d5d into develop Jan 22, 2024
4 checks passed
@rawfishthelgh rawfishthelgh deleted the test/490-알림_테스트_로직_개선 branch January 22, 2024 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍉 백엔드 백엔드 관련 이슈입니다 🛠️ 리팩터링 리팩터링을 위한 이슈입니다
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

알림 테스트 API 로직 개선
3 participants