SockJS 增加池大小

SockJS increase pool size

我正在使用 SocketJS 和 Stomp 通过后端 api 发送文件以进行处理。 我的问题是,如果同时完成两个以上的上传,上传功能会卡住。

例如:

(一分钟后,用户 1 完成上传,第三次上传开始)

我通过日志看到的错误如下:

2021-06-28 09:43:34,884 INFO  [MessageBroker-1] org.springframework.web.socket.config.WebSocketMessageBrokerStats.lambda$initLoggingTask[=10=]: 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]

很明显池大小已满:

inboundChannel[池大小 = 2,活动线程数 = 2

但是我真的找不到增加大小的方法。

这是代码:

客户端

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

服务器端配置

@EnableWebSocketMessageBroker
public class WebSocketBrokerConfig extends AbstractWebSocketMessageBrokerConfigurer {

    ...
    ...

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

我已经尝试更改 configureWebSocketTransport 参数,但没有成功。 如何增加套接字的池大小?

可以使用此方法覆盖进入 WebSocket 的入站通道:

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

The official documentation 建议池大小 = 核心数。当然,由于达到了 maxPoolSize,因此通过内部队列处理请求。因此,鉴于此配置,我可以同时处理 4 个请求。