{"id":2479,"date":"2019-08-08T03:09:04","date_gmt":"2019-08-08T03:09:04","guid":{"rendered":"https:\/\/codoid.com\/distributed-load-testing-in-locust\/"},"modified":"2022-05-25T07:50:12","modified_gmt":"2022-05-25T07:50:12","slug":"distributed-load-testing-in-locust","status":"publish","type":"post","link":"https:\/\/codoid.com\/performance-testing\/distributed-load-testing-in-locust\/","title":{"rendered":"Distributed Load Testing in Locust"},"content":{"rendered":"<p>Today, you will learn how to perform distributed load testing in Locust. If you are not familiar with Locust, then let&#8217;s refresh the basics and see how to perform distributed execution. Locust is an open source <a href=\"https:\/\/codoid.com\/performance-testing-services\/\">load testing<\/a> tool and you can describe all your test in Python code.<\/p>\n<p style=\"text-align:center;\"><img decoding=\"async\" title=\"Distributed Load Testing in Locust\" src=\"https:\/\/codoid.com\/wp-content\/uploads\/2019\/05\/Metrics-and-KPIs-for-Software-Testing.jpg\" alt=\"Distributed Load Testing in Locust\"><\/p>\n<p><strong>Installation<\/strong> <a href=\"https:\/\/locust.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Locust<\/a> is a Python library. It does not have any UI to write or configure your test. You can describe all your test in Python code.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npip install locustio\r\n<\/pre>\n<\/div>\n<p><strong>Locust File Creation<\/strong>Create a python file using the below code.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nfrom locust import HttpLocust, TaskSet, task\r\n\r\nclass UserBehavior(TaskSet):\r\n    @task\r\n    def index(self):\r\n        self.client.get(&quot;\/&quot;)\r\n\r\nclass WebsiteUser(HttpLocust):\r\n    task_set = UserBehavior\r\n    min_wait = 5000\r\n    max_wait = 9000\r\n<\/pre>\n<\/div>\n<p><b>Note: <\/b>If a file has HttpLocust class, then it will be considered as LocustFile. In the above code, we have two classes, one is TaskSet which is used to declare all your tests and the second one is HttpLocust which represents one user and it should have <i>task_set<\/i> attribute.<\/p>\n<p><strong>Executing Locust File<\/strong>Use the below command to run your Locust file.<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nlocust -f locust-examples\/locustfile.py --host=http:\/\/google.com\r\n<\/pre>\n<\/div>\n<p><b>Note: <\/b>As per the above command, our LocustFile is placed inside a folder (i.e. locust-examples). Once you execute the above command, Locust web monitor will start and you can start load execution from web monitor<\/p>\n<p><strong>Locust Web Monitor<\/strong>You can launch the web monitor using http:\/\/localhost:8089\/.<\/p>\n<p style=\"text-align:center;\"><img decoding=\"async\" title=\"Locust Web Monitor\" src=\"https:\/\/codoid.com\/wp-content\/uploads\/2019\/08\/Locust-Web-Monitor.png\" alt=\"Locust Web Monitor\"><\/p>\n<p>Now, click Start Swarming button after entering number of users and Hatch rate.<\/p>\n<h4>Distributed Execution<\/h4>\n<p>To start locust in master mode:<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nlocust -f my_locustfile.py --master\r\n<\/pre>\n<\/div>\n<p>And then on each slave (replace 192.168.0.14 with IP of the master machine):<\/p>\n<div class=\"editor editor-dark\">\n<div class=\"editor-top\">\n<ul class=\"editor-controls\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<\/div>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nlocust -f my_locustfile.py --slave --master-host=192.168.0.14\r\n<\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today, you will learn how to perform distributed load testing in Locust. If you are not familiar with Locust, then let&#8217;s refresh the basics and see how to perform distributed execution. Locust is an open source load testing tool and you can describe all your test in Python code. Installation Locust is a Python library. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2480,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[189,179,20],"tags":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.3 (Yoast SEO v20.3) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Distributed Load Testing in Locust - Codoid<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Distributed Load Testing in Locust\" \/>\n<meta property=\"og:description\" content=\"Today, you will learn how to perform distributed load testing in Locust. If you are not familiar with Locust, then let&#8217;s refresh the basics and see how to perform distributed execution. Locust is an open source load testing tool and you can describe all your test in Python code. Installation Locust is a Python library. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/\" \/>\n<meta property=\"og:site_name\" content=\"Codoid\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codoid.softwaretestingcompany\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-08T03:09:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-05-25T07:50:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codoid.com\/wp-content\/uploads\/2020\/08\/Distributed-Load-Testing-in-Locust-Banner-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"400\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codoid\" \/>\n<meta name=\"twitter:site\" content=\"@codoid\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Distributed Load Testing in Locust - Codoid","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Distributed Load Testing in Locust","og_description":"Today, you will learn how to perform distributed load testing in Locust. If you are not familiar with Locust, then let&#8217;s refresh the basics and see how to perform distributed execution. Locust is an open source load testing tool and you can describe all your test in Python code. Installation Locust is a Python library. [&hellip;]","og_url":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/","og_site_name":"Codoid","article_publisher":"https:\/\/www.facebook.com\/codoid.softwaretestingcompany","article_published_time":"2019-08-08T03:09:04+00:00","article_modified_time":"2022-05-25T07:50:12+00:00","og_image":[{"width":1200,"height":400,"url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/08\/Distributed-Load-Testing-in-Locust-Banner-1.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@codoid","twitter_site":"@codoid","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/#article","isPartOf":{"@id":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/"},"author":{"name":"admin","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586"},"headline":"Distributed Load Testing in Locust","datePublished":"2019-08-08T03:09:04+00:00","dateModified":"2022-05-25T07:50:12+00:00","mainEntityOfPage":{"@id":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/"},"wordCount":305,"commentCount":0,"publisher":{"@id":"https:\/\/codoid.com\/#organization"},"articleSection":["Performance Testing","Fixed","Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/","url":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/","name":"Distributed Load Testing in Locust - Codoid","isPartOf":{"@id":"https:\/\/codoid.com\/#website"},"datePublished":"2019-08-08T03:09:04+00:00","dateModified":"2022-05-25T07:50:12+00:00","breadcrumb":{"@id":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codoid.com\/learn\/performance-testing\/distributed-load-testing-in-locust\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codoid.com\/"},{"@type":"ListItem","position":2,"name":"Distributed Load Testing in Locust"}]},{"@type":"WebSite","@id":"https:\/\/codoid.com\/#website","url":"https:\/\/codoid.com\/","name":"Codoid","description":"","publisher":{"@id":"https:\/\/codoid.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codoid.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codoid.com\/#organization","name":"Codoid - Software Testing Company","url":"https:\/\/codoid.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/","url":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","contentUrl":"https:\/\/codoid.com\/wp-content\/uploads\/2020\/09\/Codoid_Software_Testing_Company_Logo.png","width":500,"height":500,"caption":"Codoid - Software Testing Company"},"image":{"@id":"https:\/\/codoid.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codoid.softwaretestingcompany","https:\/\/twitter.com\/codoid","https:\/\/www.instagram.com\/codoid.softwaretestingcompany\/","https:\/\/www.linkedin.com\/company\/codoid-qacompany","https:\/\/www.pinterest.com\/codoid9282\/codoid-software-testing-company\/","https:\/\/www.youtube.com\/channel\/UCCmOTDQgcf4W8oo22mBMUYA"]},{"@type":"Person","@id":"https:\/\/codoid.com\/#\/schema\/person\/360ee1d38151acb7c746787fbfa8e586","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codoid.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d33f9036c9d60684b9478f738779823?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/codoid.com"]}]}},"_links":{"self":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2479"}],"collection":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/comments?post=2479"}],"version-history":[{"count":4,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2479\/revisions"}],"predecessor-version":[{"id":16079,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/posts\/2479\/revisions\/16079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media\/2480"}],"wp:attachment":[{"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/media?parent=2479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/categories?post=2479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codoid.com\/wp-json\/wp\/v2\/tags?post=2479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}