Check number of TCP connections to the server

时间:2017-07-12 08:22:16

标签: java linux tcp connection-pooling microservices

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.

1 个答案:

答案 0 :(得分:0)

"确定"你的netstat输出与awk:

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

这将获取netstat输出,然后检查第6个分隔的数据(使用默认空间)并根据ESTABLISHED进行检查。如果满足条件,则使用以下内容将第四个分隔的数据分割为:到阵列端口。其中的第二个元素将具有连接端口,因此将针对8585进行检查。如果满足此条件,则连接计数会递增。在awk脚本结束时,将打印最终的cnt变量。