Locust pressure measuring tool python

Locust pressure measuring tool python

Locust Introduction

Locust as performance testing framework based on Python language.

The advantage is that he can achieve a single concurrent amount 10 times and Jmeter LoadRunner tools. He works as a concurrent coroutines, which is gevent library.

Locust shortcomings are also evident, he did not have a friendly performance monitoring page, no association, parameterization, defined checkpoints and the like. Of course, these are not based on python problem, if a simple to use, the pressure measurement is used to make the most appropriate

Locust installation

1, the installation of python, and joined the environmental variables: pip intsall locustio

2, the internal Pycharm directly import Locust, as shown:

Locust example _1 (access Baidu home page)

Code:

. 1  from Locust Import HttpLocust, taskset, Task   # introduced need to reference the class 
2  . 3 class his MyTasks (taskset):
 . 4 '' ' . 5     to create a test task need to inherit taskset
 . 6     can be added a plurality of test tasks
 7 ' '' 8 # Per test tasks, often presented in the form of an instance method 9 # also need to use task decorator to decorate task 10     @task
 11 DEF one_task (Self):
 12 Print ( " the implementation of the first test mission " )
 13          self.client. GET ( " / " )   #      
       
     
     
               encapsulated client requests, it requests the request method can be invoked, in brackets sub-path, and the class RunTasks (HttpLocust) host splicing, may be written directly self.clint.get ( "http://www.baidu. com / "), the class RunTasks (HttpLocust) do not need to refer to the host 
14  15 class RunTasks (HttpLocust):
 16 '' ' . 17     create a running test class needs to inherit the parent class HttpLocust
 18 is ' '' . 19      task_set = his MyTasks # class specified test task, using the parent class attributes task_set cover 20 is      min_wait = 2000     # minimum latency between the simulated load when performing tasks, milliseconds 21 is      = 5000 MAX_WAIT     # maximum waiting time is performed between the load of the task, milliseconds 22 is      Host = " http://www.baidu.com/ " # for the measured pressure      
      



   

 

start up:

Cmd can be started, or may be started directly from Pycharm console: locust -f locusttest2.py --web-host = 127.0.0.1

-F behind with the need to start .py files, - web-host = 127.0.0.1 is where we need to show the front page of

After starting 127.0.0.1:8089 can be entered to access the page in a browser

Begin execution:

Statistics page

Chart page:

The first is: RPS number of outstanding requests per second, respectively

The second is: response time

The third is: the virtual number of different times

Failed Request page

Abnormal display page request

Data Download Page

Locust Example 2 (a sub-pressure measurement system)

from Locust Import HttpLocust, TaskSet, Task 
class AdminLoadTest (TaskSet):
     '' ' 
    create pressure measurement site management background class needs to inherit TaskSet 
    can add multiple tasks 
    '' ' 
    DEF the Login (Self):    # login method 
        ' '' 
        Login examples of the method 
        : return: 
        '' ' 
        self.client.post ( " HTTP: // IP: Port / ssoserver / Login-Service = HTTP:? // IP: Port / Portal / CAS " , { ' username ' : ' Y2R6Znc = ' , ' password ' : '== MTIzNDU2NzhBYQ ' ,' Scope ' : '' , ' lt ' : ' _cFC77B10F-B8C6-39DF-8177-35D753A043FC_kF557C6AB-47D5-9530-3B1F-75EA4B339131 ' , ' eventId ' : ' Submit ' }) # where the first cut package, found login interfaces, Because js encrypted passwords are carried out, we have the correct user name and password direct result of the encryption pass. post parameters can be used directly in the form of incoming dictionaries 
DEF Zimbabwe Logout (Self):   # Log method '' ' 
        exit instance method 
        : return: ' '' 
        self.client.get ( " HTTP: // ip: Port / Portal / Zimbabwe Logout "
        
        
DEF on_start (Self):
         '' ' 
        when performed before any task scheduling, on_start instance method is called 
        to log 
        : return: ' 
        '' 
        self.login () 
    DEF on_stop (Self):
         '' ' 
        when any one of after the task scheduled for execution, on_stop instance method is called 
        : return: 
        '' ' 
        self.logout () 
    @task    # task decorator to decorate task 
    DEF admin_index (Self):
         ' '' 
        to be back home pressure measurement 
        : return: 
        '' ' 
        self.client.get ( " HTTP: // ip: Port / Portal / ")
class: RunLoadTests (HttpLocust)
     '' ' 
    to create a running class 
    ' '' 
    task_set = AdminLoadTest 
    min_wait = 200 is     # minimum latency between the simulated load when performing tasks milliseconds 
    MAX_WAIT = 500     # time of executing tasks between the dummy load The maximum waiting time in milliseconds 
    
# start: Locust -f test_load.py --web-Host = 127.0.0.1 --host = 172.25.16.7

 

 

Installation of such parameters as the actions we perform: a total of 1000 users, each user to log in, visit the home page within 2-5 seconds, quit three movements. The number of users has not incremented five seconds a way that we look at the results:

Overview page

Chart page:

For these three actions, the number of requests per second subsystem can be completed in about 150

User response time increases the amount continues to rise

There is no failure and abnormal request

to sum up:

locust pressure measurement tool used to do quite good, because it can simulate single concurrency is really too high (uses a coroutine way to simulate concurrent), beyond the initial, locust also supports distributed, so it concurrency further promoted. Due to the drawbacks Locust is also clear that he did not have a friendly performance monitoring page, no association, parameterization, defined checkpoints and the like, so locust alone is not suitable for a complete performance test, of course, other libraries if combined with the python, it should also be addressed. Interested partners can study small study ...

Guess you like

Origin www.cnblogs.com/fccyccf/p/11586305.html