我有一个Tomcat 8 websocket应用程序,并在处理websocket客户端调用时注意到某种行为。一些细节:
http-nio-8080-exec-3 - 18:50:56 <-- this takes 30 seconds
http-nio-8080-exec-3 - 18:50:56 <--+
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |- these take less than a
http-nio-8080-exec-3 - 18:50:56 | second but get queued
http-nio-8080-exec-3 - 18:50:56 | after the first one that
http-nio-8080-exec-3 - 18:50:56 | takes 30 seconds
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 |
http-nio-8080-exec-3 - 18:50:56 <--+
以上显示了一些紧密连续触发的客户端调用的服务器日志(池中线程的名称以及响应发送到客户端的时间)。第一次通话需要30秒,而其余通话不到一秒钟。问题是快速调用在慢速调用之后排队,并且由Tomcat池中的同一线程处理。
我本来期待这样的事情:
http-nio-8080-exec-3 - 18:50:56 <-- this takes 30 seconds
http-nio-8080-exec-7 - 18:50:26 <---+
http-nio-8080-exec-5 - 18:50:26 |
http-nio-8080-exec-2 - 18:50:26 |
http-nio-8080-exec-1 - 18:50:26 |
http-nio-8080-exec-8 - 18:50:26 |
http-nio-8080-exec-10 - 18:50:26 |
http-nio-8080-exec-11 - 18:50:26 |
http-nio-8080-exec-9 - 18:50:26 |
http-nio-8080-exec-20 - 18:50:26 |
http-nio-8080-exec-13 - 18:50:26 |- these take less than a
http-nio-8080-exec-15 - 18:50:26 | second, don't depend
http-nio-8080-exec-17 - 18:50:26 | on the first one, and
http-nio-8080-exec-22 - 18:50:26 | are handled by different
http-nio-8080-exec-5 - 18:50:26 | threads
http-nio-8080-exec-7 - 18:50:26 |
http-nio-8080-exec-12 - 18:50:26 |
http-nio-8080-exec-16 - 18:50:26 |
http-nio-8080-exec-11 - 18:50:26 |
http-nio-8080-exec-22 - 18:50:26 |
http-nio-8080-exec-13 - 18:50:26 <--+
但是我得到了第一个版本,而不是第二个版本。
如果我没有快速连续播放所有电话但是等待响应我会得到我期望的结果:
http-nio-8080-exec-8 - 18:54:20
http-nio-8080-exec-6 - 18:55:21
http-nio-8080-exec-7 - 18:56:20
http-nio-8080-exec-9 - 18:57:20
http-nio-8080-exec-2 - 18:58:20
http-nio-8080-exec-1 - 18:59:21
.... etc ....
从我发现的内容(例如:http://grokbase.com/t/tomcat/users/125zhqcz2s/non-blocking-websockets和此处:Tomcat 8 JSR 356 WebSocket Threading)我了解这是已实施的行为。
是否可以并行执行所有调用,每次调用都使用池中的另一个线程?