2

I have an issue with cached requests in Tomcat. Whenever I (re-)start my application, Tomcat begins caching incoming request before the application is fully initialized.

Is there a way to stop Tomcat behaving like this? I found the "cachingAllowed" option in the -Element, but I am not sure about this.

Can you please advise on, how to prevent Tomcat from caching before everything is initialized. The point I would expect requests to be cached is when the server startup is complete.

Many Thanks,

Marc

aQuip
  • 591
  • 3
  • 6
  • 22
  • This is not a bug, its a feature. What case makes you wish to not cache requests? – Grim Nov 30 '15 at 15:03
  • There is no problem with this feature, unless it caches about 1000 requests, which will be executed in the first millisecond after application start. This causes the system, which has limited memory, to throw OutOfMemoryExceptions. – aQuip Nov 30 '15 at 15:08
  • Ok... I understand the problem now. You mean OutOfMemoryErrors. – Grim Nov 30 '15 at 15:09
  • @PeterRader Can I somehow limit the number of maximum incoming requests? – aQuip Nov 30 '15 at 15:16
  • maximum incomming request != cached requests. You can increase the swap-space to have more memory. – Grim Nov 30 '15 at 15:19
  • Yeah I know, but maybe a limit to the max of incoming requests, will give the application a chance to handle all cached requests. – aQuip Nov 30 '15 at 15:21

1 Answers1

1

The effect you are describing is called request queuing. By default Tomcat starts and listens to its configured port. When the first request comes in, it triggers that the corresponding web application is deployed and started. All requests that come in before the application is started are blocked and processing starts when the application startup is done.

The above description is a little simplified, because depending on your Tomcat connector type and configuration there are different areas where requests can blocked and queued up:

  • A processing thread waits for the application to start. The limit is controlled by maxThreads.
  • A request waits for a processing thread. The limit is controlled by maxConnections.
  • An incoming TCP connection is accepted by the operating system but not yet handled by Tomcat. This is controlled by acceptCount. (BTW: I set this to 0)

As said, how the parameters work in detail may vary by connector type.

This is how you can control the limits and for the understanding what is going on. I think your effect will get better with setting acceptCount to 0.

Actually, the same problem and question was asked in: how to make http port to open after application startup in tomcat No real answer there, also. It seams this is not how Tomcat is designed to work. Solutions I can think of, but not yet tried myself:

  • Find a way to start Tomcat with a disabled connector (I found no parameter for that...) and enable it after startup by JMX
  • Switch to an embedded Tomcat or Jetty, that gets started from the application
Community
  • 1
  • 1
cruftex
  • 5,545
  • 2
  • 20
  • 36