基於TCP協議使用JMeter進行性能測試-Linux系統
在Linux系統中,JMeter沒有圖形界面,想要在其上進行測試任務,需要先在Windows上設計好測試方案,然後將.jmx文件內容拷到Linux系統,使用命令進行測試。
-
在Windows系統上,JMeter安裝包下載,並打開。參考博客:使用JMeter測試工具對服務器併發執行能力,響應速度等方面進行壓力測試。
-
打開JMeter,設計TCP請求任務。 右鍵 --> 配置元件 --> TCP取樣器配置。兩個紅框內容必須填。
-
添加線程組,配置TCP取樣器。 如果已經配置完TCP取樣器,則不需要重新填寫IP和端口號。
-
在Linux上使用。 下載JMeter安裝包並解壓,進入目錄。
[root@s1 local]# cd /usr/local/apache-jmeter-5.1.1
[root@s1 apache-jmeter-5.1.1]# ls
bin docs extras lib LICENSE licenses NOTICE printable_docs README.md
[root@s1 apache-jmeter-5.1.1]# cd bin
[root@s1 bin]# ls
ApacheJMeter.jar create-rmi-keystore.bat heapdump.sh jmeter-n-r.cmd jmeter-t.cmd mirror-server.cmd shutdown.cmd templates
BeanShellAssertion.bshrc create-rmi-keystore.sh jaas.conf jmeter.properties jmeterw.cmd mirror-server.sh shutdown.sh threaddump.sh
BeanShellFunction.bshrc examples jmeter jmeter-server krb5.conf reportgenerator.properties stoptest.cmd upgrade.properties
BeanShellListeners.bshrc hc.parameters jmeter.bat jmeter-server.bat log4j2.xml report-template stoptest.sh user.properties
BeanShellSampler.bshrc heapdump.cmd jmeter-n.cmd jmeter.sh mirror-server saveservice.properties system.properties
[root@s1 bin]# chmod 777 jmeter.sh
[root@s1 bin]# sh jmeter.sh -v
Mar 26, 2019 10:17:46 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
_ ____ _ ____ _ _ _____ _ __ __ _____ _____ _____ ____
/ \ | _ \ / \ / ___| | | | ____| | | \/ | ____|_ _| ____| _ \
/ _ \ | |_) / _ \| | | |_| | _| _ | | |\/| | _| | | | _| | |_) |
/ ___ \| __/ ___ \ |___| _ | |___ | |_| | | | | |___ | | | |___| _ <
/_/ \_\_| /_/ \_\____|_| |_|_____| \___/|_| |_|_____| |_| |_____|_| \_\ 5.1.1 r1855137
Copyright (c) 1999-2019 The Apache Software Foundation
將TCP-big.jmx文件內容複製到Linux新文件上。Windows的.jmx文件一般放在./bin目錄下。
test.jtl文件存放的是壓測結果,可以將其倒進Windows下進行查看。
[root@analysis bin]# vi TCP-big.jmx
[root@analysis bin]# ./jmeter -n -t TCP-big.jmx -l test.jtl
Creating summariser <summary>
Created the tree successfully using tcp-test1.jmx
Starting the test @ Thu May 09 06:17:09 PDT 2019 (1557407829904)
Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
summary = 21 in 00:00:00 = 84.0/s Avg: 61 Min: 19 Max: 104 Err: 0 (0.00%)
Tidying up ... @ Thu May 09 06:17:10 PDT 2019 (1557407830905)
... end of run
注意:.jmx文件中的IP和端口號要根據服務器端進行隨時更改。如果程序不正常終止,需要更改端口號,因爲之前的端口號可能被佔用。
其他的測試相關內容和HTTP類似。