jmeter.docx

35
How To Use Apache JMeter To Perform Load Testing on a Web Server This tutorial is part 1 of 2 in the series: Load Testing with Apache JMeter 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.

Upload: poojanew

Post on 14-Nov-2015

10 views

Category:

Documents


1 download

TRANSCRIPT

How To Use Apache JMeter To Perform Load Testing on a Web ServerThis tutorial is part 1 of 2 in the series:Load Testing with Apache JMeterIntroductionIn 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.PrerequisitesIn 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 JMeterBecause 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,requiredto run JMeter: Oracle JavaorOpenJDK(6 or later) Apache JMeterDepending on how you install Java, you may need to add the Java bin directory to yourPATHenvironmental 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: Oracle Java 7 update 60, 64-bit JMeter 2.11Once you have JMeter installed and running, let's move on to building a test plan!Building a Basic Test PlanAfter starting JMeter, you should see the graphical user interface with an emptyTest 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.Add a Thread GroupFirst, add aThread GrouptoTest Plan:1. Right-click onTest Plan2. Mouse overAdd >3. Mouse overThreads (Users) >4. Click onThread GroupTheThread Grouphas three particularly important properties influence the load test: Number of Threads (users): The number of users that JMeter will attempt to simulate. Set this to50 Ramp-Up Period (in seconds): The duration of time that JMeter will distribute the start of the threads over. Set this to10. Loop Count: The number of times to execute the test. Leave this set to1.

Add an HTTP Request DefaultsTheHTTP Request DefaultsConfig Element is used to set default values for HTTP Requests in our test plan. This is particularly useful if we want to send multiple HTTP requests to the same server as part of our test. Now let's addHTTP Request DefaultstoThread Group:1. SelectThread Group, then Right-click it2. Mouse overAdd >3. Mouse overConfig Element >4. Click onHTTP Request DefaultsIn HTTP Request Defaults, under the Web Server section, fill in theServer Name or IPfield with the name or IP address of the web server you want to test. Setting the server here makes it the default server for the rest of the items in this thread group.

Add an HTTP Cookie ManagerIf your web server uses cookies, you can add support for cookies by adding an HTTP Cookie Manager to the Thread Group:1. SelectThread Group, then Right-click it2. Mouse overAdd >3. Mouse overConfig Element >4. Click onHTTP Cookie ManagerAdd an HTTP Request SamplerNow you will want to add anHTTP Requestsampler toThread Group, which represents a page request that each thread (user) will access:1. SelectThread Group, then Right-click it2. Mouse overAdd >3. Mouse overSampler >4. Click onHTTP RequestIn HTTP Request, under the HTTP Request section, fill in thePathwith the item that you want each thread (user) to request. We will set this to/, so each thread will access the homepage of our server. Note that you do not need to specify the server in this item because it was already specified in the HTTP Request Defaults item.Note:If you want to add more HTTP Requests as part of your test, repeat this step. Every thread will perform all of the requests in this test plan.Add a View Results in Table ListenerIn JMeter, listeners are used to output the results of a load test. There are a variety of listeners available, and the other listeners can be added by installing plugins. We will use the Table because it is easy to read.1. SelectThread Group, then Right-click it2. Mouse overAdd >3. Mouse overListener >4. Click onView Results in TableYou may also type in a value forFilenameto output the results to a CSV file.Run the Basic Test PlanNow that we have our basic test plan set up, let's run it and see the results.First, save the test plan by clicking onFilethenSave, then specify your desired file name. Then select onView Results in Tablein the left pane, then clickRunfrom the main menu then clickStart(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:

Interpreting the ResultsYou will probably see that the Status of all the requests is "Success" (indicated by a green triangle with a checkmark in it). After that, the columns that you are probably most interest in are theSample Time (ms)andLatency(not displayed in example) columns. 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.Increasing the LoadLet's try the same test with 80 threads over 10 seconds. In theThread Groupitem in the left-pane, change theNumber of Threads (users)to80. Now clickView Results in Table, then clickStart. On our example server, this results in the following table:

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 runtop:topUnless 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, inJMeter, 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.ConclusionJMeter 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 athttp://jmeter-plugins.org/.Tagged In:Server Optimization,Miscellaneous,Scaling

Written By:Mitchell AnicasDo you find this post helpful?Show the author by Hearting it!Tutorial SeriesLoad Testing with Apache JMeterLoad 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 GmailLeave a replyYou 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:-pop3Server name:-pop.gmail.comPort:-995When you will use IMAP protocol below is the configuration detailsProtocol:-imapsServer name:-imap.gmail.comPort:-993(Note:-above configurations are the default values,in case you have some custom configurations then the values may vary).In both the casesusername:[email protected]:-passwordNow open your Jmeter and create a Thread Group .Add a Mail Reader Sampler to the Thread Group. Put all the configuration details accordingly.Save and execute.

//////////////////////////////////////////

RECORDING TRAFFIC USING APACHE JMETER HTTP PROXYSERVERPosted onJune 30, 2014byGopikrishna AnandiIn the lastarticle, 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 recordingatest script using JMeter.In todays article we will see how to record your first JMeter Test scriptusingJMeter 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.Recording using Apache JMeterHTTP(s) Proxy Server

TheHTTP(S) Proxy Serverallows 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: Open Firefox Browser Click on Tools > Options > Advanced tab > Network Tab > Setting button. Choose Manual proxy configuration radio button. Enter HTTP Proxy: localhost 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 thispost. Now open the JMeter by clicking onJMeter.batfile.2) Right click on Test Plan and choose Add > Threads (Users) > Thread Group. The new Thread Group elementwill beadded 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.

5) Before start recording we have to do simple configuration setting in the HTTP Proxy Server option Click on HTTP Proxy Server option 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 startRecording using HTTP Proxy Server in JMeter& recordyour 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 usingJDBC, Mail, JMS, LDAP etc. It is developed in Java by Stefano Mazzocchi, initially developed to test Apache JServer (now Known as Apache Tomcat Server). JMeter is developed in such a way that we can write our own plugins to extend the capabilities of JMeter.Why performance testing is necessary for application To identify the maximum operating capacity of a system. To identify any bottleneck which may occur in system operation and not in development. To determine the speed or performance of application or system on heavy load. To test robustness, availability and reliability under extreme condition.Requirement JVM 1.5 or laterJMeterYou can download latest JMeter fromhttp://jmeter.apache.org/download_jmeter.cgiExtract the zip and start the jmeter, it will look like thisJMeter WindowYou 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 TestI have started with simple API that is Login API where we need to provide user name and password in request body.Thread GroupSo 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.Add thread group in your test planThread Group window will look like thisThread Group WindowHere 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 SamplerNow we need to add Http Request to out thread group. For that right click on Thread Group go to Add > Sampler > Http RequestShow in Below Screen shot.How to add http request sampler to thread groupHttp request sampler window will look like thisHttp Request Sampler WindowHere 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 HeadersIf 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.Add Http Header Manager in your thread groupThe Http Header Manager window will look like thisHttp Header Manager WindowTo 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 ElementIn 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 belowAdd CSV File Config ElementCsv data set config window will look like thisCSV Config File Element WindowSo 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.Http Request post body using csv file inputI have replaced the values of username and password with ${USERNAME} and ${PASSWORD}.ListenersListeners are the elements where you actually see the results of your test. There are various listeners available with JMeter. But for API we actually need View Result Tree Listener, Graph Result, Aggregate Graph, Aggregate Result. To add listener right click on thread group go to Add > Listener1. View Result Tree ListenerIf you are interested to see the input provided and output of each request sent to server then View Result In Tree Listener is best.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 TabView Result Tree Listener Sampler Tabb. Request tabView Result Tree Listener Request Tabc. Response TabView Result Tree Listener Response Tab2. Graph Result ListenerYou can see your result in graph result listener, sample screen shot shown belowGraph Result Listener3. Aggregate Result ListenerThis listener will show you the results in table format where you can see various parameters of the result. First is samples means number of request execute on server, second is Average that is average time of request executed for all samples, then median is average time in middle of a set of result, then min is shortest time of this sample to execute and max is maximun time taken by any sample to execute, then error % is percentage of errors, throughput is requests per second and KB/sec is throughput measured in kilobytes per sec.Sample Aggregate reportAggregate Result ListenerYou can download sample jmx file and csv file of my loginApi from hereSample_Example.