[jetty-user] Async Context does not accept simultaneous requests

Valery Dubrava <[email protected]> Fri, 8 Mar 2013 11:20:11 -0800 (PST)
Newsgroups gmane.comp.java.jetty.support
Message-ID <[email protected]>
------=_Part_82326_6259192.1362770411604
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I tried to create context for accepting many simultaneous requests by using
AsyncServelet/Continuation. But the all requests to one context are queued.
I will provide some code blocks for introducing into the problem. Please,
help me with this issue. Maybe I understand something wrong and use this
technology to the wrong way?A simple spring xml config for JettyServer:
    &lt;bean name=&quot;jettyThreadPool&quot;
class=&quot;org.eclipse.jetty.util.thread.QueuedThreadPool&quot;&gt;       
&lt;property name=&quot;name&quot; value=&quot;jettyThreadPool&quot; /&gt;       
&lt;property name=&quot;minThreads&quot; value=&quot;10&quot; /&gt;       
&lt;property name=&quot;maxThreads&quot; value=&quot;100&quot; /&gt;   
&lt;/bean&gt;    &lt;bean name=&quot;jettyConnector&quot;
class=&quot;org.eclipse.jetty.server.nio.SelectChannelConnector&quot;&gt;       
&lt;property name=&quot;host&quot; value=&quot;0.0.0.0&quot; /&gt;       
&lt;property name=&quot;port&quot; value=&quot;8080&quot; /&gt;       
&lt;!-- The number of thread dedicated to accepting incoming connections.
&lt;= 2*processors --&gt;        &lt;property name=&quot;acceptors&quot;
value=&quot;4&quot; /&gt;        &lt;!-- Number of connection requests that
can be queued up before the operating system starts to send rejections.
--&gt;        &lt;property name=&quot;acceptQueueSize&quot;
value=&quot;1&quot; /&gt;        &lt;property name=&quot;resolveNames&quot;
value=&quot;false&quot; /&gt;        &lt;property
name=&quot;threadPool&quot; ref=&quot;jettyThreadPool&quot; /&gt;   
&lt;/bean&gt;    &lt;bean name=&quot;server&quot;
class=&quot;org.eclipse.jetty.server.Server&quot;&gt;        &lt;property
name=&quot;connectors&quot;&gt;            &lt;array&gt;               
&lt;ref bean=&quot;jettyConnector&quot; /&gt;            &lt;/array&gt;       
&lt;/property&gt;        &lt;property name=&quot;handler&quot;&gt;           
&lt;bean
class=&quot;org.eclipse.jetty.server.handler.HandlerCollection&quot;&gt;               
&lt;property name=&quot;handlers&quot;&gt;                    &lt;array&gt;                       
&lt;bean
class=&quot;org.eclipse.jetty.server.handler.ContextHandler&quot;&gt;                           
&lt;property name=&quot;contextPath&quot; value=&quot;/check&quot; /&gt;                           
&lt;property name=&quot;handler&quot;&gt;                               
&lt;bean class=&quot;com.oak.handlers.AsyncCheckHandler&quot; /&gt;                           
&lt;/property&gt;                        &lt;/bean&gt;                   
&lt;/array&gt;                &lt;/property&gt;            &lt;/bean&gt;       
&lt;/property&gt;    &lt;/bean&gt;
The AsyncCheckHandler is only for testing. In future it will make request to
remote resources which takes several seconds. That why I call a sleep with 5
seconds interval.
public class AsyncCheckHandler extends AbstractHandler {    @Override   
public void handle(String target, final Request baseRequest, final
HttpServletRequest req,            final HttpServletResponse rsp) throws
IOException, ServletException    {        final AsyncContext context =
req.startAsync(req, rsp);        context.start(new Runnable() {           
@Override            public void run()            {                try {                   
Date date = new Date();                    Thread.sleep(5000L);                   
context.getResponse().getWriter().print("Request date " + date + ", " +                                                                   
"" + Thread.currentThread().getName());                   
baseRequest.setHandled(true);                } catch (InterruptedException |
IOException e) {                    e.printStackTrace();                }
finally {                    context.complete();                }           
}        });    }}
And main class is very simple:
        ApplicationContext context = new
ClassPathXmlApplicationContext("context.xml");        Server server =
(Server) context.getBean("server");        try {            server.start();           
server.join();        } catch (Exception e) {           
e.printStackTrace();        }
When I run it and make several parallel requests to
http://localhost:8080/check each of this requests is suspended until
previous was done. That is the problem for me. I expected that after it
returns from handler it will be ready to accept new requests to this
context.Also I've tried the same thing with ServletContext and with
Continuation.Jetty version is 8.1.9.v20130131, spring is 3.2.1.RELEASE. Java
1.7.0_13I've tried this on windows7 and debian.



--
View this message in context: http://jetty.4.n6.nabble.com/Async-Context-does-not-accept-simultaneous-requests-tp4960197.html
Sent from the Jetty Support mailing list archive at Nabble.com.
------=_Part_82326_6259192.1362770411604
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

I tried to create context for accepting many simultaneous requests by using AsyncServelet/Continuation. But the all requests to one context are queued. I will provide some code blocks for introducing into the problem. Please, help me with this issue. Maybe I understand something wrong and use this technology to the wrong way?

A simple spring xml config for JettyServer:
<pre>
    &lt;bean name=&quot;jettyThreadPool&quot; class=&quot;org.eclipse.jetty.util.thread.QueuedThreadPool&quot;&gt;
        &lt;property name=&quot;name&quot; value=&quot;jettyThreadPool&quot; /&gt;
        &lt;property name=&quot;minThreads&quot; value=&quot;10&quot; /&gt;
        &lt;property name=&quot;maxThreads&quot; value=&quot;100&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean name=&quot;jettyConnector&quot; class=&quot;org.eclipse.jetty.server.nio.SelectChannelConnector&quot;&gt;
        &lt;property name=&quot;host&quot; value=&quot;0.0.0.0&quot; /&gt;
        &lt;property name=&quot;port&quot; value=&quot;8080&quot; /&gt;
        &lt;!-- The number of thread dedicated to accepting incoming connections. &lt;= 2*processors --&gt;
        &lt;property name=&quot;acceptors&quot; value=&quot;4&quot; /&gt;
        &lt;!-- Number of connection requests that can be queued up before the operating system starts to send rejections. --&gt;
        &lt;property name=&quot;acceptQueueSize&quot; value=&quot;1&quot; /&gt;
        &lt;property name=&quot;resolveNames&quot; value=&quot;false&quot; /&gt;
        &lt;property name=&quot;threadPool&quot; ref=&quot;jettyThreadPool&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean name=&quot;server&quot; class=&quot;org.eclipse.jetty.server.Server&quot;&gt;
        &lt;property name=&quot;connectors&quot;&gt;
            &lt;array&gt;
                &lt;ref bean=&quot;jettyConnector&quot; /&gt;
            &lt;/array&gt;
        &lt;/property&gt;
        &lt;property name=&quot;handler&quot;&gt;
            &lt;bean class=&quot;org.eclipse.jetty.server.handler.HandlerCollection&quot;&gt;
                &lt;property name=&quot;handlers&quot;&gt;
                    &lt;array&gt;
                        &lt;bean class=&quot;org.eclipse.jetty.server.handler.ContextHandler&quot;&gt;
                            &lt;property name=&quot;contextPath&quot; value=&quot;/check&quot; /&gt;
                            &lt;property name=&quot;handler&quot;&gt;
                                &lt;bean class=&quot;com.oak.handlers.AsyncCheckHandler&quot; /&gt;
                            &lt;/property&gt;
                        &lt;/bean&gt;
                    &lt;/array&gt;
                &lt;/property&gt;
            &lt;/bean&gt;
        &lt;/property&gt;
    &lt;/bean&gt;
</pre>

The AsyncCheckHandler is only for testing. In future it will make request to remote resources which takes several seconds. That why I call a sleep with 5 seconds interval.
<pre>
public class AsyncCheckHandler extends AbstractHandler {
    @Override
    public void handle(String target, final Request baseRequest, final HttpServletRequest req,
            final HttpServletResponse rsp) throws IOException, ServletException
    {
        final AsyncContext context = req.startAsync(req, rsp);
        context.start(new Runnable() {
            @Override
            public void run()
            {
                try {
                    Date date = new Date();
                    Thread.sleep(5000L);
                    context.getResponse().getWriter().print("Request date " + date + ", " +
                                                                    "" + Thread.currentThread().getName());
                    baseRequest.setHandled(true);
                } catch (InterruptedException | IOException e) {
                    e.printStackTrace();
                } finally {
                    context.complete();
                }
            }
        });
    }
}
</pre>

And main class is very simple:

<pre>
        ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");

        Server server = (Server) context.getBean("server");
        try {
            server.start();
            server.join();
        } catch (Exception e) {
            e.printStackTrace();
        }
</pre>

When I run it and make several parallel requests to http://localhost:8080/check each of this requests is suspended until previous was done. That is the problem for me. I expected that after it returns from handler it will be ready to accept new requests to this context.
Also I've tried the same thing with ServletContext and with Continuation.
Jetty version is 8.1.9.v20130131, spring is 3.2.1.RELEASE. Java 1.7.0_13
I've tried this on windows7 and debian.

	
	
	
<br/><hr align="left" width="300" />
View this message in context: <a href="http://jetty.4.n6.nabble.com/Async-Context-does-not-accept-simultaneous-requests-tp4960197.html">Async Context does not accept simultaneous requests</a><br/>
Sent from the <a href="http://jetty.4.n6.nabble.com/Jetty-Support-f1260.html">Jetty Support mailing list archive</a> at Nabble.com.<br/>
------=_Part_82326_6259192.1362770411604--