Web服务加Jmeter模拟多线程通信

在测试的过程中,需要模拟多线程通信,马上想到了Jmeter启动多线程去访问Web服务器实现,先简单验证一下

搭建web服务器

已有的CentOS7.2主机上,安装并设置好http服务

# yum install httpd -y   
# vi /etc/httpd/conf/httpd.conf
Listen 80
DocumentRoot "/var/www/html"

[root@localhost html]# vi index.html



    
    第一个静态文件


Hello world!

#
# service httpd start

安装Jmeter

在Windows/CentOS上安装Java8环境的说明网上一搜一大把,这里就不赘述了。下载好的apache-jmeter-5.0.zip在/var/www/html/下也放一份。作为HTTP要获取的文件。

Windows环境

解压缩apache-jmeter-5.0.zip,以管理员身份启动bin/jmeter.bat,正常情况下就能看到Jmeter的GUI。
设置一下语言


让log显示出来,设置log等级,帮助定位


已有的Test Plan下创建一个线程组


此例中5秒启动100个线程,就是每秒启动20个线程

线程组中添加一个HTTP请求,去获取zip文件




此时web服务器上
# pwd
/var/www/html
# ll
total 55624
-rwxr-xr-x. 1 wuli root   56952455 Dec 19 10:56 apache-jmeter-5.0.zip
-rwxr-xr-x. 1 wuli apache      154 Dec 19 09:09 index.html
# 

也可以加一些其它的监控项


验证

在Windows的GUI上,可以将线程组的参数先改小并运行一下。无误后将当前设置保存为thread1.jmx文件,并放到Linux服务器上。
Jmeter是非常“吃资源”的,因此在实际性能测试的时候,应该使用CLI来运行。

命令执行如:jmeter -n -t xx.jmx -l jtl
常用参数解释如下:
-n:说明jmeter非GUI运行
-t:运行的测试计划名称,xxx.jmx路径+文件
-l:JTL文件去保存结果,路径+xxx.jtl
-r: 使用远程执行
-j:保存执行log
-H:代理机主机名或者ip地址
-P:代理机端口

例如:

# pwd
/root/apache-jmeter-5.0/bin
# ./jmeter.sh -n -t thread1.jmx -l abc.jtl
Dec 19, 2018 3:03:35 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
Creating summariser 
Created the tree successfully using thread1.jmx
Starting the test @ Wed Dec 19 15:03:36 ULAT 2018 (1545203016678)
Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4445
summary =     10 in 00:00:38 =    0.3/s Avg: 14141 Min:   794 Max: 32868 Err:     0 (0.00%)
Tidying up ...    @ Wed Dec 19 15:04:16 ULAT 2018 (1545203056076)
... end of run
The JVM should have exited but did not.
The following non-daemon threads are still running (DestroyJavaVM is OK):
Thread[Thread-2,5,main], stackTrace:java.util.prefs.FileSystemPreferences#sync at line:718
java.util.prefs.FileSystemPreferences#flush at line:824
java.util.prefs.FileSystemPreferences#syncWorld at line:464
java.util.prefs.FileSystemPreferences#access$1200 at line:50
java.util.prefs.FileSystemPreferences$4$1#run at line:442

Thread[DestroyJavaVM,5,main], stackTrace:java.lang.Object#wait
java.lang.Thread#join at line:1252
java.lang.Thread#join at line:1326
java.lang.ApplicationShutdownHooks#runHooks at line:107
java.lang.ApplicationShutdownHooks$1#run at line:46
java.lang.Shutdown#runHooks at line:123
java.lang.Shutdown#sequence at line:167
java.lang.Shutdown#shutdown at line:234

# 

查看运行结果

# cat abc.jtl 
timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
1545203017967,794,HTTP请求,200,OK,线程组 1-1,text,true,,56952754,138,2,2,http://10.25.130.254/apache-jmeter-5.0.zip,65,0,46
1545203018290,1991,HTTP请求,200,OK,线程组 1-2,text,true,,56952754,138,2,2,http://10.25.130.254/apache-jmeter-5.0.zip,21,0,14
1545203018778,9388,HTTP请求,200,OK,线程组 1-3,text,true,,56952754,138,8,8,http://10.25.130.254/apache-jmeter-5.0.zip,17,0,2
1545203021031,27041,HTTP请求,200,OK,线程组 1-6,text,true,,56952754,138,7,7,http://10.25.130.254/apache-jmeter-5.0.zip,7043,0,1
1545203021042,31843,HTTP请求,200,OK,线程组 1-7,text,true,,56952754,138,7,7,http://10.25.130.254/apache-jmeter-5.0.zip,7025,0,4
1545203021041,32867,HTTP请求,200,OK,线程组 1-4,text,true,,56952754,138,5,5,http://10.25.130.254/apache-jmeter-5.0.zip,7010,0,5
1545203021043,32868,HTTP请求,200,OK,线程组 1-5,text,true,,56952754,138,4,4,http://10.25.130.254/apache-jmeter-5.0.zip,7040,0,2
1545203053901,1309,HTTP请求,200,OK,线程组 1-8,text,true,,56952754,138,3,3,http://10.25.130.254/apache-jmeter-5.0.zip,224,0,5
1545203053267,1973,HTTP请求,200,OK,线程组 1-9,text,true,,56952754,138,2,2,http://10.25.130.254/apache-jmeter-5.0.zip,852,0,632
1545203053903,1345,HTTP请求,200,OK,线程组 1-10,text,true,,56952754,138,1,1,http://10.25.130.254/apache-jmeter-5.0.zip,274,0,2
# 

你可能感兴趣的:(Web服务加Jmeter模拟多线程通信)