【发布时间】:2015-10-27 00:16:40
【问题描述】:
据我了解(如果我错了,请纠正我),在 tomcat 中,传入的 websocket 消息是按顺序处理的。这意味着如果您在一个 websocket 中有 100 条传入消息,则它们将仅使用从消息 1 到消息 100 的一个线程一对一进行处理。
但这对我不起作用。我需要同时处理 websocket 中的传入消息,以增加我的 websocket 吞吐量。传入的消息不相互依赖,因此不需要按顺序处理。
问题是如何配置 tomcat 以便为每个 websocket 分配多个工作线程来同时处理传入的消息?
感谢任何提示。
这是tomcat code 中我认为每个 websocket 连接都会阻塞的地方(这是有道理的):
/**
* Called when there is data in the ServletInputStream to process.
*
* @throws IOException if an I/O error occurs while processing the available
* data
*/
public void onDataAvailable() throws IOException {
synchronized (connectionReadLock) {
while (isOpen() && sis.isReady()) {
// Fill up the input buffer with as much data as we can
int read = sis.read(
inputBuffer, writePos, inputBuffer.length - writePos);
if (read == 0) {
return;
}
if (read == -1) {
throw new EOFException();
}
writePos += read;
processInputBuffer();
}
}
}
【问题讨论】:
标签: multithreading tomcat concurrency websocket throughput