Search code examples
websocketstompsockjs

SockJS increase pool size


I am using SocketJS and Stomp to send files over a backend api for being process. My problem is that the upload function get stuck if more than two upload are done at the same time.

Ex:

  • User 1 -> upload a file -> backend is receiving correctly the file
  • User 2 -> upload a file -> backend is receiving correctly the file
  • User 3 -> upload a file -> the backend is not called until one of the previous upload hasn't completed.

(after a minute User 1 complete its upload and the third upload starts)

The error I can see through the log is the following:

2021-06-28 09:43:34,884 INFO  [MessageBroker-1] org.springframework.web.socket.config.WebSocketMessageBrokerStats.lambda$initLoggingTask$0: WebSocketSession[11 current WS(5)-HttpStream(6)-HttpPoll(0), 372 total, 26 closed abnormally (26 connect failure, 0 send limit, 16 transport error)], stompSubProtocol[processed CONNECT(302)-CONNECTED(221)-DISCONNECT(0)], stompBrokerRelay[null], **inboundChannel[pool size = 2, active threads = 2**, queued tasks = 263, completed tasks = 4481], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 607], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 14, completed tasks = 581444]

It seems clear that the pool size is full:

inboundChannel[pool size = 2, active threads = 2

but I really cannot find a way to increase the size.

This is the code:

Client side

ws = new SockJS(host + "/createTender");
stompClient = Stomp.over(ws);

Server side configuration

@EnableWebSocketMessageBroker
public class WebSocketBrokerConfig extends AbstractWebSocketMessageBrokerConfigurer {

    ...
    ...

    @Override
    public void configureWebSocketTransport(WebSocketTransportRegistration registration) {
        registration.setMessageSizeLimit(100240 * 10240);
        registration.setSendBufferSizeLimit(100240 * 10240);
        registration.setSendTimeLimit(20000);
    }

I've already tried with changing the configureWebSocketTransport parameters but it did not work. How can I increase the pool size of the socket?


Solution

  • The inbound channel into the WebSocket can be overwritten by using this method:

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.taskExecutor().corePoolSize(4);
        registration.taskExecutor().maxPoolSize(4)
    }
    

    The official documentation suggests to have a pool size = number of cores. For sure, since the maxPoolSize is reached then requests are handled through an internal queue. So, given this configuration I can process concurrently 4 requests.