To:
Locust does not have a silly script recording function. To use it for performance testing, you must pull up your sleeves to write code. However. It is not difficult!
Write a simple performance test script
Create the load_test.py file and write a performance test script using python.
From locust import httplocust, taskset, task # defines user behavior class userbehavior (taskset): @ task def baidu_index (Self): Self. client. get ("/") Class websiteuser (httplocust): task_set = userbehavior min_wait = 3000 max_wait = 6000
The userbehavior class inherits the taskset class to describe user behavior.
The baidu_index () method indicates that a user is a row and can access the Baidu homepage. Use @ task to describe this method as a transaction. Client. Get () is used to indicate the Request Path "/". Because it is a Baidu homepage, it is specified as the root path.
The websiteuser class is used to set performance tests.
Task_set: point to a defined user behavior class.
Min_wait: lower threshold of user wait time between transactions (unit: milliseconds ).
Max_wait: upper limit of user wait time between transactions (unit: milliseconds ).
Perform a performance test
Start Performance Testing
> locust -f .\load_test.py --host=https://www.baidu.com[2017-10-16 16:44:40,839] DESKTOP-SMGQBBM/INFO/locust.main: Starting web monitor at *:8089[2017-10-16 16:44:40,842] DESKTOP-SMGQBBM/INFO/locust.main: Starting Locust 0.8
- -F specifies the performance test script file.
- -Host: Specifies the URL of the application to be tested. Pay attention to the HTTPS protocol used by Baidu.
Access through a browser: http: // localhost: 8089 (locust starts the network monitor, default port: 8089)
Set Test
Number of users to simulate sets the number of simulated users.
Hatch Rate (users spawned/second) Number of virtual users generated (started) per second.
Click "start swarming" to start the performance test.
Run the test
Performance test parameters
Type: Request type, such as get/post.
Name: Request Path. Here is the Baidu homepage, that is: https://www.baidu.com/
Request: the number of current requests.
Fails: number of failed requests.
Median: the median value, in milliseconds. Half of the server response time is lower than this value, and the other half is higher than this value.
Average: average value, in milliseconds, the average response time of all requests.
Min: Minimum Server Response Time of the request, in milliseconds.
MAX: Maximum server response time of the request, in milliseconds.
Content size: the size of a single request, in bytes.
Reqs/sec: the number of requests per second.
(3) create a performance test on Locust