7

I'm developing a web application with Spring and Tomcat 6. Sometimes, for some reason a request takes too long to complete and it reduces the server's performance. Is it possible to limit the request execution time in Tomcat 6 or Spring? Other approaches on this problem are welcome. Thanks.

  • Is the request taking long time for processing data or for fetching data from database? Based on that I could suggest solutions. – Vivek Viswanathan Jan 28 '13 at 09:02
  • 1
    Possible duplicate of http://stackoverflow.com/questions/7145131/tomcat-request-timeout – JoseK Jan 28 '13 at 09:04
  • @Vivek: Long requests are mainly for processing data. We can put them to a queue and process in order, but it's hard to determine which requests are eligible. –  Jan 28 '13 at 09:15
  • Why does the long request "reduce the server's performance". Even if you use the answer from TechExchange below, if it's the job on the queue that is slowing down your server, and a long-running request comes in and gets added to the queue, just timing out the connection won't fix your performance issue; the job will still be on the queue and will be processed presumably. – matt freake Jan 28 '13 at 09:24
  • @Disco3 With a queue we can response immediately and process jobs later, and it's possible to arrange them so that long jobs won't be processed at the same time. –  Jan 28 '13 at 09:41

3 Answers3

1

Using the HttpConnector configuration connectionTimeout

modify your server.xml

<Connector ... connectionTimeout="xxxx"

where xxxx is amount of milliseconds

TheWhiteRabbit
  • 15,480
  • 4
  • 33
  • 57
  • as far as i know , this is the ans – Hussain Akhtar Wahid 'Ghouri' Jan 28 '13 at 09:13
  • 2
    According to the documentation, connectionTimeout is "The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented". In my case, the request has been fully received. –  Jan 28 '13 at 09:23
0

Is it possible to limit the request execution time in Tomcat 6 or Spring?

Yes it is possible, but you would need to implement this yourself.

The basic idea is that the request method needs to use a Timer to schedule an interrupt for itself for N seconds in the future. Then it needs to check periodically during the request processing to see if it has been interrupted. Finally, it needs to cancel the timer if it finishes before the timeout.


The above assumes that it is the servlet should limit the time it spends processing a request. If instead you wanted to implement the timeout on the client side, it is easy to put timeout on the completion of a request; e.g. see Tomcat request timeout.

(But the problem with a client-side timeout is that the server won't know that the client has given up waiting, and will keep processing the request regardless. It is easy to get into big problems with this. Imagine a request that takes a lot longer to complete than the timeout, combined with a client that repeatedly retries requests that it has timed out ...)

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

The above statement by Sthepen is not correct. On client side, when it gives up or the browswer is closed the browser does not of course keep it's socket alive. It does a socket shutdown (recover the memory and the port, right?). The shutdown procedure will send the laid down signals to the server side socket - RST i believe.