简体   繁体   English

检查与服务器的TCP连接数

[英]Check number of TCP connections to the server

We have two application servers viz. 我们有两个应用程序服务器。 s1 and s2. s1和s2。 For every request come to s1, it calls the services exposed by s2. 对于到达s1的每个请求,它都会调用s2公开的服务。 s1 is running port 8585 and s2 runnng on port 8989 s1正在运行端口8585而s2正在端口8989

  • We have implemented the Http connection pooling on the s1, so connections will be re-used while communicating with s2. 我们已经在s1上实现了Http连接池,因此在与s2进行通信时将重新使用连接。 For that we are using apache httpclient library and PoolingHttpClientConnectionManager for connection polling. 为此,我们使用apache httpclient库和PoolingHttpClientConnectionManager进行连接轮询。
  • HttpClient intance is created only once at startup and shared while calling service exposed by s2. HttpClient实例仅在启动时创建一次,并在调用s2公开的服务时共享。
  • While creating HttpClient, we have configured HttpClient max connection to 50 创建HttpClient时,我们已将HttpClient的最大连接数配置为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. 我们在s2中添加了10秒的延迟,因此每个请求都在等待10秒才能获得响应。

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 我们正在尝试使用Jmeter生成对服务器s1的200个并发请求,并按照netstat命令检查由服务器s1到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. 有时连接计数显示100,有时显示65或其他任何数字。

"Sure up" your netstat output with awk: 用awk“确定”您的netstat输出:

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. 这将获取netstat输出,然后检查第6个定界数据(具有默认空间),并根据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. 第二个元素将具有连接端口,因此将对8585进行检查。如果满足此条件,则连接计数将增加。 At the end of the awk script, the final cnt variable is printed. 在awk脚本的末尾,将打印最终的cnt变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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