{"id":18677,"date":"2023-05-01T09:48:29","date_gmt":"2023-05-01T09:48:29","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=18677"},"modified":"2023-10-12T10:14:19","modified_gmt":"2023-10-12T10:14:19","slug":"how-to-setup-apache-jmeter-to-perform-a-stress-test-on-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-setup-apache-jmeter-to-perform-a-stress-test-on-linux\/","title":{"rendered":"How to Setup Apache JMeter to Perform a Stress Test on Linux Server"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-1024x768.jpg\" alt=\"How to Setup Apache JMeter to Stress Test a Web Server\" width=\"1024\" height=\"768\" class=\"alignnone size-large wp-image-18686 lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-1024x768.jpg 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-300x225.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-128x96.jpg 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-420x315.jpg 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-540x405.jpg 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-720x540.jpg 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-960x720.jpg 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-1140x855.jpg 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server-1320x990.jpg 1320w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/05\/How-to-Setup-Apache-JMeter-to-Stress-Test-a-Web-Server.jpg 1400w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/768;\" \/><\/p>\n<p>Apache JMeter is a powerful open-source tool designed for load testing web applications and other services. By simulating multiple users sending requests to a <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-are-web-servers-and-why-are-they-needed\/\">web server<\/a>, JMeter helps administrators and developers understand how their server reacts under heavy load.<\/p>\n<p>This is crucial for ensuring that your server can handle real-world traffic and provide a smooth user experience.<\/p>\n<p>In this tutorial, we will guide you through the process of setting up JMeter on Linux distributions, specifically <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-ubuntu-beginners-guide-ubuntu-linux-distro\/\">Ubuntu<\/a> and <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-centos-beginners-guide-centos-linux-distro\/\">CentOS<\/a>, and then using it to perform a stress test.<\/p>\n<p>Let&#8217;s get started.<\/p>\n<h2>Step 1. Installing Java<\/h2>\n<p>Before installing JMeter, ensure that Java is installed on your system, as JMeter requires it to run.<\/p>\n<h3>Ubuntu:<\/h3>\n<pre>\r\nsudo apt update\r\nsudo apt install openjdk-11-jdk\r\n<\/pre>\n<h3>CentOS:<\/h3>\n<pre>\r\nsudo yum update\r\nsudo yum install java-11-openjdk\r\n<\/pre>\n<h2>Step 2. Downloading and Installing JMeter<\/h2>\n<h3>Ubuntu:<\/h3>\n<pre>\r\nwget https:\/\/archive.apache.org\/dist\/jmeter\/binaries\/apache-jmeter-5.4.1.tgz\r\ntar -xvzf apache-jmeter-5.4.1.tgz\r\n<\/pre>\n<h3>CentOS:<\/h3>\n<pre>\r\nwget https:\/\/archive.apache.org\/dist\/jmeter\/binaries\/apache-jmeter-5.4.1.tgz\r\ntar -xvzf apache-jmeter-5.4.1.tgz\r\n<\/pre>\n<p>Download latest release: <a href=\"https:\/\/jmeter.apache.org\/download_jmeter.cgi\" rel=\"noopener\" target=\"_blank\">https:\/\/jmeter.apache.org\/download_jmeter.cgi<\/a><\/p>\n<h2>Step 3. Launching JMeter<\/h2>\n<p>Navigate to the JMeter bin directory and start JMeter:<\/p>\n<pre>\r\ncd apache-jmeter-5.4.1\/bin\r\n.\/jmeter\r\n<\/pre>\n<h2>Step 4. Setting Up a Test Plan<\/h2>\n<p>A test plan in JMeter describes a series of steps JMeter will execute when run. It&#8217;s the foundational element of any JMeter test. Here&#8217;s a more detailed breakdown:<\/p>\n<ol>\n<li><strong>Open JMeter<\/strong>: Launch the JMeter application. You&#8217;ll be greeted with a GUI that has a tree structure on the left side. This tree will house all the elements of your test.<\/li>\n<li><strong>Creating a New Test Plan<\/strong>: By default, a new test plan is already created. Right-click on the &#8220;Test Plan&#8221; node.<\/li>\n<li><strong>Add a Thread Group<\/strong>: The Thread Group is the beginning point of your test plan. It simulates user requests to the server:\n<ul>\n<li>Right-click on the Test Plan.<\/li>\n<li>Navigate to Add &gt; Threads (Users) &gt; Thread Group.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Configuring the Thread Group<\/strong>:\n<ul>\n<li><strong>Number of Threads (Users)<\/strong>: This represents the number of users you want to simulate. For instance, setting it to 100 means 100 virtual users will be sending requests to your server.<\/li>\n<li><strong>Loop Count<\/strong>: Determines how many times the test will be executed. Setting it to 10 with 100 users means 1000 requests will be sent.<\/li>\n<li><strong>Ramp-Up Period<\/strong>: The time (in seconds) taken to get all the threads started. If you have 100 users and a ramp-up period of 100 seconds, JMeter will take 100 seconds to get all 100 threads up and running.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Adding an HTTP Request<\/strong>:\n<ul>\n<li>Right-click on the Thread Group.<\/li>\n<li>Navigate to Add &gt; Sampler &gt; HTTP Request.<\/li>\n<li>In the HTTP Request form:\n<ul>\n<li><strong>Server Name or IP<\/strong>: Enter the domain name or IP address of your server.<\/li>\n<li><strong>Port Number<\/strong>: Typically, for HTTP it&#8217;s 80 and for HTTPS it&#8217;s 443, but it could be different based on your setup.<\/li>\n<li><strong>Path<\/strong>: The endpoint of your application you want to test, like &#8220;\/home&#8221; or &#8220;\/login&#8221;.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2>Step 5. Adding Listeners<\/h2>\n<p>Listeners are JMeter&#8217;s way of providing visual feedback. They capture the data from test execution and represent that data in various ways:<\/p>\n<ol>\n<li><strong>Adding a Listener<\/strong>:\n<ul>\n<li>Right-click on the Thread Group.<\/li>\n<li>Navigate to Add &gt; Listener.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Popular Listeners<\/strong>:\n<ul>\n<li><strong>View Results in Table<\/strong>: This listener provides a tabular view of all the requests sent during the test. It displays the status, response time, and other vital metrics for each request.<\/li>\n<li><strong>Graph Results<\/strong>: It provides a visual representation of the test results. You can see how response times varied over the course of the test, giving insights into potential bottlenecks.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2>Step 6. Running the Test<\/h2>\n<p>After setting up the test plan and adding listeners, you&#8217;re ready to execute the test:<\/p>\n<ol>\n<li><strong>Starting the Test<\/strong>: At the top of the JMeter GUI, you&#8217;ll see a green &#8220;Run&#8221; button (it looks like a play button). Click on it to start the test.<\/li>\n<li><strong>Monitoring the Test<\/strong>: As the test runs, the listeners you added will begin populating with data. You can monitor these in real-time:\n<ul>\n<li>For the &#8220;View Results in Table&#8221; listener, you&#8217;ll see each request being logged.<\/li>\n<li>The &#8220;Graph Results&#8221; listener will plot response times as the test progresses.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Stopping the Test<\/strong>: If you need to halt the test for any reason, click the red &#8220;Stop&#8221; button (it looks like a stop sign) at the top of the GUI.<\/li>\n<\/ol>\n<p>Remember, while JMeter provides valuable insights through its GUI, for more extensive tests, it&#8217;s recommended to run JMeter in non-GUI mode to conserve resources.<\/p>\n<h2>Running JMeter in Non-GUI Mode<\/h2>\n<p>Running JMeter in non-GUI mode is essential when conducting large-scale performance tests. The GUI consumes significant resources, which can skew test results. Non-GUI mode allows JMeter to use all available resources for the test itself, ensuring more accurate results. Here&#8217;s a step-by-step guide:<\/p>\n<h3>1. Creating Your Test Plan in GUI Mode<\/h3>\n<p>Before you can run a test in non-GUI mode, you need to create and save it:<\/p>\n<ol>\n<li>Launch JMeter in GUI mode.<\/li>\n<li>Set up your test plan as required.<\/li>\n<li>Save the test plan by navigating to <code>File &gt; Save Test Plan as<\/code>. Save it with a <code>.jmx<\/code> extension, for example, <code>my_test_plan.jmx<\/code>.<\/li>\n<\/ol>\n<h3>2. Running the Test in Non-GUI Mode<\/h3>\n<ol>\n<li><strong>Open Terminal or Command Prompt<\/strong>: Navigate to the directory where JMeter is installed.<\/li>\n<li><strong>Execute the Test<\/strong>: Use the following command structure to run your test:<\/li>\n<\/ol>\n<pre>\r\n.\/jmeter -n -t [path-to-test-plan] -l [path-to-result-file]\r\n<\/pre>\n<p>For example:<\/p>\n<pre>\r\n.\/jmeter -n -t \/path\/to\/your\/testplan\/my_test_plan.jmx -l \/path\/to\/results\/results.jtl\r\n<\/pre>\n<p>Here&#8217;s a breakdown of the command:<\/p>\n<ul>\n<li><code>-n<\/code>: This flag indicates you are running JMeter in non-GUI mode.<\/li>\n<li><code>-t<\/code>: Specifies the path to your JMeter test plan.<\/li>\n<li><code>-l<\/code>: Specifies the path where the results will be saved.<\/li>\n<\/ul>\n<h3>3. Monitoring the Test<\/h3>\n<p>While you won&#8217;t have the JMeter GUI to monitor in real-time, you can still keep an eye on server metrics using tools like <code>htop<\/code> (for CPU and memory usage) or <code>nmon<\/code> (for a more comprehensive view including network and disk I\/O).<\/p>\n<h3>4. Analyzing the Results<\/h3>\n<p>After the test completes, JMeter will save the results to the specified <code>.jtl<\/code> file. You can then:<\/p>\n<ol>\n<li><strong>Open the Results in JMeter GUI<\/strong>: Launch JMeter in GUI mode, add a listener like &#8220;View Results in Table&#8221; or &#8220;Summary Report&#8221;, and then load the <code>.jtl<\/code> file to view and analyze the results.<\/li>\n<li><strong>Use Third-party Tools<\/strong>: There are tools and platforms, like Grafana combined with InfluxDB, that can visualize JMeter results for deeper analysis.<\/li>\n<\/ol>\n<h3>5. Additional Tips<\/h3>\n<ul>\n<li><strong>Log File<\/strong>: By default, JMeter logs messages in the <code>jmeter.log<\/code> file. It&#8217;s a good practice to check this file for any warnings or errors after your test.<\/li>\n<li><strong>Adjust Heap Size<\/strong>: For large tests, you might need to increase the Java heap size to prevent memory issues. This can be done by editing the <code>jmeter<\/code> startup script.<\/li>\n<li><strong>Use Plugins<\/strong>: Even in non-GUI mode, JMeter plugins can enhance your testing. For instance, the <code>Concurrency Thread Group<\/code> and <code>Stepping Thread Group<\/code> can offer more advanced ramp-up patterns.<\/li>\n<\/ul>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">sudo apt update<\/span> \u2013 Updates the package list for upgrades on Ubuntu.<\/li>\n<li><span class=\"fw-bold\">sudo yum update<\/span> \u2013 Updates the package list for upgrades on CentOS.<\/li>\n<li><span class=\"fw-bold\">wget [URL]<\/span> \u2013 Downloads files from the internet.<\/li>\n<li><span class=\"fw-bold\">tar -xvzf [FILENAME]<\/span> \u2013 Extracts a tarball file.<\/li>\n<\/ul>\n<h2>Additional Tips<\/h2>\n<ul>\n<li><span class=\"fw-bold\">Regularly Update JMeter<\/span>: Ensure that you are using the latest version of JMeter to benefit from the latest features and security patches.<\/li>\n<li><span class=\"fw-bold\">Use Plugins<\/span>: JMeter has a rich ecosystem of plugins that can enhance its capabilities. Consider exploring the JMeter Plugin Manager to find tools that can aid your testing process.<\/li>\n<li><span class=\"fw-bold\">Monitor Server Health<\/span>: While running stress tests, it&#8217;s also beneficial to monitor the health of your server using tools like htop (an interactive process viewer for Unix systems) or nmon (A system monitor tool for Linux, which shows usage for CPU, memory, network, disks, and more.). This gives you a holistic view of how the server is handling the load.<\/li>\n<li><span class=\"fw-bold\">Distributed Testing<\/span>: For extremely high loads, consider using JMeter&#8217;s distributed testing feature. This allows you to run tests from multiple machines, simulating an even larger number of users.<\/li>\n<li><span class=\"fw-bold\">Documentation<\/span>: The official JMeter documentation is a valuable resource. It provides in-depth information on every feature and can help troubleshoot any issues you might encounter.<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is Apache JMeter used for?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Apache JMeter is an open-source tool designed for load testing web applications and other services. It simulates multiple users sending requests to a server, helping to understand the server&#8217;s performance under heavy load.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why is Java required for JMeter?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">JMeter is a Java-based application, and thus, it requires Java to run. The Java Runtime Environment (JRE) provides the libraries and components needed for JMeter to function properly.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How do I view the results of my JMeter test?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">In JMeter, you can view test results using listeners. Popular listeners include &#8220;View Results in Table&#8221;, &#8220;Graph Results&#8221;, and &#8220;Summary Report&#8221;. These listeners provide detailed insights into the test&#8217;s performance metrics.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Can JMeter be used for testing non-web applications?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Yes, while JMeter is popularly used for web application testing, it can also test various other services like FTP, LDAP, and databases. It&#8217;s a versatile tool suitable for various testing scenarios.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Is JMeter suitable for large-scale load testing?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Yes, JMeter can handle large-scale load testing. However, for very high loads, it&#8217;s recommended to distribute the testing across multiple machines using JMeter&#8217;s distributed testing capabilities.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How can I extend JMeter&#8217;s capabilities?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">JMeter&#8217;s capabilities can be extended using plugins. The JMeter Plugin Manager offers a variety of plugins that can introduce new samplers, listeners, and other functionalities to enhance your testing process.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What are the alternatives to JMeter for load testing?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">While JMeter is a popular choice, there are other load testing tools like LoadRunner, Gatling, and Locust that are also widely used in the industry. Each tool has its strengths and is suited for different scenarios and requirements.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>Understanding how your server reacts under heavy load is crucial for ensuring optimal performance and a seamless user experience. Apache JMeter provides a comprehensive solution for simulating real-world traffic and stress-testing your server.<\/p>\n<p>Running JMeter in non-GUI mode is crucial for large-scale and resource-intensive tests. It ensures that the tool uses all available resources for the test, providing more accurate and reliable results. By following the steps above, you can efficiently execute and analyze your performance tests without the overhead of the GUI.<\/p>\n<p>By following this tutorial, you&#8217;ve learned how to set up JMeter on Linux distributions, specifically Ubuntu and CentOS, and use it effectively.<\/p>\n<p>For a deeper dive into web servers, you can explore the <a href=\"https:\/\/webhostinggeeks.com\/best\/web-server\/\">best web server software<\/a> or learn more about individual servers like <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>.<\/p>\n<p>For further insights into hosting solutions, explore <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a> options.<\/p>\n<p>Welcome to the comments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apache JMeter is a powerful open-source tool designed for load testing web applications and other services. By simulating multiple users sending requests to a web server, JMeter helps administrators and&#8230;<\/p>\n","protected":false},"author":6,"featured_media":18686,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2152],"tags":[1199,2165,2153],"class_list":["post-18677","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-benchmarking","tag-apache","tag-jmeter","tag-test"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/18677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=18677"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/18677\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/18686"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=18677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=18677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=18677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}