Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Open
8 changes: 4 additions & 4 deletions src/main/java/com/flab/makedel/config/SpringAsyncConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
@EnableAsync
public class SpringAsyncConfig {

private static final int CORE_POOL_SIZE = 3;
private static final int MAX_POOL_SIZE = 100;
private static final int QUEUE_CAPACITY = 3;
private static final int KEEP_ALIVE_SECONDS = 30;
private static final int CORE_POOL_SIZE = 5;
private static final int MAX_POOL_SIZE = 500;
Copy link
Member

Choose a reason for hiding this comment

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

이거는 이렇게 높혀주신 이유가 있으실까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

라이더들에게 지역별로 푸쉬 알람을 보내긴 하지만 갑자기 푸쉬 알람이 폭증할 가능성이 있기 때문에 max_pool_size를 늘려서 푸쉬 알람 보내는 기능에 병목이 일어날 확률이 적어지도록 만들었습니다.

Copy link
Member

Choose a reason for hiding this comment

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

이런 값은 성능테스트하면서 조절하는게 일반적인데요~ 추후에 한번 테스트해보시면서 조절해봐도 좋을 것 같네요

private static final int QUEUE_CAPACITY = 0;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

queue capacity가 양수이면 LinkedBlockingQueue로 지정되고

0이하라면 SynchronousQueue를 이용합니다.

LinkedBlockingQueue는 큐의 크기가 제한되지 않는 큐입니다. 크기를 수동으로 설정을 할 수도 있습니다. 하지만 큐에 작업이 계속 쌓이게 되면 푸쉬 알람에 병목이 생길 수 있습니다.

SynchronousQueue는 큐라기보다는 작업이 들어오면 그것을 스레드에 넘겨주는 역할을 합니다. 큐에 쌓지 않고 바로 프로듀서에서 생성한 작업을 컨슈머인 스레드에게 직접 전달합니다. 쉬고 있는 스레드에게 처리할 작업을 직접 넘겨주므로 효율적입니다. 또한 대기중인 스레드가 없는 상태에서 스레드의 개수가 max pool size보다 작다면 새로운 스레드를 생성해 동작시킵니다. 따라서 푸쉬알람이 폭증해도 대비할 수 있습니다. 하지만 정해둔 max pool size보다 커진다면 abort policy를 이용해 푸쉬 알람 보내는 것을 거부하고 exception을 던집니다.

private static final int KEEP_ALIVE_SECONDS = 60;
private static final String NAME_PREFIX = "springAsyncTask-";

@Bean(name = "springAsyncTask")
Expand Down