Académique Documents
Professionnel Documents
Culture Documents
Introduction
In this tutorial, we will go over how to use Apache JMeter to perform basic load and
stress testing on your web application environment. We will show you how to use the
graphical user interface to build a test plan and to run tests against a web server.
JMeter is an open source desktop Java application that is designed to load test and
measure performance. It can be used to simulate loads of various scenarios and output
performance data in several ways, including CSV and XML files, and graphs. Because it
is 100% Java, it is available on every OS that supports Java 6 or later.
Prerequisites
In order to follow this tutorial, you will need to have a computer that you can run JMeter
on, and a web server to load test against. Do not run these tests against your
production servers unless you know they can handle the load, or you may negatively
impact your server's performance.
You may adapt the tests in this tutorial to any of your own web applications. The web
server that we are testing against as an example is a 1 CPU / 512 MB VPS running
WordPress on a LEMP Stack, in the NYC2 DigitalOcean Datacenter. The JMeter
computer is running in the DigitalOcean office in NYC (which is related to the latency of
our tests).
Please note that the JMeter test results can be skewed by a variety of factors, including
the system resources (CPU and RAM) available to JMeter and the network between
JMeter and the web server being tested. The size of the load that JMeter can generate
without skewing the results can be increased by running the tests in the non-graphical
mode or by distributing the load generation to multiple JMeter servers.
Install JMeter
Because we are using Apache JMeter as a desktop application, and there are a large
variety of desktop OSes in use, we will not cover the installation steps of JMeter for any
specific OS. With that being said, JMeter is very easy to install. The easiest ways to
install are to use a package manager (e.g. apt-get or Homebrew), or download and
unarchive the JMeter binaries from the official site and install Java (version 6 or later).
Here is a list of the software, with links to archives, required to run JMeter:
Apache JMeter
Depending on how you install Java, you may need to add the Java bin directory to
your PATHenvironmental variable, so JMeter can find the Java and keytool binaries.
Also, we will refer to the path that you installed JMeter to (the directory that you
unarchived it to) as$JMETER_HOME. Therefore, if you are on a Linux or Unix-based OS,
the JMeter binary is located at$JMETER_HOME/bin/jmeter. If you are running
Windows, you can run $JMETER_HOME/bin/jmeter.bat.
For reference, when writing this tutorial, we used the following software versions:
JMeter 2.11
Once you have JMeter installed and running, let's move on to building a test plan!
After starting JMeter, you should see the graphical user interface with an empty Test
Plan:
A test plan is composed of a sequence of test components that determine how the load
test will be simulated. We will explain the how some of these components can be used
as we add them into our test plan.
2.
3.
4.
Number of Threads (users): The number of users that JMeter will attempt to
simulate. Set this to 50
Ramp-Up Period (in seconds): The duration of time that JMeter will distribute
the start of the threads over. Set this to 10.
Loop Count: The number of times to execute the test. Leave this set to 1.
2.
3.
4.
2.
3.
4.
2.
3.
4.
2.
3.
4.
Now that we have our basic test plan set up, let's run it and see the results.
First, save the test plan by clicking on File then Save, then specify your desired file
name. Then select onView Results in Table in the left pane, then click Run from the
main menu then click Start (or just click the green Start arrow below the main menu).
You should see the test results in the table as the test is run like:
Latency: The number of milliseconds that elapsed between when JMeter sent
the request and when an initial response was received
Sample Time: The number of milliseconds that the server took to fully serve the
request (response + latency)
According to the table that was generated, the range of Sample Time was 128-164 ms.
This is a reasonable response time for a basic homepage (which was about 55 KB). If
your web application server is not struggling for resources, as demonstrated in the
example, your Sample Time will be influenced primarily by geographical distance (which
generally increases latency) and the size of the requested item (which increases
transfer time). Your personal results will vary from the example.
So, our server survived our simulation of 50 users accessing our 55 KB WordPress
homepage over 10 seconds (5 every second), with an acceptable response. Let's see
what happens when we increase the number of threads.
As you can see, the sample time has increased to nearly a second, which indicates that
our web application server is beginning to become overburdened by requests. Let's log
in to our VPS and see take a quick look at resource usage during the load test.
Log in to your web server via SSH and run top:
top
Unless you have users actively hitting your server, you should see that the Cpu(s) %
user usage (us) should be very low or 0%, and the Cpu(s) % idle (id) should be 99%+,
like so:
Now, in JMeter, start the test again, then switch back to your web server's SSH session.
You should see the resource usage increase:
In the case of our example, the CPU % user usage is 94% and the system usage (sy) is
4.7% with 0% idle. We aren't running out of memory, as indicated in the image above,
so the decreased performance is due to lack of CPU power! We can also see that the
php5-fpm processes, which are serving WordPress, are using is using the majority of
the CPU (about 96% combined).
In order to meet the demands of this simulation of 80 users in 10 seconds, we need to
either increase our CPU or optimize our server setup to use less CPU. In the case of
WordPress, we could move the MySQL database (which uses portion of the CPU) to
another server and we could also implement caching (which would decrease CPU
usage).
If you are curious, you may adjust the number of threads in the test to see how many
your server can handle before it begins to exhibit performance degradation. In the case
of our 1 CPU droplet example, it works fine until we use 72 threads over 10 seconds.
Conclusion
JMeter can be a very valuable tool for determining how your web application server
setup should be improved, to reduce bottlenecks and increase performance. Now that
you are familiar with the basic usage of JMeter, feel free to create new test plans to
measure the performance of your servers in various scenarios.
The test that we used as the example does not accurately reflect a normal user's usage
pattern, but JMeter has the tools to perform a variety of tests that may be useful in your
own environment. For example, JMeter can be configured to simulate a user logging
into your application, client-side caching, and handling user sessions with URL rewriting.
There are many other built-in samplers, listeners, and configuration tools that can help
you build your desired scenario. Additionally, there are JMeter plugins to enhance its
functionality that are available for download at http://jmeter-plugins.org/.
Tagged In: Server Optimization, Miscellaneous, Scaling
Written By:
Mitchell Anicas
Do you find this post helpful?
Show the author by Hearting it!
Tutorial Series
Load Testing with Apache JMeter
Load testing your web application servers can be an important step in
preparing your environment for production. Apache JMeter can be used to
simulate the load of many users connecting to your servers, which can be
useful in identifying your capacity limits and potential bottlenecks in your
setup. This series will show you how to use JMeter to record test scenarios,
and to perform load testing on your web servers.
////////////////////////////////
Jmeter-Check Gmail
Leave a reply
You can also configure Jmeter to read your gmail inbox or any other folder.But for that first
you need to make some configuration changes in your gmail setting . You Need to enable
pop3/imap email accounts for your gmail.
Lets see in action how to enable pop3/imap in gmail.
You can either enable POP or IMAP based on your requirements.When you enable POP3 below is
the configuration details you need to put in the jmeter sampler.
Protocol:-pop3
Server name:-pop.gmail.com
Port:-995
When you will use IMAP protocol below is the configuration details
Protocol:-imaps
Server name:-imap.gmail.com
Port:-993
(Note:-above configurations are the default values,in case you have some custom
configurations then the values may vary).
In both the cases
username:-yourname@gmail.com
password:-password
//////////////////////////////////////////
In the last article, we discussed about hands on with Apache JMeter. Now
most of the testers might be thinking about whats next after installation,
understanding the tool and how about recording a test script using JMeter.
In todays article we will see how to record your first JMeter Test
script using JMeter HTTP Proxy Server, How to do Firefox browser
settings for recording JMeter first test plan, How to do JMeter load testing tool
settings for recording your first test plan.
The HTTP(S) Proxy Server allows JMeter to intercept and record your
actions while you browse your web application with your normal browser.
JMeter will create test sample objects and store them directly into your test
plan.
First we have to setup proxy server in Firefox browser to checkout the First
Test plan recording steps. Follow simple steps:
Click on Tools > Options > Advanced tab > Network Tab > Setting button.
Enter Port: 8080 (Make sure that JMeter proxy server port number and local
proxy server port number are same )
You can check following image to get exact steps for how to setup proxy
server.
Once the above setting is done open JMeter tool to set up recording for your
first Test Plan.
1) To learn how to start JMeter you can check this post. Now open the JMeter
by clicking onJMeter.bat file.
2) Right click on Test Plan and choose Add > Threads (Users) > Thread
Group.
The new Thread Group element will be added under Test Plan. Read about
Thread Grouphere.
3) Right click on Thread Group and choose Logic Controller > Simple
Controller. The new Simple Controller option will get added under Thread
Group element.
4) Right click on Workbench and choose Add > Non-Test Elements > HTTP
Proxy Server.
The new HTTP Proxy Server option will get added under Workbench element.
This option will add JMeter proxy server in your JMeter test plan.
Under Global Setting section Set Port: 8080 (Same port value which is
configured in the above steps while configuring setting FireFox browser)
Under Test Plan Content section Choose Target Controller: Thread Group >
Simple Controller.
Once you complete your settings then JMeter HTTP Proxy Server will look like
as below:
Now you are ready to start Recording using HTTP Proxy Server in
JMeter & record your first JMeter test plan script in Apache JMeter. Click on
Start button & open the URL in FireFox browser for which you want to run
your performance testing script. Perform required navigation in FireFox
browser & all steps will be recorded in Apache JMeter. (Note: Dont do
unnecessary navigation while recording, if you did that then please remove
recorded script & start again from scratch.)
The recorded script will be displayed under Thread group > Simple Controller
option same as displayed in below image. You should also explore the
recorded script for your understanding how JMeter recording works using
proxy server.
If you enjoy reading article then you can subscribe our updates for FREE, just
add your email id . I will keep on updating the article for latest testing
information. Subscribe and stay tuned for updates, theres lot more to come.
/////////////////////////
What is JMeter
JMeter is an open source tool design by Apache to test the
applications Performance and Robustness.
JMeter can be used for web application testing and various
server testing like Database using
JDBC, Mail, JMS, LDAP etc.
JMeter Window
You can rename the test plan name and set to your choice. Also we
can add user defined variables to out test plan for further use.
Starting with simple Login API Test
I have started with simple API that is Login API where we need to
provide user name and password in request body.
Thread Group
So First we need to add Thread Group to our test plan. Thread group
means basically number of users we want to test with.
To add thread group right click on test plan go to Add > Threads
(Users) > Thread Group, shown in below screenshot.
Here you can name your thread group, Number of threads means no.
of concurrent users. Secondly ramp-up period is the time interval in
seconds to start the next thread after first thread (simply time intervals
in threads), and finally loop count is the number of times this group
thread will execute.
Http Request Sampler
Now we need to add Http Request to out thread group. For that right
click on Thread Group go to Add > Sampler > Http Request
Show in Below Screen shot.
Here also you can name to your request, I have given Login API,
then we have to provide our web server details. Server name Or IP of
our server for my example it is localhost and server port no.
In Http Request Section you can specify protocol by default it is http if
you want to use https then write there. Select your request type Post,
Get, Put, etc. Then provide you API path for my example it is
/jmetertest/api/login.do. If you want to add parameters for API then
add it to Parameter section and if your API has post body write in
Post Body section. Now you are done with your Http request.
Request Headers
If your API need Headers then we can configure those headers in
JMeter for that we need to add config element Http Header Manager.
To add Http Header Manager config element to our Thread group,
right click on thread group go to Add > Config Element > Http
Header Manager. As shown in below screen shot.
To add new header click on Add and provide header name and value.
These headers will be added to your all http request during execution
of threads.
CSV Config Element
In APIs we need to give inputs, there is a way in JMeter to provide
inputs from csv file. You can create csv file of your inputs and provide
this file to JMeter. JMeter will read your csv file line by line and provide
this data to your http request. So how to provide inputs from csv file,
its pretty simple. Create your csv file, I have created logindetails.csv
file (Attached below). Now right click on thread group and go to Add
> Config Element > CSV data set Config, as shown below
So first name your csv config data set, then provide file name or path,
but it is recommended that you place your csv file in directory where
your jmx file is present. Encoding of file, and the most important are
your variables. Name the variables in sequence as they are in csv
files. I have taken only two variables username and password and my
csv file data is also in same sequence.
If you want to use more than 1 csv data set config element in your
thread group then it is possible but you need to make sure that the
variable names should not repeat in your thread group.
Now to access the variable in your Http Request, you can simply
access these variable using syntax: ${Variable_Name}.
Have a look how I have modified my post body in http request sampler
to access input from csv file.
Have a look at View Result In Tree Window. In left side of window you
will see the APIs executed if they are in green color then API executed
successfully and if they are in red color then API execution had some
problem, you can see the reason in the right frame of window.
In Sampler result tab you can see all the details of http response by
server. In Request tab you can see http url hit and data posted with
the request, and in response tab you can see the response data of
request. All these are shown in below screen shots.
a. Sampler Tab
b. Request tab
c. Response Tab
You can see your result in graph result listener, sample screen shot
shown below
You can download sample jmx file and csv file of my loginApi from
hereSample_Example.