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

Joakim Erdfelt <[email protected]> Fri, 8 Mar 2013 12:41:13 -0700
Newsgroups gmane.comp.java.jetty.support
Message-ID <CAG4zZZC5KyAVL2dvbaXPKkLszgFNVMwB-qTrNaySxBHBM48pEQ@mail.gmail.com>
--047d7b343e2a88455104d76f0189
Content-Type: text/plain; charset=ISO-8859-1

        <!-- Number of connection requests that can be queued up before the
operating system starts to send rejections. -->
        <property name="acceptQueueSize" value="1" />

Change that, bump it up to 20 or so.

--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org


On Fri, Mar 8, 2013 at 12:20 PM, Valery Dubrava <[email protected]>wrote:

> 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:
>
>     <bean name="jettyThreadPool" class="org.eclipse.jetty.util.thread.QueuedThreadPool">
>         <property name="name" value="jettyThreadPool" />
>         <property name="minThreads" value="10" />
>         <property name="maxThreads" value="100" />
>     </bean>
>
>     <bean name="jettyConnector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
>         <property name="host" value="0.0.0.0" />
>         <property name="port" value="8080" />
>         <!-- The number of thread dedicated to accepting incoming connections. <= 2*processors -->
>         <property name="acceptors" value="4" />
>         <!-- Number of connection requests that can be queued up before the operating system starts to send rejections. -->
>         <property name="acceptQueueSize" value="1" />
>         <property name="resolveNames" value="false" />
>         <property name="threadPool" ref="jettyThreadPool" />
>     </bean>
>
>     <bean name="server" class="org.eclipse.jetty.server.Server">
>         <property name="connectors">
>             <array>
>                 <ref bean="jettyConnector" />
>             </array>
>         </property>
>         <property name="handler">
>             <bean class="org.eclipse.jetty.server.handler.HandlerCollection">
>                 <property name="handlers">
>                     <array>
>                         <bean class="org.eclipse.jetty.server.handler.ContextHandler">
>                             <property name="contextPath" value="/check" />
>                             <property name="handler">
>                                 <bean class="com.oak.handlers.AsyncCheckHandler" />
>                             </property>
>                         </bean>
>                     </array>
>                 </property>
>             </bean>
>         </property>
>     </bean>
>
> 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_13 I've tried this on windows7 and debian.
> ------------------------------
> View this message in context: Async Context does not accept simultaneous
> requests<http://jetty.4.n6.nabble.com/Async-Context-does-not-accept-simultaneous-requests-tp4960197.html>
> Sent from the Jetty Support mailing list archive<http://jetty.4.n6.nabble.com/Jetty-Support-f1260.html>at Nabble.com.
>

--047d7b343e2a88455104d76f0189
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>=A0 =A0 =A0 =A0 &lt;!-- Number of connection requests that can be queu=
ed up before the operating system starts to send rejections. --&gt;</div><d=
iv>=A0 =A0 =A0 =A0 &lt;property name=3D&quot;acceptQueueSize&quot; value=3D=
&quot;1&quot; /&gt;</div>
<div><br></div><div>Change that, bump it up to 20 or so.</div><div><br></di=
v><div><div>--</div><div>Joakim Erdfelt &lt;<a href=3D"mailto:joakim@intali=
o.com" target=3D"_blank">[email protected]</a>&gt;</div><div><a href=3D"ht=
tp://www.webtide.com/" target=3D"_blank">webtide.com</a></div>
<div><span>Developer advice, services and support</span><br><span>from the =
Jetty &amp; CometD experts</span></div><div><a href=3D"http://eclipse.org/j=
etty/" target=3D"_blank">eclipse.org/jetty</a>=A0-=A0<a href=3D"http://come=
td.org/" target=3D"_blank">cometd.org</a></div>
</div>
<br><br><div class=3D"gmail_quote">On Fri, Mar 8, 2013 at 12:20 PM, Valery =
Dubrava <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" t=
arget=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc s=
olid;padding-left:1ex">
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 t=
echnology to the wrong way?

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

    &lt;bean name=3D&quot;jettyConnector&quot; class=3D&quot;org.eclipse.je=
tty.server.nio.SelectChannelConnector&quot;&gt;
        &lt;property name=3D&quot;host&quot; value=3D&quot;0.0.0.0&quot; /&=
gt;
        &lt;property name=3D&quot;port&quot; value=3D&quot;8080&quot; /&gt;
        &lt;!-- The number of thread dedicated to accepting incoming connec=
tions. &lt;=3D 2*processors --&gt;
        &lt;property name=3D&quot;acceptors&quot; value=3D&quot;4&quot; /&g=
t;
        &lt;!-- Number of connection requests that can be queued up before =
the operating system starts to send rejections. --&gt;
        &lt;property name=3D&quot;acceptQueueSize&quot; value=3D&quot;1&quo=
t; /&gt;
        &lt;property name=3D&quot;resolveNames&quot; value=3D&quot;false&qu=
ot; /&gt;
        &lt;property name=3D&quot;threadPool&quot; ref=3D&quot;jettyThreadP=
ool&quot; /&gt;
    &lt;/bean&gt;

    &lt;bean name=3D&quot;server&quot; class=3D&quot;org.eclipse.jetty.serv=
er.Server&quot;&gt;
        &lt;property name=3D&quot;connectors&quot;&gt;
            &lt;array&gt;
                &lt;ref bean=3D&quot;jettyConnector&quot; /&gt;
            &lt;/array&gt;
        &lt;/property&gt;
        &lt;property name=3D&quot;handler&quot;&gt;
            &lt;bean class=3D&quot;org.eclipse.jetty.server.handler.Handler=
Collection&quot;&gt;
                &lt;property name=3D&quot;handlers&quot;&gt;
                    &lt;array&gt;
                        &lt;bean class=3D&quot;org.eclipse.jetty.server.han=
dler.ContextHandler&quot;&gt;
                            &lt;property name=3D&quot;contextPath&quot; val=
ue=3D&quot;/check&quot; /&gt;
                            &lt;property name=3D&quot;handler&quot;&gt;
                                &lt;bean class=3D&quot;com.oak.handlers.Asy=
ncCheckHandler&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 t=
o remote resources which takes several seconds. That why I call a sleep wit=
h 5 seconds interval.
<pre>public class AsyncCheckHandler extends AbstractHandler {
    @Override
    public void handle(String target, final Request baseRequest, final Http=
ServletRequest req,
            final HttpServletResponse rsp) throws IOException, ServletExcep=
tion
    {
        final AsyncContext context =3D req.startAsync(req, rsp);
        context.start(new Runnable() {
            @Override
            public void run()
            {
                try {
                    Date date =3D new Date();
                    Thread.sleep(5000L);
                    context.getResponse().getWriter().print(&quot;Request d=
ate &quot; + date + &quot;, &quot; +
                                                                    &quot;&=
quot; + 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 =3D new ClassPathXmlApplicationCont=
ext(&quot;context.xml&quot;);

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

When I run it and make several parallel requests to <a href=3D"http://local=
host:8080/check" target=3D"_blank">http://localhost:8080/check</a> 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 acce=
pt new requests to this context.
Also I&#39;ve tried the same thing with ServletContext and with Continuatio=
n.
Jetty version is 8.1.9.v20130131, spring is 3.2.1.RELEASE. Java 1.7.0_13
I&#39;ve tried this on windows7 and debian.

=09
=09
=09
<br><hr align=3D"left" width=3D"300">
View this message in context: <a href=3D"http://jetty.4.n6.nabble.com/Async=
-Context-does-not-accept-simultaneous-requests-tp4960197.html" target=3D"_b=
lank">Async Context does not accept simultaneous requests</a><br>
Sent from the <a href=3D"http://jetty.4.n6.nabble.com/Jetty-Support-f1260.h=
tml" target=3D"_blank">Jetty Support mailing list archive</a> at Nabble.com=
.<br></blockquote></div><br>

--047d7b343e2a88455104d76f0189--