如何快速全面验证网络端口连通性
- 2021 年 8 月 27 日
- 筆記
- Jmeter, Performance testing
1. 说明
如何高效的验证压力机能否访问被测服务器的指定端口?我们常用的方法是手动远程到被测服务器去执行telnet命令,或者试几笔交易?那么,有没有更加便捷手段……
2. 背景简述
我们测试、生产环境的网络端口访问权限都很严格,每有新的压测项目,压测前期的准备工作必有网络工单申请的流程,网络工单中涉及的压力机访问被测服务器端口都有一定的有效期。
再有就是经常会遇到:以前压测过的项目所涉及的端口访问权限,时间久了我们也很难清楚的知道,目前压力机到被测服务器端口的连通性。我们8月项目排期比较满,用了很多时间来做各个服务器端口验证工作,那么有没有一种快速全面的验证方式呢?
手工验证工作其实是很痛苦的一件事,于是我就萌生了一种想法,能不能改变现状,把验证网络的端口的效率提上来。目前采用的随机挑选法,总感觉不靠谱(其实是被坑过)。如果那么多的服务器每个都自己手动去验证,这种重复性的工作,感觉浪费好多时间。
3. 常见方案
脚本场景:百度首页,10vu-50vu,每分钟增加10vu,增加到最大50vu保持1min后,开始以每分钟10vu递减,总计运行10分钟。
我们常用的方案有两种:
-
- 随机挑选一个服务器进行验证
- 压力机单线程执行被测交易脚本
这两种的方案,都不是那么完美。随机挑选一台被测服务器进行验证,即使这台服务器验证通过,就能保证其余服务器均正常么,显然不是,这明明是在犯以偏概全的错误,其实也是在给自己的懒找借口。我们再简单说下直接用压力机单线程执行被测交易脚本,确实问题不大,能满足我们遇到得大多数情况。那么什么情况不太适用呢,那就生产压测,在生产环境压测,有些敏感的交易是不能随便发送
4. BaoLu NetworkPort Sampler
- 插件图:
- Master模式验证
我们以百度的443端口为例:
结果图:
我们再将端口号改成8888,看下结果:
- Slave模式验证
在Maser模式基础上,启动一台Salve机器,IP为192.168.1.117 ,JMeter GUI模式下分布式执行
再来看下salve机器控制台日志:
jmeter-slave.log 部分日志
1 2021-08-26 22:56:26,375 INFO c.l.n.s.CheckNetworkPortSampler: 2 ___ ___ ___ ___ ___ ___ ___ 3 /\__\ /\ \ /\ \ /\ \ /\ \ /\__\ /\__\ 4 /:/ /_\:\ \ /::\ \ /::\ \ /::\ \ /:/ //:/ _/_ 5 /:/__//\/::\__\ /::\:\__\/::\:\__\/:/\:\__\/:/__//:/_/\__\ 6 \:\ \\::/\/__/ \:\::/ /\/\::/ /\:\/:/ /\:\ \\:\/:/ / 7 \:\__\\:\__\ \::/ / /:/ / \::/ / \:\__\\::/ / 8 \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ 9 10 Initializing..... baolu-jmeter-plugins V1.0.0 11 12 2021-08-26 22:56:26,438 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 13 2021-08-26 22:56:26,438 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group. 14 2021-08-26 22:56:26,438 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error 15 2021-08-26 22:56:26,438 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false 16 2021-08-26 22:56:26,441 INFO o.a.j.t.ThreadGroup: Started thread group number 1 17 2021-08-26 22:56:26,441 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started 18 2021-08-26 22:56:26,444 INFO o.a.j.t.JMeterThread: Thread started: 192.168.1.117:1099-Thread Group 1-1 19 2021-08-26 22:56:26,503 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times 20 2021-08-26 22:56:26,503 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to UTF-8 21 2021-08-26 22:56:26,503 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true 22 2021-08-26 22:56:26,503 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000 23 2021-08-26 22:56:26,533 INFO c.l.n.s.CheckNetworkPortSampler: 192.168.1.117 -> www.baidu.com 443 connected 24 2021-08-26 22:56:26,556 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.1.117:1099-Thread Group 1-1 25 2021-08-26 22:56:26,556 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.1.117:1099-Thread Group 1-1 26 2021-08-26 22:56:26,561 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test 27 2021-08-26 22:56:26,561 INFO o.a.j.s.DataStrippingSampleSender: Test Ended on 192.168.1.117:1099 28 2021-08-26 22:56:26,561 INFO o.a.j.s.BatchSampleSender: Test Ended on 192.168.1.117:1099 29 2021-08-26 22:56:26,575 INFO o.a.j.e.StandardJMeterEngine: Test has ended on host 192.168.1.117:1099 30 2021-08-26 22:57:05,125 INFO o.a.j.s.BatchSampleSender: Using batching for this run. Thresholds: num=100, time=60000 31 2021-08-26 22:57:05,126 INFO o.a.j.s.DataStrippingSampleSender: Using DataStrippingSampleSender for this run with stripAlsoOnError: true 32 2021-08-26 22:57:05,158 INFO o.a.j.e.RemoteJMeterEngineImpl: Creating JMeter engine on host 192.168.1.117:1099 base '.' 33 2021-08-26 22:57:05,158 INFO o.a.j.e.RemoteJMeterEngineImpl: Remote client host: 192.168.1.109 34 2021-08-26 22:57:05,158 INFO o.a.j.s.FileServer: Set new base='.' 35 2021-08-26 22:57:05,164 INFO o.a.j.e.RemoteJMeterEngineImpl: Cleaning previously set properties: {} 36 2021-08-26 22:57:05,164 INFO o.a.j.e.StandardJMeterEngine: Applying properties {} 37 2021-08-26 22:57:05,169 INFO o.a.j.e.RemoteJMeterEngineImpl: Running test 38 2021-08-26 22:57:05,170 INFO o.a.j.e.StandardJMeterEngine: Running the test! 39 2021-08-26 22:57:05,171 INFO o.a.j.s.SampleEvent: List of sample_variables: [] 40 2021-08-26 22:57:05,229 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 41 2021-08-26 22:57:05,229 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group. 42 2021-08-26 22:57:05,229 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error 43 2021-08-26 22:57:05,229 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false 44 2021-08-26 22:57:05,230 INFO o.a.j.t.ThreadGroup: Started thread group number 1 45 2021-08-26 22:57:05,230 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started 46 2021-08-26 22:57:05,230 INFO o.a.j.t.JMeterThread: Thread started: 192.168.1.117:1099-Thread Group 1-1 47 2021-08-26 22:57:10,271 ERROR c.l.n.s.CheckNetworkPortSampler: 192.168.1.117 -> www.baidu.com 8888 connection timed out 48 2021-08-26 22:57:10,306 INFO o.a.j.t.JMeterThread: Thread is done: 192.168.1.117:1099-Thread Group 1-1 49 2021-08-26 22:57:10,307 INFO o.a.j.t.JMeterThread: Thread finished: 192.168.1.117:1099-Thread Group 1-1 50 2021-08-26 22:57:10,312 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test 51 2021-08-26 22:57:10,313 INFO o.a.j.s.DataStrippingSampleSender: Test Ended on 192.168.1.117:1099 52 2021-08-26 22:57:10,313 INFO o.a.j.s.BatchSampleSender: Test Ended on 192.168.1.117:1099 53 2021-08-26 22:57:10,325 INFO o.a.j.e.StandardJMeterEngine: Test has ended on host 192.168.1.117:1099
6. 结语
本次实验,宝路仅采用一台salve机器,毕竟家里电脑有限。。。。当我们有N多个目的服务器IP PORT的连通性要验证,再搭配个CSV Data Set Config配件原件即可。
采用插件的形式也方便了测试平台的快速接入,大家根据自己的实际情况来操作!最后,希望能对大家有所帮助,有任何意见或建议欢迎反馈!
对了!目前该插件已在 baolu-jmeter-plugins 文章中更新,欢迎下载体验!