简体   繁体   中英

Check number of TCP connections to the server

We have two application servers viz. s1 and s2. For every request come to s1, it calls the services exposed by s2. s1 is running port 8585 and s2 runnng on port 8989

  • We have implemented the Http connection pooling on the s1, so connections will be re-used while communicating with s2. For that we are using apache httpclient library and PoolingHttpClientConnectionManager for connection polling.
  • HttpClient intance is created only once at startup and shared while calling service exposed by s2.
  • While creating HttpClient, we have configured HttpClient max connection to 50

how to check the connection polling is working correctly?

We have added 10 sec delay in s2, so every request is waiting for 10 sec to get the response.

We are trying with Jmeter to generate 200 concurrent request to server s1 and following netstat command to check number of connections established by the server s1 to s2

while [ 1 ] ; do netstat -apnt | grep -E '8585.*ESTABLISHED' ;echo "---";sleep 3; done

it gives random behavior. Some times connection count shows 100, some times it shows 65 or any other number.

"Sure up" your netstat output with awk:

netstat -antp | awk '$6 == "ESTABLISHED" { split ($5,prt,":");if ( prt[2] == "8585" ) { cnt++ } } END { print cnt }'

This will take the netstat output and then check the 6th delimited piece of data (with the default space) and check it against ESTABLISHED. If condition is met, the fourth delimited piece of data is split using : into an array port. The second element of this will have the connecting port and so this is checked against 8585. If this condition is met, the connection count is incremented. At the end of the awk script, the final cnt variable is printed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM