22

What are some different ways/tools to verify that keep-alive is working on the server from the client's end?

Ron Garrity
  • 373
  • 1
  • 3
  • 5

2 Answers2

52

As Ron Garrity says, you can use Curl like this:

curl -Iv http://www.aptivate.org 2>&1 | grep -i 'connection #0'

And it outputs these two lines if keep-alive is working:

* Connection #0 to host www.aptivate.org left intact
* Closing connection #0

And if keep-alive is not working, then it just outputs this line:

* Closing connection #0

The output Connection ... left intact proves that the server did not close the connection, and it is available for the client to reuse. It's up to the client to decide whether it actually wants to reuse the connection or not. You can demonstrate it with Curl by listing the same URL twice on the command line

curl -Iv http://www.aptivate.org --next http://www.aptivate.org 2>&1 | grep -i '#0'

in which case it will give output something like:

Re-using existing connection! (#0) with host ...
Piran
  • 103
  • 3
qris
  • 1,151
  • 11
  • 18
7

You could try

ab -n 500 -c 5 -k http://www.domain.com/

and look via top, if 5 workers are constantly serving the requests keepalive should work (-k) switch. Do the same without -k and see the difference.

Cheers Izac

Izac
  • 1,758
  • 1
  • 11
  • 11
  • 1
    that's what i wound up doing, though i read that curl can tell you this too. if it says "Connection #0 to host www.example.com left intact", it means keep-alive is on. – Ron Garrity Aug 26 '11 at 20:53