Skip to content
Extraits de code Groupes Projets
Valider 57899830 rédigé par Mohamed Lemine BAILLAHI's avatar Mohamed Lemine BAILLAHI
Parcourir les fichiers

Merge branch 'bugfix/MS-115' into 'develop'

Optimize performance for 1000+ concurrent connections

Closes MS-115

See merge request !24
parents 4e715bdc 1032c464
Pipeline #15818 en échec avec les étapes
in 40 secondes
......@@ -2,6 +2,8 @@
### Added
- optimize the push product and hide product features
- fixed live pagination bug
- Optimize performance for 1000+ concurrent connections
## [0.0.7-RELEASE]
### Added
- added export messages feature
......
package com.marketingconfort.mydressin.mydressinstreamservices.configs;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration;
import org.springframework.web.socket.handler.WebSocketHandlerDecorator;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
......@@ -26,18 +30,46 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
.setAllowedOriginPatterns("*")
.withSockJS()
.setWebSocketEnabled(true)
.setHeartbeatTime(25000)
.setDisconnectDelay(5000)
.setClientLibraryUrl("https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.5.1/sockjs.min.js");
}
@Override
public void configureMessageBroker(@NonNull MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
// Configure thread pool for message broker
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(4);
taskScheduler.setThreadNamePrefix("ws-heartbeat-scheduler-");
taskScheduler.initialize();
// Configure in-memory broker with optimized settings
config.enableSimpleBroker("/topic")
.setTaskScheduler(taskScheduler)
.setHeartbeatValue(new long[]{10000, 10000});
config.setApplicationDestinationPrefixes("/app");
// Configure message size limits
config.setPreservePublishOrder(true);
}
@Override
public void configureWebSocketTransport(
@NonNull final org.springframework.web.socket.config.annotation.WebSocketTransportRegistration registration) {
public void configureWebSocketTransport(@NonNull WebSocketTransportRegistration registration) {
// Configure message size and timeout limits
registration.setMessageSizeLimit(128 * 1024) // 128KB
.setSendTimeLimit(20 * 1000) // 20 seconds
.setSendBufferSizeLimit(512 * 1024) // 512KB
.setTimeToFirstMessage(30 * 1000); // 30 seconds
// Configure thread pools for message processing
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(10);
taskExecutor.setMaxPoolSize(20);
taskExecutor.setQueueCapacity(1000);
taskExecutor.setThreadNamePrefix("ws-message-executor-");
taskExecutor.initialize();
registration.addDecoratorFactory(new WebSocketHandlerDecoratorFactory() {
@Override
public @NonNull WebSocketHandler decorate(@NonNull final WebSocketHandler handler) {
......@@ -45,6 +77,8 @@ public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void afterConnectionEstablished(@NonNull final WebSocketSession session) throws Exception {
connectedClients.incrementAndGet();
session.setTextMessageSizeLimit(64 * 1024); // 64KB per message
session.setBinaryMessageSizeLimit(128 * 1024); // 128KB for binary
super.afterConnectionEstablished(session);
}
......
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter