SockJS增加了池大小



我使用SocketJS和Stomp通过后台api发送文件以供处理。我的问题是,如果同时完成两次以上的上传,上传功能就会被卡住。

例如:

  • 用户1->上传文件->后端正在正确接收文件
  • 用户2->上传文件->后端正在正确接收文件
  • 用户3->上传文件->直到上一次上载尚未完成

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

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

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]

很明显,池大小已满:

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);
}

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

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

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

官方文件建议使用池大小=核心数量。当然,由于已达到maxPoolSize,因此请求将通过内部队列进行处理。因此,在这种配置下,我可以同时处理4个请求。

最新更新