"Turn" use JMeter for stress testing

Source: Internet
Author: User

  The stress test takes the software response speed as the test target, especially when the large number of concurrent users in a short period of time access, software performance and anti-pressure capability.

JMeter is an open-source stress testing tool, and the latest release version is 2.3.4, which not only tests WEB servers, but also tests the capabilities of databases , JMS, Web Service, LDAP, JUNIT and many other objects. : http://jakarta.apache.org/site/downloads/downloads_jmeter.cgi

Here is a brief introduction to JMeter.

    • The test plan is the starting point of the test, the container for all other components.
    • A thread group is a component used to simulate user concurrency. Each task of jmeter is handled by threads. Thread groups have three properties, number of threads, ramp-up period, and number of loops. The number of threads is the number of concurrent, ramp-up period represents how long it takes to create all the threads defined in the number of threads.
    • Logic controllers can organize samplers to make complex test requests.
    • Configure the configuration required in the main configuration sampler in the component.
    • Timer sets the time interval between requests.
    • The predecessor processor is typically used to modify requests (request).
    • Sampler (sampler), the main actor. Each sampler can be monitored by the listener and generate test results.
    • The post processor is typically used to come up with the returned data (Response).
    • Assertion to determine if the sampler is working properly.
    • Listeners, collects and organizes test results, and can specify formats to generate files in the form of XML, CSV, and so on.

The workbench can add non-test components, one of the most important is the HTTP proxy server.

The HTTP proxy server can be used to record test scripts. By setting the browser's proxy server to 127.0.0.1:8080, and then starting the JMeter HTTP proxy server, you can record the actions in the browser. HTTP proxy server can set the Include mode and exclusion mode, I generally use the exclusion mode to exclude some CSS, JS, GIF, PNG and so on.

This is how the basic components of the jmeter are used, please continue to see below.

JMeter not a lot of Chinese information, I Google a bit, I found that basically did not introduce how to use the information step-by-step. I'll tidy it up first.

is probably the following aspects:

    1. Recording scripts
    2. Using user-defined parameters
    3. Using the Controller
    4. Using timers
    5. Using a front-facing post processor
    6. Using listeners

I am also just the entry level, so the writing out of things may be relatively simple, suitable for novice reference use.

This time, we introduce a script recording using an HTTP proxy server.

JMeter can record scripts or use other tools, such as badboy to record scripts suitable for jmeter use, and we use JMeter's own features by default.

Open JMeter, right-click on the Workbench node, add >> non-test Components >> HTTP proxy server, use default settings.

Then set the browser to set the proxy server to 127.0.0.1:8080.

Then start the HTTP proxy server to open Google as an example, and it generates the following script:

It recorded a lot of JS, CSS, PNG, GIF path, and these are not useful for test scripts, we can in the HTTP proxy server exclusion mode settings, do not log these.

Set up the exclusion mode, restart the HTTP proxy server, open the first page of Google again, found that the finished script is much more concise.

To search for "JMeter" as an example, the script is finished:

In some use to JS a lot of pages, JS action will be recorded in, like the/complete/search is the input box JS action, can be deleted.

JMeter's script recording is this way, you can also use other tools, such as Badboy, it is more simple to use, specifically can refer to the official website http://www.badboy.com.au/.

Finally, when setting up an HTTP proxy server, there are two places to be aware of:

To verify that port 8080 is conflicting, it is occupied by another program, such as a Web server. If there is a conflict, you can change to another port that does not conflict

The port of the JMeter HTTP proxy server and the port to which the browser is set are consistent.

How to use external data in JMeter, JMeter also provides a series of components, mostly included in the configuration components, such as: CSV Data Set config,random Variable, user-defined variables, etc., in addition, the predecessor processor >> User parameters can also use a custom variable.

Here I focus on user parameters and how to use CSV Data Set config.

User parameters can set parameters for each thread in the test plan or test plan, and if the parameters are set less than the number of threads, they will be reused.

Continue to Google , if you want to search by different keywords, you can set the following in the user parameters:

1. Right-click [Thread Group], add >> Pre-processor >> user parameters, add 5 users to the user parameter symbol. Then add a variable [keyword],5 user corresponding value can be filled in casually.

2. Set the number of threads for the [thread Group] to 5

3. Modify the request named/search in the script. Modify the value of the field named [Q] to ${keyword}

User parameters can also read the CSV file, the above example if you read the CSV, you need to

1. Create a new file in Apachejmeter.jar's sibling directory, Keyword.txt, where the content is one keyword per line

2. Set the number of threads for the [thread Group] to 5

3. If user and variable are set, name is keyword, user _1 is ${_stringfromfile (keyword.txt)}

4. Modify the request named/search in the script. Modify the value of the field named [Q] to ${keyword}

After doing this, click Run >> start, you will see the number of threads in the upper-right corner of the JMeter from 0 to 5, after execution, it becomes 0

Note: In general, the number of variables defined in the number of threads and user parameters is the same unless you have special needs

I generally use the user parameters to define some very important constants, such as reading large-scale data, we can use the CSV data Set Config. The CSV data Set config is read by default in the specified CSV file, and each thread uses one of the data in order, and if the number of threads is more than the actual data, the data is reused in order.

1. Right-click [Thread Group], add >> Configure component >> CSV Data set Config, set filename as CSV file, Variable names is the variable name, set to keyword, Delimiter is usually a comma, four boxes are generally set to follow

2. Set the number of cycles for the [thread Group] to be permanent and the number of threads to 1

3. Modify the request named/search in the script. Modify the value of the field named [Q] to ${keyword}

After doing this, click Run >> start, you will see the number of threads in the upper-right corner of the JMeter from 0 to 1, after execution, it becomes 0

Of course, my example is relatively simple, there is a slightly more complicated, and often used in the case is the user name, password combination. At the time of large data volume testing, because of the problem of caching and so on, it is impossible to use the same user to perform the operation, so to use a lot of users to execute, this time the CSV data Set config is very useful, or when the data is inserted, it is also useful.

How to use the external data already know, but how to confirm that each thread is executed by our defined keywords?

There are several ways to use the listener, or you can use assertions, both of which are left to be introduced later.

"Turn" use JMeter for stress testing

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.