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 文章中更新,歡迎下載體驗!