Python-based performance load test locus-2-Quick Start

Source: Internet
Author: User

Quick Start Example locustfile.py

This is a quick start for a small example locustfile.py:

FromLocustImportHttplocust,TaskSetDefLogin(L):L.Client.Post("/login",{"Username":"Ellen_key","Password":"Education"})DefIndex(L):L.Client.Get("/")DefProfile(L):L.Client.Get("/profile")ClassUserbehavior(taskset): tasks = { index:2, profile :1} def on_start  (selflogin ( self) class websiteuser ( httplocust): task_set =  Userbehavior min_wait = 5000 max_wait = 9000             

Here we define a few locust tasks that pass in a parameter (an instance of locust) and can be called normally. These tasks are clustered within the class named Taskset in the Tasks property. We also define a class named Httplocust, which represents a user, and we define a virtual user's wait time between performing different tasks, as if the Taskset class should define the user's "behavior." Tasksets can be nested.

The Httplocust class inherits the Locust class and adds a Slave property, which is an instance of httpsession that is used to initiate an HTTP request.

In addition, we can define tasks, which is more convenient because of the use of the @task adorner. The following code is equivalent to the code above.

FromLocustImportHttplocust,TaskSet,TaskClassUserbehavior(TaskSet):DefOn_Start(Self):"" "On_Start is called if a locust start before any task is scheduled" ""Self.Login()DefLogin(Self):Self.Client.Post("/login",{"Username":"Ellen_key","Password":"Education"})@task(2)DefIndex(Self):Self.Clientget ( "/" )  @task  (1) def profile  (selfself. Client. Get () class  Websiteuser (httplocust): task_set = userbehavior min_wait = 5000 span class= "n" >max_wait = 9000 

The Locust class (like Httplocust, because it's a subclass) can define the minimum and maximum wait times-based on the wait time between the M virtual user-task (minimum wait and maximum wait), as with other user behavior.

Start Locust

If the above file is named locustfile.py and we execute the command path and this file is in the same sibling directory, then long can be started by the following command locust

Locust--host=http://example.com

If the locust file is placed elsewhere:

Locust-f. /locust_files/my_locust_file.py--host=http://example.com

If you need to run locust distributed under multiple processes, we can start a main process with "-master":

Locust-f. /locust_files/my_locust_file.py--master--host=http://example.com

You can then start any number of slave processes:

Locust-f. /locust_files/my_locust_file.py--slave--host=http://example.com

If we want to run locust on multiple machines, we can also define the primary server to which it belongs while starting from the server (if you are running locust on only one machine, you do not need to do this because the primary server defaults to 127.0.0.1)

Locust-f. /locust_files/my_locust_file.py--slave--master-host=192.168.0.100--host=http://example.com

Ps:

See all feature Options

Locust–help
Open the Locust page interface

If you have started locust with either of these commands, then you should open your browser and point to http://127.0.0.1:8089 (if you run locust locally). Then you will be presented with the following gorgeous page.

 

Python-based performance load test locus-2-Quick Start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.