{"id":35,"date":"2015-07-13T09:09:36","date_gmt":"2015-07-13T09:09:36","guid":{"rendered":"http:\/\/loadfocus.com\/blog\/tech\/?p=35"},"modified":"2023-04-10T20:00:59","modified_gmt":"2023-04-10T20:00:59","slug":"how-to-measure-cpu-and-memory-while-running-a-load-test","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/tech\/2015\/07\/how-to-measure-cpu-and-memory-while-running-a-load-test","title":{"rendered":"How to Measure CPU and Memory while Running a Load Test"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span><p class=\"lead\"><!-- pn-tldr --><\/p>\n<h2>Key takeaways<\/h2>\n<ul>\n<li>Response times alone cannot tell you whether the server is saturated or merely waiting.<\/li>\n<li>Watch the load generator too, since a saturated generator caps the test rather than the target.<\/li>\n<li>Correlate resource use with the load curve; the point where they diverge is the finding.<\/li>\n<\/ul>\n<p><!-- \/pn-tldr -->In order to make\u00a0sure that your application will not break under a heavy load, a web application owner has to perform some basic performance tests.<\/p>\n<p>Here are\u00a04 simple steps how to achieve this with LoadFocus <a href=\"https:\/\/loadfocus.com\">load testing tool<\/a>:<\/p>\n<ol>\n<li>Log into your account on the LoadFocus platform<\/li>\n<li>Click on the \u201cNew Load Test\u201d menu<\/li>\n<li>Enter the details of your web application (the endpoint\/URL that you want to access, the number of clients per second and the number of seconds that the test will run) \u2013 check image attached for an example<\/li>\n<li>Before starting the test log into your server and use the script that we provide for monitoring the CPU and memory as below (the script is developed for Linux servers):\n<ol>\n<li>copy the script cpu_mem_stats.sh to the server where your application is installed: <a href=\"https:\/\/loadfocus.com\/blog\/wp-content\/uploads\/cpu_mem_stats.sh\" target=\"_blank\" rel=\"noopener noreferrer\">click here to download script.<\/a><\/li>\n<li>run the following command:\n<pre class=\"lang-java\"><code class=\"lang-java\">\nchmod 777 cpu_mem_stats.sh\n<\/code><\/pre>\n<\/li>\n<li>run the following command:\n<pre class=\"lang-java\"><code class=\"lang-java\">\n.\/cpu_mem_stats.sh -p node -t 200 -f \/home\/ubuntu\/log.txt -c true\n<\/code><\/pre>\n<\/li>\n<li>the meaning of the parameters is (please modify according to your needs):<\/li>\n<\/ol>\n<ul>\n<li><i>-p &#8211; The process name to look for<\/i><\/li>\n<li><i>-t &#8211; The time to monitor specified in seconds<\/i><\/li>\n<li><i>-f &#8211; path to the file to write the output (if not specified the output will be logged into the console)<\/i><\/li>\n<li><i>-c &#8211; if specified as true will output in CSV format<\/i><\/li>\n<\/ul>\n<ol start=\"5\">\n<li>Start your load test from LoadFocus.com<\/li>\n<li>The result of the response times will give you a graph like this:<\/li>\n<li>After the test ends get the result from the stats test on your server (in our example log.txt)<\/li>\n<li>For creating the graphs from the result files we recommend the following online solution: https:\/\/plot.ly\/ . From that you will get a graph similar to:<\/li>\n<li>Now by using the graphs from LoadFocus and the results from the <em>cpu_mem_stats.sh<\/em> you can correlate how you server is behaving under load, which will give you an idea if the machine needs to be upgraded or is enough to support the load your clients will generate.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><!-- pn-faq --><\/p>\n<h2>Frequently Asked Questions<\/h2>\n<h3>Why measure CPU and memory if I already have response times?<\/h3>\n<p>Response times tell you the system is slow but not why. A server at 30 percent CPU with rising latency is waiting on something else, usually a database or a downstream call, and that is a completely different fix from a saturated server.<\/p>\n<h3>What should I watch on the machine generating the load?<\/h3>\n<p>The same metrics. A load generator that runs out of CPU or file descriptors quietly caps the traffic it produces, so the test flatlines and the target looks healthier than it is.<\/p>\n<h3>What am I looking for in the numbers?<\/h3>\n<p>The point where resource use and the load curve stop moving together. While they climb in step the system is coping; the moment they diverge you have found the bottleneck worth investigating.<\/p>\n<p><!-- \/pn-faq --><!-- pn-related-reading --><\/p>\n<h2>Related reading<\/h2>\n<ul>\n<li><a href=\"https:\/\/loadfocus.com\/blog\/2022\/04\/what-is-cpu-utilization-in-performance-testing\">What is CPU Utilization in Performance Testing?<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/blog\/2016\/04\/how-to-use-apache-jmeter-to-load-test-a-web-server\">How To Use Apache JMeter To Load Test a Web Server<\/a><\/li>\n<li><a href=\"https:\/\/loadfocus.com\/blog\/tech\/2015\/07\/using-a-csv-file-for-login-credentials-and-extracting-the-token-from-the-response-when-running-jmeter-tests\">JMeter: CSV Login Credentials and Token Extraction<\/a><\/li>\n<\/ul>\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\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>Key takeaways Response times alone cannot tell you whether the server is saturated or merely waiting. Watch the load generator too, since a saturated generator caps the test rather than the target. Correlate resource use with the load curve; the point where they diverge is the finding. In order to make\u00a0sure that your application will&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/tech\/2015\/07\/how-to-measure-cpu-and-memory-while-running-a-load-test\" class=\"more-link\" title=\"Read How to Measure CPU and Memory while Running a Load Test\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":501,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-performance"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":11,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":405,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/posts\/35\/revisions\/405"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/media\/501"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/tech\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}