[Refactor] #267 - 유저 회원가입 이벤트 발행 비동기 처리 #268
Merged
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.
🚀PullRequest🚀
📟 관련 이슈
💻 작업 내용
유저 회원가입 이벤트 발행 로직을 비동기로 처리하도록 변경하였습니다.
비동기는 기본적으로 해당 요청의 반환 결과를 기다리지 않고 다음 실행을 이어나가는 방법을 말합니다. 로그인 특성상 회원가입 이벤트를 Discord에 로깅하는데 로깅하는 데까지 유저가 기다리는 시간이 많을 뿐더러, 이는 유저에게 불필요한 대기시간이므로 비동기로 분리하였습니다.
비동기로 분리했을 떄의 API 수행 시간 차이는 다음과 같이 테스트하였습니다.
[기존 로직을 통해 이벤트를 발행한 경우]
[비동기로 변경된 로직으로 이벤트를 발행한 경우]
위 테스트 결과를 보시면 거의 이벤트의 I/O 시간만큼 유저의 회원가입 시간이 오래 걸린다는 것을 확인할 수 있습니다. 이를 통해 비동기 처리의 효과를 확인할 수 있습니다.
그리고 비동기 처리를 위한 쓰레드 풀을 설정하였는데요.
저희는 EC2 프리티어를 사용하고 있어서 싱글 코어입니다.
싱글 코어인데 쓰레드 풀의 크기를 크게 설정하면 정상적인 처리가 되지 않을 뿐더러, 회원가입 이벤트가 동시다발적으로 많이 발생하지 않을 것입니다. 그래서 쓰레드 풀의 크기를 4로 설정하고 keep-alive 시간도 60초로 설정하여 정상적으로 처리되도록 하였습니다.
또한, 대기 큐 오버플로우가 발생하면 이벤트를 받지 않고 폐기하도록 정책을 설정하였습니다.
잘못된 점 있으면 지적해주시기 바랍니다 감사합니다.
첨언 : 궁금해하실거 같아서 덧붙히자면, @async 어노테이션은 AOP로 동작하기 떄문에 self-invocation(자가 호출) 즉, 같은 클래스 내에서 호출을 못합니다. 따라서 SignUpService로 클래스를 분리하고 빈을 주입받아 호출하도록 하였습니다.
📝 리뷰 노트