Performance Testing Advanced :( a) performance test tools Locust

An open source load testing tool.

An open source performance testing tools.

define user behaviour with python code, and swarm your system with millions of simultaneous users.

Using Python code to define user behavior. It can simulate the use of millions of concurrent users accessing your system.

Why the sudden concern for performance testing tool? In fact, I just simply interested in just the tool itself on Locust.

1, it is with the current mainstream LoadRunner and Jmeter play are not the same. 2, it is entirely based on the Python development with Python to write user behavior.

Ah, if you want to make good use of it, you must have some knowledge of Web development. But also familiar with Python development.

Official Website: http://locust.io/

A, Locust installation                                                         

1, install Python:

Official: https://www.python.org/

Installation Python3

2, installation Locust

2.1 pip command by mounting /> pip install locustio

2.2 on GitHub by cloning project installation (Python3 recommended): https://github.com/locustio/locust

3, installation pyzmq

If you intend to run Locust distributed across multiple processes/machines, we recommend you to also install pyzmq.

If you intend to run Locust distributed across multiple processes / machine, I suggest you also install pyzmq.

By command to install pip: pip install pyzmq

4, the installation is successful, CMD typing the command verification: locust --help

Second, simply write performance test scripts                                         

Creating load_test.py file, write performance test scripts Python.

Copy the code
from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):

    @task(1)
    def baidu(self):
        self.client.get("/")



class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 3000
    max_wait = 6000
Copy the code

Creating UserBehavior () class inherits TaskSet class for user behavior.

Creating baidu () method represents a behavior, access Baidu home page. With @task () method is a decoration of the task. 1 shows an example of the selection performed Locust weight, the greater the value, the higher the frequency is performed. In the current UserBehavior () behavior is only a baidu () task, so, right here is reset to a few, there is no impact.

WebsiteUser () class is used to set the performance test.

task_set: point to a defined class of user behavior.

min_wait: lower bound of waiting time between users perform tasks, unit: milliseconds.

max_wait: waiting time between users perform tasks on the sector, unit: milliseconds.

Third, the performance test run                                                            

Change to the directory where the performance test script, startup performance tests:

 -------------------------------------------------------------------------------------------------------------------

locust -f load_test.py --host=https://www.baidu.com

[2020-03-15 22:38:16,967] fnngj-PC/INFO/locust.main: Starting web monitor at *:8089

[2020-03-15 22:38:16,967] fnngj-PC/INFO/locust.main: Starting Locust 0.7.5

 --------------------------------------------------------------------------------------------------------------------

load_test.py test script, https: //www.baidu.com test site.

Open your browser and visit: http: //127.0.0.1: 8089

Number of users to simulate simulated users disposed

Hatch rate (users spawned / second) hatching rate? I do not know how to translate, produce (start) number of users per second.

Click Start swarming start running performance tests.

If caught your interest, the rest of you from a play! Difficulties in the preparation of performance testing scripts.

Reference document: http://docs.locust.io/en/latest/quickstart.htm L

----------------------------------------------------------------------------------------------------

Four, Locust tutorial series

" Locust introduce "

" Locust Installation "

" Locust Create performance ."

" Locust NO-Web mode "

" Locust Parameters "

" Locust Distributed Run "

" Locust classes and methods ."

" Locust setting assertion "

" Locust parameterized "

Guess you like

Origin www.cnblogs.com/Kevin6317/p/12501368.html