Locust压测官方文档阅读笔记

官方文档地址:What is locust
1. Each Locust class must have a task_set attribute set, that points to a TaskSet and defines the behaviour of the user and is described in more detail below.
2. min_wait and max_wait attributes: each simulated user will wait between executing each task(milliseconds)
3. this is specified on the command line, using the –host option, when locust is started. If one declares a host attribute in the locust class, it will be used in the case when no –host is specified on the command line.
4. Declaring tasks
1.we can use the task decorator, @task takes an optional weight argument that can be used to specify the task’s execution ratio.
2.the task attribute can be described as a list, each time a task is to be performed, it will be randomly chosen from the tasks attribute; Also, it can be a dict, and the task that is to be executed will be chosen at random but with the int as ratio.
The ratio mentioned above means it would be n times more likely to be executed than another_task
5. Making HTTP requests
When using the HttpLocust class, each instance gets a client attribute which will be an instance of HttpSession which can be used to make HTTP requests.
The behaviour of this user is defined by the task_set attribute, which should point to a TaskSet class. This class creates a client attribute on instantiation which is an HTTP client with support for keeping a user session between requests. We can reference the HttpSession instance using self.client inside the TaskSet.
The instance of HttpLocust has methods such as get, post, put, delete, head, patch, options.
6. Assert
We can mark the requests as success using catch_response argument and a with statement; Also we can use the response code(status_code).
7. Running locust distributed

猜你喜欢

转载自blog.csdn.net/Yumi_huang/article/details/82220116