JMeter官方文档学习笔记
jmeter可以测试的内容包括:
(1)Web - HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)
(2)SOAP / REST Webservices
(3)FTP
(4)Database via JDBC
(5)LDAP
(6)Message-oriented middleware (MOM) via JMS
(7)Mail - SMTP(S), POP3(S) and IMAP(S)
(8)Native commands or shell scripts
(9)TCP
(10)Java Objects
官方文档地址:https://jmeter.apache.org/usermanual/get-started.html#overview
1. Getting Started
1.0 Overview
jmeter的使用步骤:
(1)Test plan building,构建测试计划;
(2)Load Test running,压力测试,注意:压测时要适当调大jmeter的堆空间(默认大小1G),另外压测时不要使用GUI模式;
(3)Load Test analysis,利用第2步产生的报表数据对压测进行分析。
1.1 Requirements
(1)JMeter 4.0要求Java 8或者Java 9
虽然可以使用JRE,但是推荐安装JDK,特别是要测试HTTPS时,因为需要用到
JDK的keytool utility。
(2)因为jmeter是java程序,所以对操作系统没有要求。
1.2 Optional
(1)jmeter使用了apache的Xerces XML parser来处理xml文件,你也可以自己指定xml解析器,只需要将第三方jar包放置于JMeter的classpath目录下,然后在jmeter.properties文件里指定xml解析器的全类名即可。
(2)可以利用jmeter的POP3(S)、IMAP(S) 、SMTP(S) sampler将测试报告以邮件的形式发送出去。
(3)如果要测试HTTPS,可以使用 SSL Manager对客户端进行认证
(4)如果要测试JDBC,需要在JMeter的classpath目录下添加响应的JDBC driver
(5)如果要测试JMS,需要在JMeter的classpath目录下添加JMS Client jar包
(6)ActiveMQ JMS需要activemq-all-X.X.X.jar
1.3 Installation
下载jmeter最新的安装包后解压即可,注意不要使用带空格的路径
1.4 Running JMeter
运行bin目录下的jmeter.bat (for Windows) or jmeter (for Unix)文件即可。
GUI mode should only be used for creating the test script, NON GUI mode must be used for load testing
bin目录下还有一些其他有用的脚本,这里我们只介绍unix环境下的,windows环境的也大同小异
(1)jmeter
运行jmeter(默认是GUI模式),这里定义了一些可能不适用于所有JVM的JVM设置
(2)jmeter-server
以server模式启动jmeter(使用适当的参数调用JMeter脚本)
(3)jmeter.sh
very basic JMeter script (You may need to adapt JVM options like memory settings).
非常基础的jmeter脚本(您可能需要调整JVM选项,如内存设置)
(4)mirror-server.sh
以非GUI模式运行jmeter镜像服务
(5)shutdown.sh
运行一个Shutdown客户端来优雅地停止一个非GUI实例
(6)stoptest.sh
运行一个Shutdown客户端来粗鲁地停止一个非GUI实例
可以通过以下方式指定jvm参数:
JVM_ARGS="-Xms1024m -Xmx1024m" jmeter -t test.jmx [etc.]
可以将JVM参数保存在bin目录下的setenv.sh文件中,这样通过脚本启动jmeter的时候,脚本就会自动加载该文件中的设置,脚本内容类似如下:
# This is the file bin/setenv.sh,
# it will be sourced in by bin/jmeter
# Use a bigger heap, but a smaller metaspace, than the default
export HEAP="-Xms1G -Xmx1G -XMaxMetaspaceSize=192m"
# Try to guess the locale from the OS. The space as value is on purpose!
export JMETER_LANGUAGE=" "
可以定义如下环境变量:
(1)GC_ALGO
Java runtime options to specify JVM garbage collection algorithm. Defaults to -XX:+UseG1GC -XX:MaxGCPauseMillis=250 -XX:G1ReservePercent=20
(2)HEAP
Java runtime options for memory management used when JMeter is started. Defaults to -Xms1g -Xmx1g -X:MaxMetaspaceSize=256m
(3)JAVA_HOME
Must point at your Java Development Kit installation. Required to run the with the "debug" argument. On some OSes it JMeter will try its best to guess the location of the JVM.
(4)JMETER_COMPLETE_ARGS
If set indicates, that JVM_ARGS and JMETER_OPTS are to be used, only. All other options like HEAP and GC_ALGO will be ignored. Default is empty.
(5)JMETER_HOME
May point to your JMeter install dir. If empty it will be set relative to the jmeter script.
(6)JMETER_LANGUAGE
Java runtime options to specify used language. Defaults to -Duser.language=en -Duser.region=EN
(7)JMETER_OPTS
Java runtime options used when JMeter is started. Special options for operating systems might be added by JMeter.
(8)JRE_HOME
Must point at your Java Runtime installation. Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME are both empty, JMeter will try to guess JAVA_HOME. If JRE_HOME and JAVA_HOME are both set, JAVA_HOME is used.
(9)JVM_ARGS
Java options to be used when starting JMeter. These will be added before JMETER_OPTS and after the other JVM options. Default is empty