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 <!-- Number of connection requests that can be queu=
ed up before the operating system starts to send rejections. --></div><d=
iv>=A0 =A0 =A0 =A0 <property name=3D"acceptQueueSize" value=3D=
"1" /></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 <<a href=3D"mailto:joakim@intali=
o.com" target=3D"_blank">[email protected]</a>></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 & 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"><<a href=3D"mailto:[email protected]" t=
arget=3D"_blank">[email protected]</a>></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> <bean name=3D"jettyThreadPool" class=3D"org.ecli=
pse.jetty.util.thread.QueuedThreadPool">
<property name=3D"name" value=3D"jettyThreadPool&=
quot; />
<property name=3D"minThreads" value=3D"10" /=
>
<property name=3D"maxThreads" value=3D"100" =
/>
</bean>
<bean name=3D"jettyConnector" class=3D"org.eclipse.je=
tty.server.nio.SelectChannelConnector">
<property name=3D"host" value=3D"0.0.0.0" /&=
gt;
<property name=3D"port" value=3D"8080" />
<!-- The number of thread dedicated to accepting incoming connec=
tions. <=3D 2*processors -->
<property name=3D"acceptors" value=3D"4" /&g=
t;
<!-- Number of connection requests that can be queued up before =
the operating system starts to send rejections. -->
<property name=3D"acceptQueueSize" value=3D"1&quo=
t; />
<property name=3D"resolveNames" value=3D"false&qu=
ot; />
<property name=3D"threadPool" ref=3D"jettyThreadP=
ool" />
</bean>
<bean name=3D"server" class=3D"org.eclipse.jetty.serv=
er.Server">
<property name=3D"connectors">
<array>
<ref bean=3D"jettyConnector" />
</array>
</property>
<property name=3D"handler">
<bean class=3D"org.eclipse.jetty.server.handler.Handler=
Collection">
<property name=3D"handlers">
<array>
<bean class=3D"org.eclipse.jetty.server.han=
dler.ContextHandler">
<property name=3D"contextPath" val=
ue=3D"/check" />
<property name=3D"handler">
<bean class=3D"com.oak.handlers.Asy=
ncCheckHandler" />
</property>
</bean>
</array>
</property>
</bean>
</property>
</bean>
</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("Request d=
ate " + date + ", " +
"&=
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("context.xml");
Server server =3D (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 <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'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'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--