[Python] Locust: open source load testing tool
Locust is a open source performance testing tool.
Define user behaviour with python code, and swarm your system with millions of simultaneous users.
Use Python code to define user behavior. Use it to simulate millions of concurrent users accessing your system.
If you often pay attention to my blog, probably will note that I have three or four years did not write about the performance test article, in fact, this year did not update a few decent blog, but I was the busiest year, because Write a book about interface automation.
Back to the theme, why suddenly focus on performance testing tools? In fact, I am simply interested in the Locust tool itself. 1, it is the current mainstream LoadRunner and Jmeter are not the same. 2, it is based entirely on Python development, with Python to write user behavior.
Well, if you want to use it, you have to have some knowledge of Web development. But also familiar with Python development.
Official website: http://locust.io/
Locust installation
1, Install Python:
Official: https://www.python.org/
Install Python2 or Python3
2, Install Locuse
- through the pip command to install /> pip install locustio
- through the GitHub cloning project installation (Python3 recommended ): https://github.com/locustio/locust
3, Install pyzmq
If you intend to run Locust distributed across multiple processes/machines, we recommend you also also install pyzmq.
If you intend to run Locust distributed over multiple processes/machines, we recommend that you also install pyzmq.
Installed with the pip command. /> pip install pyzmq
4, the installation is successful, CMD typing command validation. /> locust -help
Write a simple performance test script
Create a load_test.py file to write performance test scripts in Python.
Create the UserBehavior() class to inherit the TaskSet class for user behavior.
Create a google() method to represent a behavior, visit the google home page. Use @task() to decorate the method for a task. 1 indicates that a Locust instance is selected to execute the weight, the greater the value, the higher the execution frequency. There is only one google() task under the current UserBehavior() behavior, so the weight here is set to a few and has no effect.
The WebsiteUser() class is used to set performance tests.
task_set: points to a defined user behavior class.
min_wait: the lower bound of the wait time between the user’s tasks, in milliseconds.
max_wait: The upper bound of the wait time between the user’s tasks, in milliseconds.
Operational performance test
Switch to the directory where the performance test script is located, start the performance test:
…/> locust -f load_test.py –host=https://www.google.com
[2016-11-19 22:38:16,967] fnngj-PC/INFO/locust.main: Starting web monitor at *:8089
[2016-11-19 22:38:16,967] fnngj-PC/INFO/locust.main: Starting Locust 0.7.5
load_test.py for the test script, https://www.google.com for the tested site.
Open the browser to visit: http://127.0.0.1:8089
Number of users to simulate Sets the number of simulated users
Hatch rate (users spawned/second)? Do not know how to translate, generate (start) the number of users per second.
Click Start swarming to start the performance test.
If you have aroused your interest, the rest of your own play it! Difficulty in the preparation of performance test scripts.