Tomcat 7 Async Processing failing - only one request processed simultanously

荒凉一梦 提交于 2019-12-01 05:56:21

OK, as the part of the research I've written testing programm that opened multiply connections to tomcat and did GET/POST on the async servlet. I've debugged and rechecked my server.xml configuration, limited thread pool for better visibility of test results etc. Now my configuration of connector looks like that:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" 
               minProcessors="3"
               maxProcessors="8"
               maxThreads="20"
               connectionTimeout="150000" 
               asyncTimeout="150000" />

And this is working! I've made test using NIO and made 1000 connections at one time, and all of them got processed in one time.

However, the effect I've described, still exists in browser. When I try to load servlet on 10 tabs, first get loaded, than second etc. It seems to be browser's behaviour, nothing gets blocked on server. When I opened 3 browsers (Firefox, Chrome, Opera) I've got 3 connections processed on one time.

So, the asynchronous processing defined in Servlet API 3.0 works on Tomcat 7, however, it must be tested with own programm not with multiple tabs in browser... testing COMET chat in multiple tabs can also not work as expected. However, in real-life example one computer will open only one connection. And, the browser's behaviour is not any server's fault.

edit After Spring MVC solution was included into web application, async processing mode was stopped (parameter from web.xml was ignored). However, the async support can be set up manually via adding line:

request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);

I think you have your server configured correctly. If you're just loading with a browser then the problem may be the way in which your browser is working. If you just access the web page with the browser then the browser will try and load the entire page and block until that is finished. Your browser won't finish the load until the async request is finished.

For example, if you were to look at the messaging with a tool like Fiddler I'd expect you'd see the following (assuming delay is 4):

Browser -> Server [Time: 0]   Request
Server -> Browser [Time: 0.1] Async Response
Server -> Browser [Timer: 4]  Complete Response
Browser shows page loaded.

If you took out the async mode you'd see:

Browser -> Server [Time: 0] Request
Server -> Browser [Time: 4] Response
Browser shows page loaded.

In both examples the page won't be fully loaded until the whole request is finished, even though one is asynchronous and one is synchronous. To fully take advantage of asynchronous requests you're going to need a smarter client, e.g. Javascript or flex or something.

In other words, I don't think you can say the server is correct or not by just loading with the browser. I would grab a tool like Fiddler and see exactly what HTTP messages are going across.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!