You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Matthew Turany <mt...@anokii.com.au> on 2014/03/27 04:08:05 UTC

Is it possible to send a 'keep-alive' packet back to client session every x seconds?

Hi,

Trying to figure out if this is possible; apache reverse-proxy sitting in
front of a server running tomcat serving a web app. Due to the amount of
data in the backend DB, when a user generated report is requested, it can
take several minutes (3-4) for the report to be presented to the browser
session.

In this particular case the client browser is sitting behind a gateway /
firewall that will drop the connection after 60 seconds of 'inactvity' e.g.
no traffic back to the browser (high-security environment).

The app presents a web pop-up stating "Your report is being prepared" and
session keepalive timeouts are all set accordingly, however since the
gateway doesn't see any active traffic it will close the connection forcing
the client browser to reconnect on a new connection which in affect loses
their report. (Note: that this all works fine for anyone not behind that
particular gateway)

Is it possible to configure either apache or tomcat to send a packet every
x number of seconds so that at the client end the gateway thinks the
session is still active and will keep the connection open, or is this
something best put into the actual web app?

Thanks,
Matt

Re: Is it possible to send a 'keep-alive' packet back to client session every x seconds?

Posted by Frederik Nosi <fr...@postecom.it>.
Hi Matthew,

On 03/28/2014 01:35 AM, Matthew Turany wrote:
> Thanks everyone, development tells me that their going to build the
> function into the application.

You're lucky ;-)

> trying to build custom kernels and then using a tcp_keepalive would be a
> logistic nightmare.

I know you solved differently this issue, but in case other people is 
watching this thread, who said you have to build custom kernels?!? Just 
change a sysctl knob and be done with that. Exagerating, it's just ~100 
characers to type, no reboot required neither. Check here for the 
details, i'm sure will come handy in other situations:

http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html


>
> Cheers,
> Matt
>
>
[...]

Frederik

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


Re: Is it possible to send a 'keep-alive' packet back to client session every x seconds?

Posted by Matthew Turany <mt...@anokii.com.au>.
Thanks everyone, development tells me that their going to build the
function into the application.
trying to build custom kernels and then using a tcp_keepalive would be a
logistic nightmare.

Cheers,
Matt


On Fri, Mar 28, 2014 at 12:53 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Mark,
>
> On 3/27/14, 5:38 AM, Mark Thomas wrote:
> > On 27/03/2014 03:08, Matthew Turany wrote:
> >> Is it possible to configure either apache or tomcat to send a
> >> packet every x number of seconds so that at the client end the
> >> gateway thinks the session is still active and will keep the
> >> connection open, or is this something best put into the actual
> >> web app?
> >
> > http://tomcat.apache.org/connectors-doc/reference/workers.html
> > socket_keepalive
> >
> > You'll need to configure the OS to send the packets frequently
> > enough.
> >
> > Alternatively, change the application design: - One request to
> > trigger generation of the report - N requests to retrieve report
> > which returns either "still processing" (maybe with an ETA) or
> > "here it is".
>
> +1
>
> I believe this is a better design in the long-run. It also allows you
> to do things like off-line processing of batches without changing your UI.
>
> Another thing you could do is simulate the above by using a
> report-builder thread launched from your servlet, and then have your
> request-processing thread to a flush() on the response (causing
> chunked encoding to be used), then sleep for some amount of time
> (maybe 1-5 seconds), then check the status of the report, then flush()
> again (not sure if it will keep emitting 0-length chunks if you flush
> over and over again), then sleep again.
>
> This seems like a perfect use case for async processing.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iQIcBAEBCAAGBQJTNFd6AAoJEBzwKT+lPKRYANwP/Rx3W5KQQnLzMx/xEY41cix0
> JuAEGxZVQyX5LDwLlB5iivIAGdVqLZxXGP/4on/sIgl+XjC59hkU4N77oLokb3Cl
> heAgUmR9VA4KsUTMeSJmN0Km5lMOzCv3c+Ru5fAjSpsNKgp2SjsitpdGgRfebd1y
> djQfemWIkC6bBHjtW4PbwGkva9Kny8FVx2Ius8f6V+jKcHGLGztWIfy99rR0Oya3
> 2dP/JboBPH0PYW19Jhor7qM7IMJXJjdRSswnBc63e7runvw8hA1DD3KDW0mHceVo
> Q4Q0WW1zRaT1DOzkmQhOs4H68ev20EjV9DZu8Md17kJVrwkeFMN+GGNppLeivzdK
> UZHkEWbZjDZRcIGR0iEQQZGLVCRMImNsm+fBoO6piXrr8UFpzMUqXLMiSuD3Woab
> GFtvydUBuO4gyxAHXh2yW+XJ1iZBSfigUBvTZUKOyS1sEURBKmgTopySuJaKPhYN
> OMYCQ8e5MKbcxl09qp7JRg+H/jfIr9NBgakWrQRe4R1Pox1doMaNZsJufwpkbxH2
> 0CKNuLClIrvQC/iw5D7McB0o5PY5brOMGzWfdb6Psgnrq/4FB3QDdSCbIaQ8JF+E
> GfRZ5D2VE73ueb8dYiElA0t3fEV0DSdqOtxR40IwROlpR6My7HBUVgy/7dxkxEg7
> xXj/B0T5nbShYxZrlw3S
> =RtBD
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Is it possible to send a 'keep-alive' packet back to client session every x seconds?

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

Mark,

On 3/27/14, 5:38 AM, Mark Thomas wrote:
> On 27/03/2014 03:08, Matthew Turany wrote:
>> Is it possible to configure either apache or tomcat to send a
>> packet every x number of seconds so that at the client end the
>> gateway thinks the session is still active and will keep the
>> connection open, or is this something best put into the actual
>> web app?
> 
> http://tomcat.apache.org/connectors-doc/reference/workers.html 
> socket_keepalive
> 
> You'll need to configure the OS to send the packets frequently
> enough.
> 
> Alternatively, change the application design: - One request to
> trigger generation of the report - N requests to retrieve report
> which returns either "still processing" (maybe with an ETA) or
> "here it is".

+1

I believe this is a better design in the long-run. It also allows you
to do things like off-line processing of batches without changing your UI.

Another thing you could do is simulate the above by using a
report-builder thread launched from your servlet, and then have your
request-processing thread to a flush() on the response (causing
chunked encoding to be used), then sleep for some amount of time
(maybe 1-5 seconds), then check the status of the report, then flush()
again (not sure if it will keep emitting 0-length chunks if you flush
over and over again), then sleep again.

This seems like a perfect use case for async processing.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTNFd6AAoJEBzwKT+lPKRYANwP/Rx3W5KQQnLzMx/xEY41cix0
JuAEGxZVQyX5LDwLlB5iivIAGdVqLZxXGP/4on/sIgl+XjC59hkU4N77oLokb3Cl
heAgUmR9VA4KsUTMeSJmN0Km5lMOzCv3c+Ru5fAjSpsNKgp2SjsitpdGgRfebd1y
djQfemWIkC6bBHjtW4PbwGkva9Kny8FVx2Ius8f6V+jKcHGLGztWIfy99rR0Oya3
2dP/JboBPH0PYW19Jhor7qM7IMJXJjdRSswnBc63e7runvw8hA1DD3KDW0mHceVo
Q4Q0WW1zRaT1DOzkmQhOs4H68ev20EjV9DZu8Md17kJVrwkeFMN+GGNppLeivzdK
UZHkEWbZjDZRcIGR0iEQQZGLVCRMImNsm+fBoO6piXrr8UFpzMUqXLMiSuD3Woab
GFtvydUBuO4gyxAHXh2yW+XJ1iZBSfigUBvTZUKOyS1sEURBKmgTopySuJaKPhYN
OMYCQ8e5MKbcxl09qp7JRg+H/jfIr9NBgakWrQRe4R1Pox1doMaNZsJufwpkbxH2
0CKNuLClIrvQC/iw5D7McB0o5PY5brOMGzWfdb6Psgnrq/4FB3QDdSCbIaQ8JF+E
GfRZ5D2VE73ueb8dYiElA0t3fEV0DSdqOtxR40IwROlpR6My7HBUVgy/7dxkxEg7
xXj/B0T5nbShYxZrlw3S
=RtBD
-----END PGP SIGNATURE-----

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


Re: Is it possible to send a 'keep-alive' packet back to client session every x seconds?

Posted by André Warnier <aw...@ice-sa.com>.
Mark Thomas wrote:
> On 27/03/2014 03:08, Matthew Turany wrote:
>> Is it possible to configure either apache or tomcat to send a packet every
>> x number of seconds so that at the client end the gateway thinks the
>> session is still active and will keep the connection open, or is this
>> something best put into the actual web app?
> 
> http://tomcat.apache.org/connectors-doc/reference/workers.html
> socket_keepalive
> 
> You'll need to configure the OS to send the packets frequently enough.

That's a bit the hammer, isn't it ? Under Linux at least, this seems to be a global kernel 
setting, so it applies to all connections.

> 
> Alternatively, change the application design:
> - One request to trigger generation of the report
> - N requests to retrieve report which returns either "still processing"
> (maybe with an ETA) or "here it is".
> 

Apart from any gateways/proxies/firewalls, there is also a browser timeout : if the 
browser sends a request, and then does not get a response for 4-5 minutes, eventually it 
will time-out, close the connection, and display "the server is not responding.. try again 
later".

Another possibility is to have the application periodically send some kind of "partial 
response" to the browser (e.g., a line of ".."), to be replaced by the real response when 
it's ready.  It's a 20-year old trick, and it is a bit tricky to get right, but it still 
works.  Of course it means that the application has to be able to do that, and is not 
itself waiting on a call to a slow external resource.



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


Re: Is it possible to send a 'keep-alive' packet back to client session every x seconds?

Posted by Mark Thomas <ma...@apache.org>.
On 27/03/2014 03:08, Matthew Turany wrote:
> Is it possible to configure either apache or tomcat to send a packet every
> x number of seconds so that at the client end the gateway thinks the
> session is still active and will keep the connection open, or is this
> something best put into the actual web app?

http://tomcat.apache.org/connectors-doc/reference/workers.html
socket_keepalive

You'll need to configure the OS to send the packets frequently enough.

Alternatively, change the application design:
- One request to trigger generation of the report
- N requests to retrieve report which returns either "still processing"
(maybe with an ETA) or "here it is".

Mark


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


Re: Is it possible to send a 'keep-alive' packet back to client session every x seconds?

Posted by Frederik Nosi <fr...@postecom.it>.
Hi,
On 03/27/2014 04:08 AM, Matthew Turany wrote:
> Hi,
>
> Trying to figure out if this is possible; apache reverse-proxy sitting in
> front of a server running tomcat serving a web app. Due to the amount of
> data in the backend DB, when a user generated report is requested, it can
> take several minutes (3-4) for the report to be presented to the browser
> session.
>
> In this particular case the client browser is sitting behind a gateway /
> firewall that will drop the connection after 60 seconds of 'inactvity' e.g.
> no traffic back to the browser (high-security environment).
> The app presents a web pop-up stating "Your report is being prepared" and
> session keepalive timeouts are all set accordingly, however since the
> gateway doesn't see any active traffic it will close the connection forcing
> the client browser to reconnect on a new connection which in affect loses
> their report. (Note: that this all works fine for anyone not behind that
> particular gateway)
>
> Is it possible to configure either apache or tomcat to send a packet every
> x number of seconds so that at the client end the gateway thinks the
> session is still active and will keep the connection open, or is this
> something best put into the actual web app?

The usual solution in this case is using Keepalive TCP. Check this, it's 
based on Linux but
the theory works on every other OS:

http://www.tldp.org/HOWTO/html_single/TCP-Keepalive-HOWTO/

> Thanks,
> Matt
>