"0 cost to achieve Web performance test: Based on Apache JMeter" Reading notes

Source: Internet
Author: User
Tags http cookie log log

1, performance test concept performance testing purposes:
    • Evaluate system capabilities to verify that the system meets expected performance metrics
    • Identify weaknesses in the system
    • System tuning for improved system performance
    • Detect problems that can occur over long periods of time, revealing hidden issues
    • Verify stability, Reliability
Common performance indicators
    1. b/S Architecture (H5 page belongs to B/S architecture): General focus on Web server performance metrics

      • Average number of responses per second = Total requests/seconds
      • Average number of business script iterations per second
      • A successful request
      • Failed requests
      • Number of successful clicks
      • Number of failed clicks
      • Number of hits per second
      • Number of successful clicks per second
      • Number of failed clicks per second
      • Number of attempts to connect
      • Throughput
    2. c/S architecture (native belongs to C/s architecture): Software backend is usually a database

      • Number of user connections, that is, the number of connections to the database
      • Database deadlock
      • The database Cache hit condition
Average number of concurrent test environments

C= (max online *10%)/n,n is a production environment and test environment Server configuration conversion ratio, typically 4.

2, JMeter introduction JMeter working principle

JMeter can act as a proxy network between the Web server and the browser interfacing capture the browser's request and the response of the Web server so that the performance test script is generated

JMeter installation directory
  1. JMeter Tuning settings: Adjusting the Jmeter.bat under the Bin folder

    set HEAP=-Xms512m -Xmx512m set NEW=-XX:NewSize=128m -XX:MaxNewSize=128m set SURVIVOR=-XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=50% set TENURING=-XX:MaxTenuringThreshold=2

    By experience, the heap value is set at most half of physical memory and defaults to 512MB. If more than half, the JMeter will run slower and even "memory overflow" errors will occur. If you run an exception, you can view the information in the Jmeter.log log.

  2. Detailed Log acquisition: If the user wants to get a more detailed log, you can modify the Log_level.jmeter in the Jmeter.properties file in the bin directory. The default is info, which can be modified to debug when debugging. Property settings also have a graphical interface, select Workbench Right-click "Add"-"non-test Element"-"Properties Display"

  3. The usermanual subdirectory of Printable_docs is the user manual document, where component_reference.html is the most commonly used core component help document. Users can also view them in the Help document in the graphical interface.

  4. JMeter Boot: JMeter has multiple boot modes to enter the Bin folder of the JMeter installation directory (Unix system)

    • ./jmeter: Run jmeter (default GUI mode)
    • Jmeter-server: Clothing weapon mode start JMeter, call JMeter script with appropriate parameters
    • Jmeter.sh: A very basic jmeter script that does not specify JVM options
    • mirror-server.sh: Starting JMeter mirror server in non-GUI mode
    • SHUTDOWN.SH: Close a non-GUI instance (elegant)
    • STOPTEST.SH: Stop a non-GUI instance (broken)
  5. JMeter with parameter start:

    • -H help print out useful information and exit
    • -N Non-GUI mode run JMeter in non-GUI mode
    • -t test file, JMeter test script file to run
    • Files that record results with-l log file
    • -R remote execution, starting remote service
    • -H proxy Host, setting up the proxy host used by JMeter
    • -p proxy port, setting the port number of the proxy host used by JMeter
  6. Example: Jmeter-n-t test1.jmx-l logfile1.jtl-h 192.168.1.1-p 8080

  7. Using a proxy server: If the test object is hidden behind a firewall/proxy server, the host name and port number of the firewall/proxy server should be provided to jmeter with the following parameters:

    • -H
    • -P
    • -N: Hosts that do not use proxies (such as localhost)
    • -U: Agent-Authenticated user name, if required
    • -A: Agent-authenticated password, if required
  8. Note: JMeter built-in HTTP proxy Server user record Http/https Protocol browser session, unlike the agent function above, can not be confused

    Example: Jmeter-h my.proxy.server-p 8000-u username-a password-n localhost

3. Web performance test script recording and development JMeter common test elements
  1. Thread Group

    • The ramp-up parameter is used to set the time required for JMeter to reach the maximum number of threads, cannot be set too long or too short, and the recommended initial value is set to ramp-up= bus path number
    • The scheduler can expand the additional dispatch Control Panel, can set "Start Time" "End Time" "duration" "Start delay", "start delay" will invalidate "start Time", "duration" will make "End time" invalid
  2. Controller--Sampler

    • The sampler tells JMeter to send a request to the specified server and waits for the server to request it.
    • Includes: FTP request,http request, JDBC request ...
    • If you intend to send the same class of requests to the same server, consider using the default configuration component
    • Visible as assertions, regular expressions can be used in assertions
  3. Controller-Logic Controller
    • can help control the test logic, especially the number and order of requests
    • All Web tests should add a cookie manager, or JMeter will ignore cookies. Adding the cookie manager to the thread group level ensures that all HTTP requests use the same cookie.
  4. Listener
  5. Timer
    • By default, threads do not have an interval between sending requests
    • The timer can be used as a sub-item of the sampler or logic controller, affecting only the sampler in the scope
    • To add a pause to a location in a test plan, you can use the "Test action" sampler
  6. Assertion
    • The assertion affects all the samplers in action. To affect only one sampler, you need to use the assertion as a child of that sampler
  7. Configuring components
    • You can add or modify requests
    • Valid only for the number of test branches in which it resides. example, assuming that an HTTP cookie manager is placed in a simple controller, the cookie manager is only effective against other logical controllers within the simple controller. For example, the cookie manager is valid for "Web Page1" and "Web Page2" and is not valid for "Web Page3"

- 相比父分支的配置元件,子分支内部的配置元件优先级更高。**注:配置元件“用户定义的参数”会在测试初始阶段执行,无论它处于何处,因此建议将其放在线程组开始部分**
    1. Front-facing processor

      • Perform special operations before the sampler makes a request, often to modify or update certain settings or variable values of the sampler before making a request
      • If attached to a sampler, it will only be executed before the sampler is run
    2. Rear Sampler

JMeter Execution Order Scope rules
    • Configuring components
    • Front-facing processor
    • Timer
    • Sampling device
    • Back-mounted processor
    • Assertion
    • Listener

* example, in the following test process

`Controller    Post-Processor1    Sampler1    Sampler2    Timer1    Assertion1    Pre-Processor1    Timer2    Post-Processor2    `

The order of execution is:

   `Pre-Processor1    Timer1    Timer2    Sampler1    Sampler2    Post-Processor1    Post-Processor2    Assertion1    `

Note 1: Some components follow a layering rule. That is, if the parent test element of the component is a sampler, it takes effect only on the sampler, and if the parent test component is a logical controller, it takes effect on all sub-samplers under that logical controller

Note 2: Configuration components (HTTP header Manager, Cookie Manager, and HTTP Authorization Manager) are handled differently from the default configuration component (the configuration default element). The settings contained by the default configuration symbol are combined into a series of variable values, and the settings of the configuration components are not merged. For a sampler, if there are multiple configuration components within the same scope range, only one configuration component will be applied.

JMeter Property Variables
    1. The JMeter property is globally visible and is typically used to define some default values that are used by JMeter. Cannot be a variable value for a particular thread.
    2. The JMeter variable is a local variable for the test thread. Note: Variables defined in both the test plan and the user-defined variables (configuration symbol) are visible to the entire test plan. If the same variable is defined in more than one user-defined variable, it will only take effect in the last definition. Once a thread is started, the initial value of the entire set of variables is copied to the thread. Other test elements, such as "User variables" (pre-processors) or "Regular expression extractors" (post processors), can be used to redefine variables and only affect the current thread.
    3. Property and variable case sensitivity
    4. Using variable parameterization tests, you can use variables, or for large concurrent stress tests, it is best to have the JMeter property
Recording a Web test script
  1. The JMeter agent does not currently support recording the HTTPS protocol because HTTPS is a security protocol, the agent cannot decipher its communication content and record request parameters or cookies, but the Badboy tool is available.
  2. JMeter Agent Basic Steps

    • Start JMeter, right-click the test plan, add a new thread group: add-"Thread Group", add "HTTP request Defaults", fill in the protocol: Http,ip such as Www.baidu.com,Path left blank, port number 80.
    • Select Workbench and right-click to add "HTTP Proxy Server".
      • Port domain: 8088 indicates the port number used by the agent;
      • Target Controller: Select "Test Plan->thread Group" to indicate which branch of the test tree the agent recorded script will hang under;
      • Click Add in Patterns to Include, create a blank input field, and enter ". *.html".
      • Click Add in Patterns to Exclude, generate a blank input field, enter ". *.gif"
      • Click the Start button at the bottom-start the browser, but do not close the JMeter
    • When recording scripts for different sites, you need to adjust the filter style accordingly. Browser settings:
      • Select tools-"Internet options-" connection-"LAN settings-" use a proxy server for your LAN
      • Address: Enter "Localhost" or the IP address of the machine
      • Port: Enter 8088 (consistent with the port number set by the proxy)
      • Enter "Http://www.baidu.com" in the browser address bar, click on the page on a few links-close the browser, back to the JMeter window
  3. Problems encountered in the actual operation:

    • When you click Start in HTTP Proxy server, the error is as follows:

      2015/09/17 16:24:21 ERROR - jmeter.protocol.http.proxy.ProxyControl: Could not initialise key store java.io.IOException: >> keytool???? java.io.FileNotFoundException: proxyserver.jks (Permission denied) << Command failed, code: 1 ‘keytool -genkeypair -alias :jmeter: -dname "cn=JMeter Proxy (DO NOT TRUST)" -keyalg RSA -keystore proxyserver.jks -storepass {redacted} -keypass {redacted} -validity 7‘

Online search reasons, a, some people say because the java1.7 SDK path is not set correctly, but my settings have been successful. B, some people said to change the path in the Jmeter.bat, so try to modify the file, after the modification still reported wrong. C, some people said on the Mac should add the SDK path in the jmeter.sh file, and then add the following:

Java_home=/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home/bin export JAVA_HOME PATH= $JAVA _home:$ Path Export Path

Another error was reported after adding. D, from one person's website to see another approach is to set the JVM parameters, so try to: export JVM_ARGS=-Dproxy.cert.directory=`readlink -f ~`; /opt/apache-jmeter-2.12/bin/jmeter continue to Error: "readlink: illegal option -- f" , because the Mac Readlink is not available, depending on the brew installation Greadlink replacement, the final solution is as follows:

 a. brew安装,brew官方网站http://brew.sh/对其进行了详细描述:ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

 b. 运行命令brew install coreutils

 c. export JVM_ARGS=-Dproxy.cert.directory=`greadlink -f /Users/ting`

 d. 运行jmeter,./jmeter

The problem is resolved. Run the agent recording again, no more errors.

4, detailed JMeter test element jmeter Logic Controller
    1. Simple controller: For combination samplers and other logic controllers
    2. Cycle controller: Cycle times are set by the loop controller
    3. Only once controller: tells JMeter to execute only once, then loop execution in the test plan skips all requests under the controller
    4. Alternating controller: If the sampler or logic controller is placed under it, the test element under the controller is alternately executed each time the loop jmeter
    5. Random controller: Randomly pick one execution per cycle
    6. Random order controller: Each of its sub-test elements is executed at most once, but the order of execution is random
    7. Throughput controllers (Throughput Controller): Allows the user to set the frequency at which they are executed. Divided into percent execution and total executions
    8. Run-time controller: Controls the length of time that the sub-test element is allowed to run
    9. Module controller: Dynamically replace test plan fragments in the current test plan
Configuring components

Can be used to initialize default values and variables that will be processed at the initial stage of the scope

    1. CSV Data Set Config
    2. HTTP Authorization Manager: Helps testers specify one or more logins for a Web page. When using a browser to access a restricted page, testers can see this kind of verification, the browser will show a login dialog box, when encountering such a page, JMeter will transfer the login information.
    3. HTTP Cache Manager
    4. HTTP Cookie Manager: It stores and sends cookies like a browser
    5. HTTP request default: You can set the default value used by HTTP requests
    6. HTTP Header Manager: You can add or reload HTTP request headers (I understand that it is the header of the HTTP request manager)
    7. JDBC Connection Configuration
    8. Sign-in configuration symbol: You can add or reload user names and passwords for the sampler (as part of its initial settings) using the login configuration symbol
    9. User-defined variables
Timer

Timer processing is preceded by sampling within the uniform scope

    1. Fixed timer: This timer is used if the tester wants each thread to have a fixed interval between requests.
    2. Gaussian random Timer
    3. Constant Throughput Timer: This timer introduces a variable pause duration, which is calculated to ensure that the total throughput is as close to the specified value as possible. If the test server cannot handle so many requests, the timer cannot guarantee that the throughput will not degrade
      • After the timer is adopted, the throughput value is not necessarily constant and can be defined by a variable or function, so that its value can be dynamically changed during the test run.
      • Throughput should not change too frequently during a test run, it takes a certain amount of time for the new value to take effect
    4. Synchronizing Timer: The purpose is to block threads until N threads are blocked and then released together. So synchronizing timer can create a lot of instantaneous pressure at multiple points on the test plan. A collection point function similar to LR. Front-facing processor
    5. User parameters
Post Processor Sampler

0 cost to implement Web performance test: Based on Apache JMeter book notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.