{"id":744,"date":"2016-04-13T11:29:06","date_gmt":"2016-04-13T11:29:06","guid":{"rendered":"https:\/\/loadfocus.com\/blog\/?p=744"},"modified":"2023-09-03T14:10:13","modified_gmt":"2023-09-03T14:10:13","slug":"how-to-use-apache-jmeter-to-load-test-a-web-server","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/2016\/04\/how-to-use-apache-jmeter-to-load-test-a-web-server","title":{"rendered":"How To Use Apache JMeter To Load Test a Web Server"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 6<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span><h3>Overview<\/h3>\n<p class=\"lead\">We are going to present how to use Apache JMeter (open source load testing tool) in order to perform basic load and stress testing on your web application. We are going through each step and show how to use JMeter&#8217;s GUI (graphical user interface) in order to build a test plan, configure load tests, run test and inspect the results.<\/p>\n<p>Apache JMeter is an open source Java application, so it can run on any OS (operating system) which supports JAVA 6 or later. JMeter is a load testing (performance testing) tool designed to run tests on any given URI endpoint, with configurable number of concurrent clients (users) and other useful test configurable metrics and inspect results. Test results can be viewed in charts, tables or can be exported in CSV or XML formats.<\/p>\n<h3>Prerequisites<\/h3>\n<p>In order to start using JMeter you need a machine that you can install and run JMeter on. By default JMeter runs as a GUI application, which requires more resources than a command line based application. In order to perform the load tests faster and without bottlenecks you can run JMeter in the non-graphical mode (details on how to start JMeter in non-graphical mode in the next post)<br \/>\nPlease note that results can differ based on the web server where the web application is hosted. Factors that we need to take into account are:<\/p>\n<ul>\n<li>system resources CPU, RAM Memory of the web server<\/li>\n<li>system resources CPU, RAM Memory of the machine where JMeter is installed (from where the tests are executed)<\/li>\n<li>location of the web server between the load test injector and the web server where the application is hosted (which affects the latency of the tests &#8211; use a <a href=\"https:\/\/loadfocus.com\">cloud load testing tool<\/a> in order to easily run load tests from different locations)<\/li>\n<\/ul>\n<h3>Install JMeter<\/h3>\n<p>Apache JMeter is very easy to install. Depending on the OS, there are different ways on how to do this.<\/p>\n<p>In order to run JMeter, here is what you need to install:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/jdk7-downloads-1880260.html\">Oracle JAVA<\/a> or <a href=\"http:\/\/openjdk.java.net\/install\">OpenJDK<\/a> (6 or later)<\/li>\n<li><a href=\"http:\/\/jmeter.apache.org\/download_jmeter.cgi\">Apache JMeter<\/a> (2.11 or 2.13)<\/li>\n<\/ul>\n<p>Make sure that after installing JAVA you add it to the $PATH environment variable. <a href=\"https:\/\/web.archive.org\/web\/20201112013717\/https:\/\/www.java.com\/EN\/DOWNLOAD\/HELP\/PATH.XML\">Here<\/a> you can find how to add the JAVA to the $PATH environment variable for every OS .<br \/>\n           \r\n            <div class=\"onp-locker-call\" style=\"display: none;\" data-lock-id=\"onpLock380220\">\r\n                <p>\nTo start <strong>JMeter<\/strong> on Windows OS you need to go to the folder where you unarchived JMeter binaries and just run $JMETER_HOME\/bin\/jmeter.bat batch file. Please see here <a href=\"https:\/\/loadfocus.com\/blog\/2014\/06\/24\/run-apache-jmeter-on-mac\/\">how you can run JMeter on Mac<\/a>.<\/p>\n<p>So, once all is installed and JMeter is running you can start creating your first load test. For this demo we are going to use Apache JMeter 2.11 on Mac.<\/p>\n<h3>Build Test Plan<\/h3>\n<p>In order to create a load test, add a Thread Group, in order to configure the thread properties (load test configuration):<\/p>\n<img loading=\"lazy\" decoding=\"async\" width=\"669\" height=\"171\" class=\"aligncenter size-full wp-image-754\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-test-plan.png\" alt=\"apache jmeter test plan\" \/>\n<p>Start by adding a <em>Thread Group<\/em> to your <em>Test Plan<\/em> by following the below steps:<\/p>\n<ul>\n<li>Select\u00a0the<em> Test Plan<\/em> on the left side, and Right-click it<\/li>\n<li>Hover to <em>Add -&gt; Threads (Users) -&gt; Thread Group<\/em><\/li>\n<li>Click on<em> Thread Group<\/em><\/li>\n<\/ul>\n<img loading=\"lazy\" decoding=\"async\" width=\"755\" height=\"391\" class=\"aligncenter size-full wp-image-748\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-adding-thread-group.png\" alt=\"apache jmeter thread group\" \/>\n<p>Configure the following properties which will be used to run your load test:<\/p>\n<h3>See more details<\/h3>\n<p><script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- Horizontal --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-8151016364557535\" data-ad-slot=\"3116377147\" data-ad-format=\"auto\" data-full-width-responsive=\"true\"><\/ins><br \/>\n<script><br \/>\n                                 (adsbygoogle = window.adsbygoogle || []).push({});<br \/>\n                            <\/script><\/p>\n<ul>\n<li><strong>Number of threads (users)<\/strong>: The number of concurrent clients\/users JMeter is going to simulate. Set it to <strong>10<\/strong>.<\/li>\n<li><strong>Ramp-up Period<\/strong>: How long JMeter should take to get all the threads started. Set it to <strong>10<\/strong>.<\/li>\n<li><strong>Loop Count<\/strong>: Number of times to perform the test case. Set it also to <strong>10<\/strong>.<\/li>\n<\/ul>\n<img loading=\"lazy\" decoding=\"async\" width=\"263\" height=\"122\" class=\"aligncenter size-full wp-image-749\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-configre-thread-group.png\" alt=\"apache jmeter thread group configuration\" \/>\n<p>Now we add a <em>HTTP Request Sampler<\/em> which represents an individual request made by each thread.<br \/>\nTo do this Add a <em>HTTP Request Sampler<\/em> to your <em>Thread Group<\/em> by following the below steps:<\/p>\n<ul>\n<li>Select on the <em>Thread Group<\/em> on the left side, then Right-click it<\/li>\n<li>Hover (mouse over) to <em>Add -&gt; Sampler -&gt; HTTP Request<\/em><\/li>\n<li>Click on <em>HTTP Request<\/em><\/li>\n<\/ul>\n<img loading=\"lazy\" decoding=\"async\" width=\"1092\" height=\"657\" class=\"aligncenter size-full wp-image-746\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-adding-http-request-sampler.png\" alt=\"apache jmeter http sampler\" \/>\n<p>In the <em>HTTP Request Sampler<\/em>, under Web server, set the URL in the Server Name or IP field (website URL i.e www.example.com or public IP address).<\/p>\n<p>Check here <a href=\"https:\/\/loadfocus.com\/blog\/2021\/12\/how-to-use-csv-data-set-to-configure-jmeter-tests\/\">how to use a CSV Data Set in your JMeter test<\/a>.<\/p>\n<p>If you want to execute more than one <em>HTTP Request<\/em> by each thread (user), simply duplicate the <em>HTTP Request Sampler<\/em> and update the Server Name or IP. Here are the steps to duplicate the <em>HTTP Request Sampler<\/em>.<\/p>\n<ul>\n<li>Select HTTP Request Sampler, then Copy it (Cmd\/Control + C)<\/li>\n<li>Select Thread Group, then Paste it (<em>Cmd\/Control + V<\/em>)<\/li>\n<\/ul>\n<p>Note: In our JMeter test we will continue to use only one <em>HTTP Request Sampler.<\/em><\/p>\n<h3>Add HTTP Cookie Manager (optional)<\/h3>\n<p>If your web application uses Cookies, JMeter allows to add cookies which will be sent with each HTTP request. You can do that simply by adding the HTTP Cookie Manager by following these steps:<\/p>\n<ul>\n<li>Select <em>Thread Group<\/em>, then Right-click it<\/li>\n<li>Hover (mouse-over) <em>Add -&gt; Config Element -&gt; HTTP Cookie Manager<\/em><\/li>\n<\/ul>\n<h3>Add HTTP Header Manager (optional)<\/h3>\n<p>In case you need to send specific headers with every request, JMeter allows to add headers by adding the HTTP Header Manager by following these steps:<\/p>\n<ul>\n<li>Select <em>Thread Group<\/em>, then Right-click it<\/li>\n<li>Hover (mouse-over) <em>Add -&gt; Config Element -&gt; HTTP Header Manager<\/em><\/li>\n<\/ul>\n<h3>Add View Results in Table<\/h3>\n<p>You need to use JMeter&#8217;s Listeners in order to view the output of a load or stress test. One of the most used <em>Listeners<\/em> is the <em>View Results in Table<\/em>, which we&#8217;ll use in the post and here is how to add it to your <em>Test Plan<\/em>:<\/p>\n<ul>\n<li>Select <em>Thread Group<\/em>, then Right-click it<\/li>\n<li>Hover (mouse-over) <em>Add -&gt; Listener -&gt; View Results in Table<\/em><\/li>\n<\/ul>\n<img loading=\"lazy\" decoding=\"async\" width=\"1270\" height=\"785\" class=\"aligncenter size-full wp-image-747\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-adding-listener-view-results-in-table.png\" alt=\"apache jmeter results listener\" \/>\n<h2>Run your Test Plan<\/h2>\n<p>After installing everything needed in order to start Apache JMeter and after configuring the <em>Test Plan<\/em>, you can start running your test.<\/p>\n<p>First, save the test plan with the <em>.jmx<\/em> extension.<br \/>\nRun the test by pressing the green arrow button in the toolbar or by pressing <em>Cmd\/Control + R<\/em> keys.<\/p>\n<img loading=\"lazy\" decoding=\"async\" width=\"1011\" height=\"250\" class=\"aligncenter size-full wp-image-752\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-load-test-results.png\" alt=\"apache jmeter results in tree\" \/>\n<p>You&#8217;ll starting seeing results in the View Results in Table, important columns are <em>Sample Time (ms)<\/em>, <em>Status<\/em>, <em>Bytes<\/em> and <em>Latency<\/em>. To understand better the <a href=\"https:\/\/loadfocus.com\/blog\/2014\/07\/10\/errors-and-response-codes-in-load-testing-on-loadfocus-com\/\" class=\"broken_link\">errors and responses<\/a> you can check out this post.<\/p>\n<ul>\n<li><strong>Sample Time (ms)<\/strong>: Represents the number of milliseconds that the server took to serve the request (response + latency)<\/li>\n<li><strong>Latency (ms)<\/strong>: Represents the number of milliseconds that elapsed between when JMeter sent the request and when an initial response was received<\/li>\n<\/ul>\n<p>At the bottom of the <em>View Results in Table<\/em>, you can see the <em>Average Sample Time<\/em> in ms and the <em>Standard Deviation<\/em>.<br \/>\nAccording to the results, after running <strong>100 samples<\/strong> the <em>Average Sample Time<\/em> in milliseconds was <strong>133 ms<\/strong>. <em>Latency<\/em> is going to be affected by the geographic distance between the place from where the request is made to the place where the web server is hosted.<\/p>\n<img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"31\" class=\"aligncenter size-full wp-image-756\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-view-results-in-table-finish-100.png\" alt=\"apache jmeter 100 samples\" \/>\n<p>So, no error occurred on our test when running the <strong>10 requests X 10 threads (users) = 100 samples<\/strong>, and the <em>Sample Time<\/em> was low <strong>133 ms<\/strong>.<\/p>\n<h3>Increase the Load by changing the Threads (users) values<\/h3>\n<p>In order to make our load test more realistic, let&#8217;s change the Threads (Users) field to <strong>300<\/strong>.<br \/>\nClear the previous JMeter results by pressing <em>Cmd\/Control + E<\/em> or by clicking the Clear icon in JMeter&#8217;s toolbar.<\/p>\n<p>Start the test, and check the results again. As you can see, the Sample Time increased almost by <strong>50% to 178 ms<\/strong>, however no errors occurred while running our load test with JMeter.<\/p>\n<img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"33\" class=\"aligncenter size-full wp-image-757\" src=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/apache-jmeter-view-results-in-table-finish-3000.png\" alt=\"apache jmeter 3000 samples\" \/>\n<p>Also, while running the tests, server side monitoring will be helpful, looking at metrics like <em>CPU<\/em> or <em>Memory<\/em>. In Windows you can monitor these stats by opening the <em>PerfMon<\/em> tool or in Linux by typing the top command in terminal.<\/p>\n<p>You can extend the load test up to 1000 threads (users), to check how your system behaves and discover potential bottlenecks, memory leaks, performance issues. <a href=\"https:\/\/loadfocus.com\">LoadFocus.com<\/a> is a cloud load testing service and you can run load tests with thousands of threads (users).<\/p>\n<h2>Conclusion<\/h2>\n<p><strong>JMeter<\/strong> is a useful load testing tool, which helps you find load testing issues, discover bottlenecks and increate performance of your web application. Feel free to experiment different values for the load test in order to understand how your web server behaves under heavy load. In order to add more plugins to your default JMeter installation, you can check the <strong><a href=\"https:\/\/jmeter-plugins.org\/\">JMeter plugins<\/a><\/strong> add-ons or check here how to <a href=\"https:\/\/loadfocus.com\/blog\/tech\/2015\/07\/how-to-install-jmeterplugins-extras-and-jmeterplugins-extraslibs\/\">add JMeter plugins to JMeter<\/a>.<\/p>\n<p><\/p>\r\n            <\/div>\r\n         \r\n\r\n        <\/p>\n<p>In order to run load tests with thousands of threads (users) and to run load tests from different world locations, you can use <a href=\"https:\/\/loadfocus.com\">LoadFocus.com<\/a> which offers a cloud load testing service, easy to use, which keeps all your tests and test runs in the history automatically.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 6<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>Overview We are going to present how to use Apache JMeter (open source load testing tool) in order to perform basic load and stress testing on your web application. We are going through each step and show how to use JMeter&#8217;s GUI (graphical user interface) in order to build a test plan, configure load tests,&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/2016\/04\/how-to-use-apache-jmeter-to-load-test-a-web-server\" class=\"more-link\" title=\"Read How To Use Apache JMeter To Load Test a Web Server\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,9,6,125],"tags":[124,123],"class_list":["post-744","post","type-post","status-publish","format-standard","hentry","category-apache-jmeter","category-load-testing","category-performance-testing","category-stress-testing","tag-how-to-use-apache-jmeter","tag-jmeter-load-test"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/comments?post=744"}],"version-history":[{"count":2,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/744\/revisions"}],"predecessor-version":[{"id":2776,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/744\/revisions\/2776"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media?parent=744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/categories?post=744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/tags?post=744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}