Jmeter (1) - from entry to proficient - environment construction (detailed tutorial)

content

1. Introduction to JMeter

2. Comparison between JMeter and LoadRunner

3. JMeter Disadvantages

4. Download and install

5. JMeter run

6. JMeter directory structure analysis

7. JMeter main configuration file


1. Introduction to JMeter

Apache JMeter is a 100% pure JAVA desktop application designed as software for testing client/server architectures (eg web applications). It can be used to test the performance of static and dynamic resources, such as: static files, Java Servlet, CGI Scripts, Java Object, database and FTP server and so on. JMeter can be used to simulate large loads to test the robustness of a server, network or object or to analyze overall performance under different loads. At the same time, JMeter can help you perform regression testing on your application. Use the test scripts and assertions you create to verify that your program returns the expected values. For higher adaptability, JMeter allows to call secondary developed jar packages to enrich your test scenarios; JMeter allows you to use regular expressions to create these assertions.

2. Comparison between JMeter and LoadRunner

JMeter is an open source (with typical open source tool characteristics: the interface is not beautiful ) testing tool, although it has many shortcomings compared with LoadRunner, for example: its result analysis ability is not as detailed as LoadRunner; it has many advantages:

  • Open source, he is an open source free software, you don't need to pay anything to use it,
  • Small, compared to the huge size of LR (the latest LR11 is nearly 4GB), it is very small and does not require installation, but requires a JDK environment because it is a tool developed using java.
  • Powerful functions, jmeter was originally designed as a simple web performance testing tool, but after several updates and expansions, it can now complete tests on databases, FTP, LDAP, WebService, etc. Because of its open source nature, of course, you can also extend its functions according to your own needs. Extremely scalable. It can test performance, test interfaces, and even automate UI work by loading browser drivers!

The biggest difference between the two: jmeter does not support IP spoofing, while LR does.

  From the above, Jmeter has many advantages, but nothing and nothing can violate a rule, that is, "no one is perfect without gold", Jmeter also has shortcomings, let's take a look at Jmeter's For the shortcomings, Brother Hong won't delve into whether it was brought in by the mother's womb or caused by the day after tomorrow. Generally, for software, it is brought in the mother's womb, and it is inherently insufficient. The reason is: during development, there may be insufficient consideration for some reasons, resulting in the disease in the womb.

3. JMeter Disadvantages

  Using JMeter cannot verify the JS program, nor the page UI, so it is necessary to cooperate with Selenium to complete the testing of Web2.0 applications.

4. Download and install

4.1JMeter installation

1. http://jmeter.apache.org/Download the latest version of JMeter, unzip the file to any directory

2. Install JDK and configure the environment variable JAVA_HOME

3. System requirements: JMeter2.11 requires JDK1.6 or above to support running

4. JMeter can run on the following operating systems: Unix, Windows and Open VMS.

5. It should be avoided that the jdk path and the jmeter path have Chinese and spaces, otherwise there will be exceptions, which will also cause problems in remote testing.

4.2JMeter plugin installation

1. Plugin download address: Install :: JMeter-Plugins.org

2. Unzip the plugin after downloading: find JMeterPlugins-Extras.jar, and put JMeterPlugins-Extras.jar in the apache-jmeter-2.12\lib\ext directory.

5. JMeter run

5.1 Two postures of JMeter startup

5.1.1 Start pose 1

Enter the bin directory, double-click to run jmeter.bat to start jmeter

Note: There will be two windows when opened, JMeter's command window and JMeter's graphical operation interface. The command window cannot be closed.

 5.1.2 Start pose 2

Enter the bin directory and double-click the ApacheJmeter.jar package to run

Note: There will be only one window when it is opened. The graphical operation interface of JMeter is different from the one above.

 

6. JMeter directory structure analysis

6.1 root directory

The root directory of the decompressed Jmeter installation package is as follows:

6.2 Description of the root directory (from top to bottom)

(1) The backup directory script backup directory, the files in it are all files ending with .jmx suffix

  Actually, this directory does not exist after installation and decompression. This is because after Brother Hong used JMeter, JMeter automatically created this directory, and then backed up the script file.

(2) bin directory executable file directory

  1. Jmeter.bat: is the main script to start jmeter.
  2. Jmeter-server.bar: is used to achieve online load.
  3. Jmeter.properties: It is the main configuration file of jmeter. More than 80% of the configuration items are implemented through this file. (PS: After modifying the configuration file, you need to restart Jmeter to take effect)

Jmeter.bat opens the main interface of Jmeter

  The log file name used by Jmeter is defined in Jmeter.properties. By default, the log can be viewed in Jmeter.log

(3) dosc directory

  The files in the docs directory are JMeter's Java Docs, and the content in the usermanual subdirectory of printable_docs is the JMeter user manual document, of which component_reference.html is the most commonly used core component help document. This directory stores the API documents of jmeter's official documents, which are mainly used for secondary development.

(4) extras directory

  The files in this directory provide support for the build tool Ant, which can be used to automate tests, such as batch script execution, to generate HTML-formatted reports, and when the test is running, the test data can be recorded, and Jmeter will automatically generate a . jtl file, put the file in the extras directory, and run "ant -Dtest=filename report" to generate the test statistics report. Can also be used for continuous integration.

(5) lib directory

  This directory contains two subdirectories, the ext subdirectory stores the core jar package of JMeter, and the junit subdirectory stores JUnit test scripts. The packages that user extensions depend on should be placed directly in the lib directory instead of lib/ext.

Note: The package file in zip format cannot be recognized, so the required package files are required to end with .jar

(6) Licenses jmeter software license file directory

(7) printable_docs directory

  This directory stores the official help documents provided by jmeter. There are some commonly used JMeter script cases in the demos subdirectory of printable_docs, which can be used as a reference. Printable half version catalog.

(8) LICENSE JMeter - License Instructions

(9) NOTICE JMeter - simple information description

(10) README.md ——The official basic introduction of JMeter

6.3 Open backup, as shown below:

 

6.4 Open bin, as shown below:

Examples: The directory contains Jmeter usage examples, open it is a csv sample

ApacheJMeter.jar: JMeter source package

jmeter.bat: Windows startup file

jmeter.log: Jmeter running log file

jmeter.sh: linux startup file

jmeter.properties: System configuration file

jmeter-server.bat: The server used for Windows distributed testing, start the load generator service file

jmeter-server: start the load generator file under Linux

shutdown.cmd under windows jmeter closes the file

stoptest.cmd jmeter test stop file under windows

6.5 Open docs, as shown below:

api: api files and css and image styles

Uploading...Reupload canceled

6.6 Open lib, as shown below:

This folder is full of some jar packages

 

7. JMeter main configuration file

7.1jmeter.properties configuration file

jmeter.properties, defines the key configuration of jmeter operation; the following Hongge lists the key configuration of this file as follows:

#默认语言设置

      language=en

#捕捉cookie开关

      CookieManager.save.cookies=true

#配置编辑器的字体和尺寸

     jsyntaxtextarea.font.family=宋体

     jsyntaxtextarea.font.size=20

#配置默认编码格式

     sampleresult.default.encoding=UTF-8

#SSL 配置:重点关注下面几个配置# 指定 HTTPS 协议层  
   # 指定 HTTPS 协议层
   https.default.protocol=TLS
   # 指定 SSL 版本,实际应用中可能需要修改
   https.default.protocol=SSLv3
   # 设置启动的协议
   https.socket.protocols=SSLv2Hello SSLv3 TLSv1
   # 缓存控制,控制 SSL 是否可以在多个迭代中重用
   https.use.cached.ssl.context=true

#JMeter 测试项目自动备份配置
   # 设置是否启用自动备份,默认是 true
   jmeter.gui.action.save.backup_on_save=true
   # 设置自动备份目录,默认备份至 JMeter 根目录的 backups下
   jmeter.gui.action.save.backup_directory=
   # 设置自动备份项目数,默认为最近 10 个
   jmeter.gui.action.save.keep_backup_max_count=10

#远程主机配置
  # 配置远程主机的 IP,默认为本机。用逗号","可以设置多个远程主机
  remote_hosts=127.0.0.1
  # 多个远程主机指定示例如下,其中:后为端口
  remote_hosts=127.0.0.1:1099,127.0.0.1:1200,127.0.0.1:1300
  对于 RMID 的配置请直接看配置文件中的选项说明

#日志管理配置
  # 设置日志格式
  log_format_type=default
  # 设置日志输出级别
  log_level.jmeter=INFO
  # 设置 junit 日志输出级别
  log_level.jmeter.junit=DEBUG
  # 设置日志输出目标文件,默认为 jmeter.log
  log_file=jmeter.log

# jmeter.bat 关键配置修改
#为了更优化的使用 jmeter,需要对 jmeter.bat 中的一些配置根据当前机器的配置进行优化,这里进行关键配置项说明,大家根据自己的机器的配置来进行修改。jvm 相关配置,大概在 80 行左右,找到这些配置,对其中的数值根据当前机器的硬件配置来修改。
  set HEAP=-Xms2048m -Xmx2048m
  set NEW=-XX:NewSize=512m -XX:MaxNewSize=512m
  set SURVIVOR=-XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=50%
  set TENURING=-XX:MaxTenuringThreshold=2
  if %current_minor% LEQ "8" (
  rem Increase MaxPermSize if you use a lot of Javascript in your Test Plan :
  set PERM=-XX:PermSize=512m -XX:MaxPermSize=1024m)

# 设置输出报告模板格式

     jmeter.save.saveservice.output_format = csv

copy

7.2system.properties configuration file

system.properties, which defines the system variables of the Java process, which can be queried through System.getProperties().

7.3 user.properties configuration file

user.properties, custom configuration, can override jmeter.properties.

7.4 Expansion

1. The configuration file may have a priority relationship. It seems that user.properties will override jmeter.properties. Generally, modifying the configuration is modifying or adding user.properties. It is not recommended to modify jmeter.properties.

2. By modifying the following configuration of reportgenerator.properties, the sampling time can be reduced and the sampling accuracy can be increased. Other content of the generated report can also be modified here. Of course, it is recommended that these modifications be placed in user.properties

 

3. Modify these configurations in jmeter.properties to control the display time of the report DashBoard. It is recommended to put these configurations in user.properties

 

4. The display time of the output control report is as follows:

Time flies, and the time to say goodbye has come again.  Of course, in addition to dry goods, I also won benefits for everyone! 

 

Guess you like

Origin blog.csdn.net/ZangKang1/article/details/123905680