Herramientas de usuario

Herramientas del sitio


fw:locust

¡Esta es una revisión vieja del documento!


Locust

Is a load testing tool in which you define user behaviour and the system launches a lot of non-real users accessing your web page.

Basic things

Install

$ pip install locustio

Basic things in Locust

Examples

This…

from locust import HttpLocust, TaskSet
 
def login(l):
    l.client.post("/login", {"username":"ellen_key", "password":"education"})
 
def index(l):
    l.client.get("/")
 
def profile(l):
    l.client.get("/profile")
 
class UserBehavior(TaskSet):
    tasks = {index:2, profile:1}
 
    def on_start(self):
        login(self)
 
class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait=5000
    max_wait=9000

Is the same than…

from locust import HttpLocust, TaskSet, task

class UserBehavior(TaskSet):
    def on_start(self):
        """ on_start is called when a Locust start before any task is scheduled """
        self.login()

    def login(self):
        self.client.post("/login", {"username":"ellen_key", "password":"education"})

    @task(2)
    def index(self):
        self.client.get("/")

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

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait=5000
    max_wait=9000

Executing Locust

In the same path than the locust file:

locust

Or in different path:

locust -f ../locust_files/my_locust_file.py

Running multiple processes

  • It's recommended to install zeromq: $ pip install pyzmq
  • You can find more about this subject here.

You'll need a master:

locust -f ../locust_files/my_locust_file.py --master

And an arbitrary number of slave processes:

locust -f ../locust_files/my_locust_file.py --slave

Or with multiple machines:

locust -f ../locust_files/my_locust_file.py --slave --master-host=192.168.0.100

Accessing to the web interface

You only need to access the url: http://127.0.0.1:8089

More things...

fw/locust.1407483722.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)