You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Wang Han <it...@gmail.com> on 2008/04/17 03:24:03 UTC

Can we slow down the speed of servlet response ?

Hi all,

The story is:
                              http
NM app  <-------->   servlet

the app sends some request to servlet and will handle the response
after 5 minutes.
But in the servlet side, it handles the request too fast and always
sends response back to app in 30 seconds.

So I wonder is there a way to add some delay in tomcat to slow down
the speed of response?

I know invoking thread.sleep() in servlet is not recommend , so any
other way please?

B.R
Han

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Wang Han <it...@gmail.com>.
Hi Chris,

In fact I am simulating large number of devices for our network
management application. In reality, the real device takes about
3 minutes to handle request/send back response to app.

I use some plain txt file to compose response in simulated device. It
only need around 3 seconds.

I'm not sure whether it will impact Network management app but I do
want to the simulator as same with real devices as possible, So I
wonder whether we can add delay in tomcat...

Maybe I should use tomcat version 1.0 instead to slow down the response :-)

On Thu, Apr 17, 2008 at 10:40 AM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>
>  Han,
>
>
>  Wang Han wrote:
>  | But in the servlet side, it handles the request too fast and always
>  | sends response back to app in 30 seconds.
>
>  Maybe you should get together with the guys who are always asking about
>  how to optimize Tomcat and get their code to run faster.
>
>  Seriously, though.... I don't get it. The server responds too /fast/?
>  How can that be? Why would getting the response /later/ be advantageous?
>
>  - -chris
>
>  -----BEGIN PGP SIGNATURE-----
>  Version: GnuPG v1.4.9 (MingW32)
>  Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>  iEYEARECAAYFAkgGuJcACgkQ9CaO5/Lv0PCeWwCeLY8q9vss6Gi+zI9cy3RkH2A1
>  UXUAnjDmH4WjvjUV/tsjK2LHZ3ajkIEq
>  =2oMe
>  -----END PGP SIGNATURE-----
>
>  ---------------------------------------------------------------------
>  To start a new topic, e-mail: users@tomcat.apache.org
>  To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Han,

Wang Han wrote:
| But in the servlet side, it handles the request too fast and always
| sends response back to app in 30 seconds.

Maybe you should get together with the guys who are always asking about
how to optimize Tomcat and get their code to run faster.

Seriously, though.... I don't get it. The server responds too /fast/?
How can that be? Why would getting the response /later/ be advantageous?

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgGuJcACgkQ9CaO5/Lv0PCeWwCeLY8q9vss6Gi+zI9cy3RkH2A1
UXUAnjDmH4WjvjUV/tsjK2LHZ3ajkIEq
=2oMe
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Can we slow down the speed of servlet response ?

Posted by "Reich, Matthias" <ma...@siemens.com>.
Hi,

if your simulation really requires waiting on server side,
you could also have a look at Comet
(http://tomcat.apache.org/tomcat-6.0-doc/aio.html).
A Comet solution would not block a thread per request while waiting for
the timeout condition.

By the way, when using the Http11NioProtocol on a Linux box, you should
consider this:
http://www.mail-archive.com/users@tomcat.apache.org/msg36968.html

-- Matthias

-----Original Message-----
From: Wang Han [mailto:itwanghan@gmail.com] 
Sent: Thursday, April 24, 2008 11:25 AM
To: Tomcat Users List
Subject: Re: Can we slow down the speed of servlet response ?

Hi Chris,

Just received the latest version NM software and it works well with
Thread.sleep works now.
It seems old NM SW bug caused Thread.sleep() failed.

the latest NM will send 60 concurrent requests maximum and I
configured the "Connector" element as:
 <Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443" enableLookups="true" disableUploadTimeout="true"
acceptCount="250" maxThreads="250" connectionTimeout="20000"...

Not sure whether it can meet the NM requirement , any suggestion?

I just get a Linux box with 1G memory to host my Servlet.Will update
you after I finish the test.

B.R
Han


On Fri, Apr 18, 2008 at 7:47 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>
>  Han,
>
>  Wang Han wrote:
>  | I have tried Thread.sleep() in my servlet and it fails.
>  | My NM app throws exception and can't handle such response..
>
>  What exception is thrown? I can't see a reason why Thread.sleep
wouldn't
>  work.
>
>
>  - -chris
>
>  -----BEGIN PGP SIGNATURE-----
>  Version: GnuPG v1.4.9 (MingW32)
>  Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>  iEYEARECAAYFAkgIijwACgkQ9CaO5/Lv0PBFHACfaRiSezHeWHpnaPI/2NRyqGR2
>  nZsAn32xEYEJ3VzREBoDaFC3iLZyC7Q3
>  =Jnab
>  -----END PGP SIGNATURE-----
>
>
>
>  ---------------------------------------------------------------------
>  To start a new topic, e-mail: users@tomcat.apache.org
>  To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Wang Han <it...@gmail.com>.
Hi Chris,

Just received the latest version NM software and it works well with
Thread.sleep works now.
It seems old NM SW bug caused Thread.sleep() failed.

the latest NM will send 60 concurrent requests maximum and I
configured the "Connector" element as:
 <Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443" enableLookups="true" disableUploadTimeout="true"
acceptCount="250" maxThreads="250" connectionTimeout="20000"...

Not sure whether it can meet the NM requirement , any suggestion?

I just get a Linux box with 1G memory to host my Servlet.Will update
you after I finish the test.

B.R
Han


On Fri, Apr 18, 2008 at 7:47 PM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>
>  Han,
>
>  Wang Han wrote:
>  | I have tried Thread.sleep() in my servlet and it fails.
>  | My NM app throws exception and can't handle such response..
>
>  What exception is thrown? I can't see a reason why Thread.sleep wouldn't
>  work.
>
>
>  - -chris
>
>  -----BEGIN PGP SIGNATURE-----
>  Version: GnuPG v1.4.9 (MingW32)
>  Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>  iEYEARECAAYFAkgIijwACgkQ9CaO5/Lv0PBFHACfaRiSezHeWHpnaPI/2NRyqGR2
>  nZsAn32xEYEJ3VzREBoDaFC3iLZyC7Q3
>  =Jnab
>  -----END PGP SIGNATURE-----
>
>
>
>  ---------------------------------------------------------------------
>  To start a new topic, e-mail: users@tomcat.apache.org
>  To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Han,

Wang Han wrote:
| I have tried Thread.sleep() in my servlet and it fails.
| My NM app throws exception and can't handle such response..

What exception is thrown? I can't see a reason why Thread.sleep wouldn't
work.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgIijwACgkQ9CaO5/Lv0PBFHACfaRiSezHeWHpnaPI/2NRyqGR2
nZsAn32xEYEJ3VzREBoDaFC3iLZyC7Q3
=Jnab
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Wang Han <it...@gmail.com>.
Hi all,

Thanks for your interesting suggestion.

I have tried Thread.sleep() in my servlet and it fails.
My NM app throws exception and can't handle such response..

Will try he other 2 method and see what will happen.

B.R
Hanks

On Thu, Apr 17, 2008 at 3:18 PM, Benjamin Lerman <to...@ambre.net> wrote:
> > To start with, I'd take the naive approach and see whether it worked
>  > well enough for the job.  I'd use thread.sleep(), and make sure I had
>  > enough worker threads (configured in server/conf.xml) to handle the
>  > number of outstanding requests you want to generate.  That could be
>  > many thousands (I don't know your requirements), and each one
>  > potentially consumes a thread on the host operating system, so make
>  > sure you're running on a system that has enough memory and enough
>  > threads configured in the OS.  Sorry I can't be specific on what
>  > "enough" is, but I've never done this myself!
>  >
>  > A second - and completely different - approach would be to throttle the
>  > bandwidth out of the server in some way, such that the responses were
>  > buffered for the required time.  I'm not sure this is feasible at the
>  > link layer, as I presume you're using HTTP, so the TCP acks would have
>  > to get back in a timely fashion.  If you're able to manage that
>  > somehow, though, connecting the Tomcat server via the networking
>  > equivalent of two tin cans and a piece of string - possibly a serial
>  > lead? - might provide the slowdown you're looking for.
>
>   A third solution: compute your result immediately, keep that in the
>  session as well as the time of the request, forward to a waiting view
>  that will wait client side and then ask the result on a specific URL,
>  then when asked for the result, check that 1) the result has been
>  computed, if this is not the case returns an error, 2) enough time has
>  passed, else re-forward to the waiting view. If all is correct, send the
>  result that lies in the session.
>
>         Benjamin Lerman
>
>
>
>  ---------------------------------------------------------------------
>  To start a new topic, e-mail: users@tomcat.apache.org
>  To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Benjamin Lerman <to...@ambre.net>.
> To start with, I'd take the naive approach and see whether it worked
> well enough for the job.  I'd use thread.sleep(), and make sure I had
> enough worker threads (configured in server/conf.xml) to handle the
> number of outstanding requests you want to generate.  That could be
> many thousands (I don't know your requirements), and each one
> potentially consumes a thread on the host operating system, so make
> sure you're running on a system that has enough memory and enough
> threads configured in the OS.  Sorry I can't be specific on what
> "enough" is, but I've never done this myself!
>
> A second - and completely different - approach would be to throttle the
> bandwidth out of the server in some way, such that the responses were
> buffered for the required time.  I'm not sure this is feasible at the
> link layer, as I presume you're using HTTP, so the TCP acks would have
> to get back in a timely fashion.  If you're able to manage that
> somehow, though, connecting the Tomcat server via the networking
> equivalent of two tin cans and a piece of string - possibly a serial
> lead? - might provide the slowdown you're looking for.

 A third solution: compute your result immediately, keep that in the
session as well as the time of the request, forward to a waiting view
that will wait client side and then ask the result on a specific URL,
then when asked for the result, check that 1) the result has been
computed, if this is not the case returns an error, 2) enough time has
passed, else re-forward to the waiting view. If all is correct, send the
result that lies in the session.

	Benjamin Lerman

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Can we slow down the speed of servlet response ?

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Wang Han [mailto:itwanghan@gmail.com]
> the app sends some request to servlet and will handle the response
> after 5 minutes.
> But in the servlet side, it handles the request too fast and always
> sends response back to app in 30 seconds.
>
> So I wonder is there a way to add some delay in tomcat to slow down
> the speed of response?
>
> I know invoking thread.sleep() in servlet is not recommend , so any
> other way please?

It's not recommended because the thread is considered busy through the sleep, and isn't recycled to handle another request.  This is a big problem in high-load environments as you want maximum throughput with minimum threads... but, you have an unusual requirement!

To start with, I'd take the naive approach and see whether it worked well enough for the job.  I'd use thread.sleep(), and make sure I had enough worker threads (configured in server/conf.xml) to handle the number of outstanding requests you want to generate.  That could be many thousands (I don't know your requirements), and each one potentially consumes a thread on the host operating system, so make sure you're running on a system that has enough memory and enough threads configured in the OS.  Sorry I can't be specific on what "enough" is, but I've never done this myself!

A second - and completely different - approach would be to throttle the bandwidth out of the server in some way, such that the responses were buffered for the required time.  I'm not sure this is feasible at the link layer, as I presume you're using HTTP, so the TCP acks would have to get back in a timely fashion.  If you're able to manage that somehow, though, connecting the Tomcat server via the networking equivalent of two tin cans and a piece of string - possibly a serial lead? - might provide the slowdown you're looking for.

                - Peter "1200/75 is the future" Crowther

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Wang Han <it...@gmail.com>.
Hi Reich, Lloyd, Chris,

Finally the issue is resolved by enabling APR feature in tomcat. Now
the NM can use 40 concurrent threads to talk with 100 simulated
devices with 70s delay on each successfully.

But I am not very clear yet why I have to use APR instead of NIO
connector in the scenario :)

Meanwhile, I can't try all methods in our mail thread due to some restriction:
1. change "on the client-side", the NM is black box to me, so hard to
modify its code;
2. Comet event, it's interesting, I will spend some time to learn it.

Anyway, thanks all of you for your suggestion to help me address the problem!

B.R
Han


  Unfortunately The NM application is a black box to me, I have no
idea about its implementation detail at all, so it is hard to make any
change on the "client side".

I tried to let the NM application talk with 100 simulated devices,
it communicates with 97 devices successfully with 60 secs delay on each.

But there are still 3 devices that get failed when talk to the NM.
the 3 devices respond

On Fri, Apr 25, 2008 at 1:19 AM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>
>  Lloyd,
>
>
>  DIGLLOYD INC wrote:
>  | I think you're barking up the wrong tree here--use a Mock Object (a
>  | dummy) to stub out your app so it thinks it's calling the Servlet.
>  | After you've tested your app working, then revert to actually sending
>  | the request to Tomcat.
>
>  That's a great idea.
>
>  Han, how do you contact the servlet from your client? Do you use
>  straight HttpURLConnections?
>
>  If so, then you can use a library I wrote to test this sort of thing:
>  http://sourceforge.net/projects/tuc/
>
>  Hope that helps,
>
>  - -chris
>
>  -----BEGIN PGP SIGNATURE-----
>  Version: GnuPG v1.4.9 (MingW32)
>  Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>  iEYEARECAAYFAkgQwRwACgkQ9CaO5/Lv0PCZjgCggszeMR1gwOuwmNfbGZ/fTdsz
>  ZcgAnR2rLUeLSOzMbsXpbr+KeXLP7v5Z
>  =5a4D
>  -----END PGP SIGNATURE-----
>
>
>
>  ---------------------------------------------------------------------
>  To start a new topic, e-mail: users@tomcat.apache.org
>  To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lloyd,

DIGLLOYD INC wrote:
| I think you're barking up the wrong tree here--use a Mock Object (a
| dummy) to stub out your app so it thinks it's calling the Servlet.
| After you've tested your app working, then revert to actually sending
| the request to Tomcat.

That's a great idea.

Han, how do you contact the servlet from your client? Do you use
straight HttpURLConnections?

If so, then you can use a library I wrote to test this sort of thing:
http://sourceforge.net/projects/tuc/

Hope that helps,
- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgQwRwACgkQ9CaO5/Lv0PCZjgCggszeMR1gwOuwmNfbGZ/fTdsz
ZcgAnR2rLUeLSOzMbsXpbr+KeXLP7v5Z
=5a4D
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Can we slow down the speed of servlet response ?

Posted by DIGLLOYD INC <di...@diglloyd.com>.
Han,

I think you're barking up the wrong tree here--use a Mock Object (a  
dummy) to stub out your app so it thinks it's calling the Servlet.   
After you've tested your app working, then revert to actually sending  
the request to Tomcat.

If the Servlet provides real data that must come from the servlet,  
wrap the request on the client side, maintaining a queue of requests  
and responses *on the client side*.  Make your app use this client- 
side facility, and have that facility insert the delay when in test  
mode.

Lloyd

On Apr 16, 2008, at 6:24 PM, Wang Han wrote:

> Hi all,
>
> The story is:
>                              http
> NM app  <-------->   servlet
>
> the app sends some request to servlet and will handle the response
> after 5 minutes.
> But in the servlet side, it handles the request too fast and always
> sends response back to app in 30 seconds.
>
> So I wonder is there a way to add some delay in tomcat to slow down
> the speed of response?
>
> I know invoking thread.sleep() in servlet is not recommend , so any
> other way please?
>
> B.R
> Han
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Lloyd Chambers
http://diglloyd.com

[Mac OS X 10.5.2 Intel, Tomcat 6.0.16]





---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org