{"id":19092885,"url":"https://github.com/eon01/load_testing_locust","last_synced_at":"2026-06-14T01:34:03.528Z","repository":{"id":74328553,"uuid":"113942737","full_name":"eon01/load_testing_locust","owner":"eon01","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-12T04:47:22.000Z","size":149,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T07:48:04.420Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eon01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-12T04:19:39.000Z","updated_at":"2017-12-16T15:30:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"618cdd05-4516-42a6-a312-32ff55c46de3","html_url":"https://github.com/eon01/load_testing_locust","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eon01/load_testing_locust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eon01%2Fload_testing_locust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eon01%2Fload_testing_locust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eon01%2Fload_testing_locust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eon01%2Fload_testing_locust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eon01","download_url":"https://codeload.github.com/eon01/load_testing_locust/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eon01%2Fload_testing_locust/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34306772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-13T02:00:06.617Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T03:22:38.226Z","updated_at":"2026-06-14T01:34:03.512Z","avatar_url":"https://github.com/eon01.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\n\nThere are several types of test types in software engineering and load testing is one of the most common tests.\n\nThe purpose of this test is checking if a software can handle what it was designed to handle and identifying the blottleneck and any performance degradation. \n\nThis is performed by putting demand on a application under normal and peak load conditions. Load testing could help you determine some metrics like the Mean Time Between Failure (MTBF) and Mean Time To Failure (MTTF).\n\nAccording to [Microsoft guide Performance Testing Guidance for Web Applications](https://msdn.microsoft.com/en-us/library/bb924357.aspx), a load test enables you to measure response times, throughput rates, and resource-utilization levels, and to identify your application’s breaking point, assuming that the breaking point occurs below the peak load condition. \n\nAs a conclusion, load testing helps you to:\n\n- Determine the throughput required to support the anticipated peak production load.\n- Determine the adequacy of a hardware environment.\n- Evaluate the adequacy of a load balancer.\n- Detect concurrency issues.\n- Detect functionality errors under load.\n- Collect data for scalability and capacity-planning purposes.\n- Help to determine how many users the application can handle before performance is compromised.\n- Help to determine how much load the hardware can handle before resource utilization limits are exceeded. \n\nGatling, JMeter, Locust are some of the load testing tools.\n\nIn this practice lab, we are going to create a simple REST API and write some load test scenarios.\n\n# Preparing Our Application\n\n\nIn this practice lab, we are going to create a minimal RESTful API using the Flask framework. Our application will let the user get a list of software testing types or add a new type.\n\nThe purpose of this lab is to load test our RESTful API using Locust.\n\nWe are going to use:\n\n- Python 3.5\n- Python Virtualenv to create an isolated environment for our application\n- Locust: A load testing framework\n\nThis is the structure of our project folder:\n\n```\napp/\n├── app.py\n└── __init__.py\n__init__.py\n.gitignore\n```\n\nYou can also download the .gitignore file from [this repository](https://github.com/github/gitignore/blob/master/Python.gitignore).\n\nLet's start by creating the virtual environment for our Flask application. \n\n```\npython3 -m venv /path/to/new/virtual/environment\n```\n\nIf you are using Linux.\n\n```\nc:\\\u003ec:\\Python35\\python -m venv c:\\path\\to\\myenv\n```\n\nIf you are using Windows.\n\nIf everything is fine, let's activate it:\n\n```\n. /path/to/new/virtual/environment/bin/activate\n```\n\nIn order to use Flask, you need to install it from the Python Package Index using PIP:\n\n```\npip install flask\n```\n\nLet's create our application files:\n\n```\nmkdir project\nwget -O .gitignore \"https://github.com/github/gitignore/blob/master/Python.gitignore\" 2\u003e templog\ntouch __init__.py\nmkdir app\ntouch app/app.py\ntouch app/__init__.py\n```\n\nPaste this code inside the app.py file:\n\n```\nfrom flask import Flask, jsonify, request\n\napp = Flask(__name__)\n\ntesting_types = [\n  { 'name': 'unit testing', 'description': 'testing individual units of source code' }\n]\n\n\n@app.route('/tests')\ndef get_tests():\n  return jsonify(testing_types)\n\n\n@app.route('/tests', methods=['POST'])\ndef add_test():\n  testing_types.append(request.get_json())\n  return '', 204\n  \n  \n  \nif __name__ == '__main__':\n    app.run(debug=True)  \n    \n```\n\nThe above code has two functions:\n- get_tests : Used to get the list of tests from the testing\\_types dictionary \n- add_tests : Used to add a test to the testing\\_types dictionary\n    \nOur initial dictionary contains one test type:\n\n```\ntesting_types = [\n  { 'name': 'unit testing', 'description': 'testing individual units of source code' }\n]\n```\n\nIn order to run our API, type:\n\n```\npython app/app.py\n```\n\nYou should see something similar to the following output:\n\n```\npython app/app.py \n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n * Restarting with stat\n * Debugger is active!\n * Debugger PIN: 179-596-761\n```\n\nOur web server runs on: http://127.0.0.1:5000/ and in order to test it we can use a curl request. You can use your terminal or a graphical tool like Postman, Swagger or any other alternative.\n\nThis is our curl request to get the testing types list:\n\n```\ncurl -X GET  http://127.0.0.1:5000/tests\n```\n\nAt this stage, it should return:\n\n```\n[\n  {\n    \"description\": \"testing individual units of source code\", \n    \"name\": \"unit testing\"\n  }\n]\n```\n\nLet's try adding another type of test:\n\n```\ncurl -X POST -H \"Content-Type: application/json\" -d '{\n  \"name\": \"load testing\",\n  \"description\": \"checking if a software can handle the expected load\"\n}' http://localhost:5000/tests\n```\n\nAfter executing the last POST request, we can verify using another GET:\n\n```\ncurl -X GET  http://127.0.0.1:5000/tests\n```\n\nWe should see the two types of tests:\n\n```\n[\n  {\n    \"description\": \"testing individual units of source code\", \n    \"name\": \"unit testing\"\n  }, \n  {\n    \"description\": \"checking if a software can handle the expected load\", \n    \"name\": \"load testing\"\n  }\n]\n```\n\n# Load Testing Our RESTful API Using Locust\n\nLocust is described as an easy-to-use, distributed, user load testing tool. It is intended for load-testing web sites (or other systems) and figuring out how many concurrent users a system can handle.\n\nA swarm of locusts will attack your website. The behavior of each locust (or test user if you will) is defined by you and the swarming process is monitored from a web UI in real-time. This will help you battle test and identify bottlenecks in your code before letting real users in.\n\nSince Locust is event-based, it is possible to support concurrent users on a single machine. \n\nStart by installing Locust:\n\n```\npip install locustio\n```\n\nNow in the project root directory, create the locustfile.py file that will describe our testing scenarios:\n\n```\nfrom locust import HttpLocust, TaskSet, task\n\nclass UserBehavior(TaskSet):\n\n    @task\n    def get_tests(self):\n        self.client.get(\"/tests\")\n        \n    @task\n    def put_tests(self):\n        self.client.post(\"/tests\", {\n\t\t\t\t\t\t  \"name\": \"load testing\",\n\t\t\t\t\t\t  \"description\": \"checking if a software can handle the expected load\"\n\t\t\t\t\t\t})\n        \n\nclass WebsiteUser(HttpLocust):\n    task_set = UserBehavior\n    \n```\n\nIn this file we told Locust to create two test tasks:\n\n- The first one will execute a GET request to list the test types we stored in our dictionary\n- The second one will execute a POST request to add a new testing type\n\nNow start our Flask API using ``` python app/app.py ``` and Locust using ``` locust --host=http://localhost:5000 ```.\n\nMake sure to change ``` http://localhost:5000 ``` by the real address of your application.\n\nThe web interface of Locust is available by default at ``` http://localhost:8089 ```\n\n![Locust Home Page](images/locust_home.png \"Locust Home Page\")\n\nSay our API should support a number of 10000 user. We can start a test by giving this value to Locust, using the web interface, as well as the the hatch rate which is the number of users spawned by second.\n\nAfter clicking on \"Start spawning\", you can see different live statistics about your tasks like the number of requests, fails, and other statistics about the response time.\n\n![Locust Statistics](images/locust_stats.png \"Locust Statistics\")\n\nUsing the Charts view, we can determine some fact-based conclusions. For instance, if we don't accept a response time greater than 450ms, we know that our application cannot handle more than 117 request per second and that the max number of simultaneous users should be less than 350.\n\n\n# Conclusion\n\nIn this practice lab, we created a RESTful API and tested its performance using Locust. Using the results from our tests, we determined how our API can behave with a certain number of users and requests.\n\nLoad testing is an important practice since it prevents organizations from downtimes and failures due to errors like the timeout or memory overflows. Load testing gives meaningful results when tests are done against a similar environment to production (configurations, code, physical resources like disks and memory ..etc).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feon01%2Fload_testing_locust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feon01%2Fload_testing_locust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feon01%2Fload_testing_locust/lists"}