I'm trying to verify that HTTP persistent connections are being used during communication with a Tomcat webserver I've got running. Currently, I can retrieve a resource on my server from a browser (e.g. Chrome) and verify using netstat that the connection is established:
# visit http://server:8080/path/to/resource in Chrome
[server:/tmp]$ netstat -a
...
tcp 0 0 server.mydomain:webcache client.mydomain:55502 ESTABLISHED
However, if I use curl, I never see the connection on the server in netstat.
[client:/tmp]$ curl --keepalive-time 60 --keepalive http://server:8080/path/to/resource
...
[server:/tmp]$ netstat -a
# no connection exists for client.mydomain
I've also tried using the following curl command:
curl -H "Keep-Alive: 60" -H "Connection: keep-alive" http://server:8080/path/to/resource
Here's my client machine's curl version:
[server:/tmp]$ curl -V
curl 7.19.5 (x86_64-unknown-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 libssh2/1.1
Protocols: tftp ftp telnet dict http file https ftps scp sftp
Features: IDN IPv6 Largefile NTLM SSL libz
How do I get curl to use a persistent/keepalive connection? I've done quite a bit of Googling on the subject, but with no success. It should be noted that I've also used links
on the client machine to retrieve the resource, and that does give me an ESTABLISHED
connection on the server.
Let me know if I need to provide more information.
curl already uses keepalive by default.
As an example:
Produces the following:
This snippet:
Indicates it re-used the same connection.
Use the same "
curl -v http://my.server/url1 http://my.server/url2
" invocation against your server and check that you see the same message.Consider using tcpdump instead of netstat to see how the packets are handled. netstat will only give you a momentary glimpse of what's happening, whereas with tcpdump you'll see every single packet involved. Another option is Wireshark.
If your server allows 'KeepAlive On', you can use telnet to keep a persistent connection going like so:
One way to test HTTP persistent connection/Keep-Alive is to see if the TCP connection is reused for subsequent connections.
For example. I have a file containing link of http://google.com repeated multiple times.
Running below command will open http://google.com multiple times with the same TCP connection.
And during this time if you netstat you can find that the TCP connection has not changes and the older one is resued (The socket remains the same).
But when we ask client to use HTTP 1.0 which dose not support persistent HTTP connection the socket address changes
from this we can be sure that the TCP connection is reused.
--keepalive-time
man curl... man.. :D