From 4637860afc0dab9c3f9effd738a1fb94a27aa6d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=8A=B9=EC=A7=84?= Date: Wed, 9 Oct 2024 09:40:47 +0900 Subject: [PATCH] [FEAT] thread pool and retry backoff setting --- .../config/rabbitmq/RabbitMQConfig.java | 12 ++++--- .../backend/config/socket/StompConfig.java | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java b/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java index d68dc72..807f5b7 100644 --- a/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java +++ b/backend/src/main/java/com/twtw/backend/config/rabbitmq/RabbitMQConfig.java @@ -16,7 +16,7 @@ import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.retry.backoff.FixedBackOffPolicy; +import org.springframework.retry.backoff.ExponentialBackOffPolicy; import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.support.RetryTemplate; @@ -132,8 +132,8 @@ public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory( final SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); factory.setConnectionFactory(connectionFactory); - factory.setConcurrentConsumers(3); - factory.setMaxConcurrentConsumers(10); + factory.setConcurrentConsumers(20); + factory.setMaxConcurrentConsumers(200); factory.setRetryTemplate(retryTemplate()); return factory; } @@ -145,8 +145,10 @@ public RetryTemplate retryTemplate() { final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(3); - final FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); - backOffPolicy.setBackOffPeriod(3000); + final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy(); + backOffPolicy.setInitialInterval(10_000); + backOffPolicy.setMultiplier(1.5); + backOffPolicy.setMaxInterval(60_000); retryTemplate.setRetryPolicy(retryPolicy); retryTemplate.setBackOffPolicy(backOffPolicy); diff --git a/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java b/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java index 119d969..36a3e90 100644 --- a/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java +++ b/backend/src/main/java/com/twtw/backend/config/socket/StompConfig.java @@ -4,8 +4,11 @@ import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.util.AntPathMatcher; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; @@ -38,4 +41,34 @@ public void configureMessageBroker(final MessageBrokerRegistry registry) { registry.setApplicationDestinationPrefixes("/pub"); } + + @Override + public void configureClientInboundChannel(final ChannelRegistration registration) { + registration.taskExecutor(inboundTaskExecutor()); + } + + @Override + public void configureClientOutboundChannel(final ChannelRegistration registration) { + registration.taskExecutor(outboundTaskExecutor()); + } + + @Bean + public ThreadPoolTaskExecutor inboundTaskExecutor() { + final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(15); + executor.setMaxPoolSize(150); + executor.setThreadNamePrefix("stomp-inbound-"); + executor.initialize(); + return executor; + } + + @Bean + public ThreadPoolTaskExecutor outboundTaskExecutor() { + final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(20); + executor.setMaxPoolSize(200); + executor.setThreadNamePrefix("stomp-outbound-"); + executor.initialize(); + return executor; + } }