Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat request timeout

In my web application there are some requests which last longer than 20 seconds. But in some situations the code can lead to infinite loop or something similar which slows down the server.

I want to put a request timeout for 60 sec on the server side. Is this implemented in tomcat?

like image 359
Horatiu Jeflea Avatar asked Aug 22 '11 08:08

Horatiu Jeflea


People also ask

What is Tomcat connection timeout?

connectionTimeout. The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.

How many request Can a Tomcat server handle at a time?

The default installation of Tomcat sets the maximum number of HTTP servicing threads at 200. Effectively, this means that the system can handle a maximum of 200 simultaneous HTTP requests.

How does Tomcat handle concurrent requests?

APR allows Tomcat to use Apache server libraries to further enhance its capabilities as a web server. NIO mode enables Tomcat to simultaneously handle multiple connections per thread by using poller threads to keep connections alive and worker threads to process incoming requests.

What is maxThreads in Tomcat?

By default, if the maximum threads value is not set, Tomcat uses a default value of 200 maximum threads. Here is an example: <connector connectiontimeout="20000" maxthreads="400" port="8080" protocol="HTTP/1.1" redirectport="8443" />


1 Answers

With Tomcat 7, you can add the StuckThreadDetectionValve which will enable you to identify threads that are "stuck". You can set-up the valve in the Context element of the applications where you want to do detecting:

<Context ...>   ...   <Valve      className="org.apache.catalina.valves.StuckThreadDetectionValve"     threshold="60" />   ... </Context> 

This would write a WARN entry into the tomcat log for any thread that takes longer than 60 seconds, which would enable you to identify the applications and ban them because they are faulty.

Based on the source code you may be able to write your own valve that attempts to stop the thread, however this would have knock on effects on the thread pool and there is no reliable way of stopping a thread in Java without the cooperation of that thread...

like image 148
beny23 Avatar answered Sep 28 '22 10:09

beny23