Herramientas de usuario

Herramientas del sitio


fw:locust

Diferencias

Muestra las diferencias entre dos versiones de la página.

Enlace a la vista de comparación

Ambos lados, revisión anterior Revisión previa
Próxima revisión
Revisión previa
fw:locust [2014/08/08 08:28]
alfred [Basic things in Locust]
fw:locust [2020/05/09 09:25] (actual)
Línea 2: Línea 2:
 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. 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.
  
 +  * Docs: [[http://​docs.locust.io/​en/​latest/​]]
 ===== Basic things ===== ===== Basic things =====
 ==== Install ==== ==== Install ====
Línea 12: Línea 13:
  
 ''​HttpLocust''​ is a ''​Locust''​ class that allows HTTP requests. ''​HttpLocust''​ is a ''​Locust''​ class that allows HTTP requests.
 +
 +The ''​Locust''​ class represents a user then, the system, will create a lot of locust instances (one for each user simulated). It contains...
 +  * ''​task_set''​ attribute, which will be set with a ''​TaskSet''​ instance that defines the user behaviour.
 +  * ''​min_wait''​ and ''​max_wait''​ attributes, milliseconds that a simulated user will wait between executing each task. If they are not set, locust will wait a second to execute it again (both have 1000 as default).
 +  * ''​host'',​ you can specify it on the command line using the –host option. It tells the host to be loaded.
 +  * ''​weight''​ tells the frequency of use, for example, ''​WebUserLocust''​ will be executed three times ''​MobileUserLocust''​.
 +<code python>
 +class WebUserLocust(Locust):​
 +    weight = 3
 +    ....
 +
 +class MobileUserLocust(Locust):​
 +    weight = 1
 +    ....
 +</​code>​
 +The ''​TaskSet''​ represents the user behaviour. It's a collection of tasks (actions). If we were loadtesting an auction website this tasks would be like “loading the start page”, “searching for some product” and “making a bid”.
 +
 +In a load test, each TaskSet will pick one of it’s tasks and call it. It will then wait a number of milliseconds,​ chosen at random between min_wait and max_wait attributes. Then it will again pick a new task which will be called, then wait again, and so on.
 +
 === Examples === === Examples ===
 This... This...
Línea 38: Línea 58:
 </​code>​ </​code>​
 Is the same than... Is the same than...
-<​code>​+<​code ​python>
 from locust import HttpLocust, TaskSet, task from locust import HttpLocust, TaskSet, task
  
Línea 70: Línea 90:
 <​code>​ <​code>​
 locust -f ../​locust_files/​my_locust_file.py locust -f ../​locust_files/​my_locust_file.py
 +</​code>​
 +Running two locust in the same file (weight attribute will define the frequency of calling).
 +<​code>​
 +locust -f locust_file.py WebUserLocust MobileUserLocust
 </​code>​ </​code>​
  
Línea 93: Línea 117:
  
 ===== More things... ===== ===== More things... =====
 +==== The TaskSet class ====
 +=== Declaring tasks with the task decorator ===
 +<code python>
 +from locust import Locust, TaskSet, task
 +
 +class MyTaskSet(TaskSet):​
 +    @task
 +    def my_task(self):​
 +        print "​Locust instance (%r) executing my_task"​ % (self.locust)
 +
 +class MyLocust(Locust):​
 +    task_set = MyTaskSet
 +</​code>​
 +Or defining weight (task2 will be executed twice than task):
 +<code python>
 +from locust import Locust, TaskSet, task
 +
 +class MyTaskSet(TaskSet):​
 +    min_wait = 5000
 +    max_wait = 15000
 +
 +    @task(3)
 +    def task1(self):​
 +        pass
 +
 +    @task(6)
 +    def task2(self):​
 +        pass
 +
 +class MyLocust(Locust):​
 +    task_set = MyTaskSet
 +</​code>​
 +
 +=== Set an dictionary to tasks attribute ===
 +The next dictionary will assign two tasks, each one with their weight.
 +<code python>
 +class MyTaskSet(TaskSet):​
 +    tasks = {my_task: 3, another_task:​1}
 +</​code>​
 +
 +=== The on_start function ===
 +A TaskSet class can declare an on_start function. That function is called when a simulated user starts executing tasks in that TaskSet.
 +
 +=== Nesting TaskSets ===
 +We can define a ''​TaskSet''​ as a task. Then it will represent a group of sub-task which are executed in that way. 
 +
 +It could be useful to represent a user that makes actions over the web (like enter in a web, then browse films and watch one, then navigate in the blog and comment and comment again, then navigate again, then browse films...). ​
 +
 +A nested class set could call the ''​self.interrupt()''​ function. It interrupts the action in that class set.
 +
 +=== Nested sub-tasks examples ===
 +
 +<code python>
 +class ForumPage(TaskSet):​
 +    @task(20)
 +    def read_thread(self):​
 +        pass
 +
 +    @task(1)
 +    def new_thread(self):​
 +        pass
 +
 +    @task(5)
 +    def stop(self):
 +        self.interrupt()
 +
 +class UserBehaviour(TaskSet):​
 +    tasks = {ForumPage:​10}
 +
 +    @task
 +    def index(self):​
 +        pass
 +</​code>​
 +<code python>
 +class MyTaskSet(TaskSet):​
 +    @task
 +    class SubTaskSet(TaskSet):​
 +        @task
 +        def my_task(self):​
 +            pass
 +</​code>​
 +==== Hacer nuestro propio cliente ====
 +Haremos un cliente "​específico"​ para la tarea de deseemos. Este heredará de la clase ''​Locust''​ y usará el código que deseemos. Luego, para definir las acciones del test de carga heredaremos de esa clase; esta contendrá el taskset. Ver [[http://​docs.locust.io/​en/​latest/​testing-other-systems.html|aquí]],​ donde tenemos un código ''​XmlRpcClient''​ y una clase ''​Locust''​ que lo usa, la ''​XmlRpcLocust''​.
  
 +==== The HTTPClient ====
 +  * [[http://​docs.locust.io/​en/​latest/​writing-a-locustfile.html#​using-the-http-client]]
fw/locust.1407486528.txt.gz · Última modificación: 2020/05/09 09:24 (editor externo)