Cogman
Cogman

Reputation: 2160

With mod_jk, tomcat, and jersey, how do you keep a long running request alive?

On the client side, we are using HttpClient for communication. On the server side we are using Jersey and tomcat.

Our requests look like this

client -> load balancer -> server

The problem is this, a client will make a request to the server; That request spills over the 180 second timeout for mod_jk which causes the load balancer to kill off the connection. What I need is some way to signal to mod_jk that "yes, this connection is alive and progressing" so that it doesn't terminate the connection. Alternatively, it would be nice if we could signal to mod_jk that "This request may take a long time".

Our not great solution right now in the load balancer we have bumped up the socket_timeout to 20 minutes. The better solution is to get the server to signal that it is still working. The best solution is to make the request run faster (it tops out at 12 minutes).

How can I make the server signal that it is still moving forward? Unfortunately sending down partial data doesn't really work well for us as this request is to get an expensive and large object and the object really isn't streamable.

Upvotes: 0

Views: 345

Answers (1)

Marcel Stör
Marcel Stör

Reputation: 23565

Tomcat has different implementations of the response output stream.

The different behavior is caused by the AJP connector which connects the load balancer and Tomcat (just guessing you use AJP). With Tomcat standalone one can write to the response output stream and the content is buffered. When you write to a response output stream which is backed by the AJP connector the content is flushed immediately. That makes sense because if there isn't a constant stream of data passed from Tomcat to load balancer it will "hang up" after while treating this as a timeout.

So, I suggest you find some way of continuously or periodically sending "some data" while the real response pay load is being prepared.

Upvotes: 2

Related Questions