Locust stress test helloworld

1. What is Locust

Locust is an easy-to-use, scriptable and extensible performance testing tool that can be run directly using pyhton.

2. Install Locust

Python 3.9.16
pip install locust==2.15.1

3. A simple example

3.1. Write the following code and name the file locustfile_test.py

from locust import HttpUser, TaskSet, task
import urllib3

urllib3.disable_warnings()

class UserBehavior(TaskSet):

    def on_start(self):
        print("start****")

    def on_stop(self):
        print("stop****")

    @task(1)
    def baidu_page1(self):
        res = self.client.get("/", verify=False)

class WebsiteUser(HttpUser):
    tasks = [UserBehavior]
    host = "https://www.baidu.com"
    min_wait = 1000
    max_wait = 2000

3.2. Execute the above code through the following command

locust -f locustfile_test.py

3.3. Access through http://localhost:8089/, Number of total users to simulate sets the number of simulated users, Spawn rate (users spawned/second) the number of virtual users started per second

3.4. Results after [Start swarming]:

    Performance parameters:

Type: Request type, such as Get/Post
Name: request path
Requests: Current Request Quantity
Failes: Number of failed requests
Median: Median milliseconds, half of the server responses are below this value, and half are above this value
 90%: 90% request response time
Average: Average value, in milliseconds, the average response time of all requests
 Min: Minimum server response time for requests
 Max: Requested server maximum response time
Average size: Single request size, bytes
RPS: The number of requests that can be processed per second

4. The difference between locust and jmeter

tool the difference
jmeter You need to "write" scripts by selecting components on the UI interface. The simulated load is thread-bound, which means that each user of the simulation needs a separate thread. The number of loads that can be simulated by a single load machine is limited
locust Complete the test script by writing simple and easy-to-read code, based on events, under the same configuration, the number of loads that can be simulated by a single load machine far exceeds that of jmeter

PS : However, the limitation of locust is that its own monitoring of the test process and display of test results is not as comprehensive and detailed as jmeter. Secondary development is required to meet the increasingly complex performance test needs.

References

Locust - A modern load testing framework

Guess you like

Origin blog.csdn.net/keeppractice/article/details/130260844