Locust Multiple Hosts With Different Peak Concurrency (Web UI)
Question:
I am trying out the Locust load testing Framework. I have a case where I want to test multiple hosts:
from locust import HttpUser, task, between
from tasks import TaskList
class FirstUser(HttpUser):
wait_time = between(5, 15)
host = "https://example.com"
tasks = TaskList
class SecondUser(HttpUser):
wait_time = between(5, 15)
host = "https://anotherexample.com"
tasks = TaskList
I have found that Locust accepts a fixed_count
parameter to spawn an exact number of users on a class.
I want this fixed_count
to be set from the Web UI. I can see from the Locust source code here that it should be possible to pass an extra_options
to define new fields on the Web UI Form. There is however no documentation on how to define these fields nor how to obtain the values they submit.
Does anyone know how to go about doing this?
Answers:
Perhaps it could be made more prominent or more clear, but the Locust docs do talk about how to get custom arguments to appear in the web UI using this example:
@events.init_command_line_parser.add_listener
def _(parser):
parser.add_argument("--my-argument", type=str, env_var="LOCUST_MY_ARGUMENT", default="", help="It's working")
# Set `include_in_web_ui` to False if you want to hide from the web UI
parser.add_argument("--my-ui-invisible-argument", include_in_web_ui=False, default="I am invisible")
# Set `is_secret` to True if you want the text input to be password masked in the web UI
parser.add_argument("--my-ui-password-argument", is_secret=True, default="I am a secret")
You then can access your custom arguments in your User like this:
class WebsiteUser(HttpUser):
@task
def my_task(self):
print(f"my_argument={self.environment.parsed_options.my_argument}")
print(f"my_ui_invisible_argument={self.environment.parsed_options.my_ui_invisible_argument}")
It should be possible to add a custom argument to the web UI that you can then use to set your fixed_count
to.
I am trying out the Locust load testing Framework. I have a case where I want to test multiple hosts:
from locust import HttpUser, task, between
from tasks import TaskList
class FirstUser(HttpUser):
wait_time = between(5, 15)
host = "https://example.com"
tasks = TaskList
class SecondUser(HttpUser):
wait_time = between(5, 15)
host = "https://anotherexample.com"
tasks = TaskList
I have found that Locust accepts a fixed_count
parameter to spawn an exact number of users on a class.
I want this fixed_count
to be set from the Web UI. I can see from the Locust source code here that it should be possible to pass an extra_options
to define new fields on the Web UI Form. There is however no documentation on how to define these fields nor how to obtain the values they submit.
Does anyone know how to go about doing this?
Perhaps it could be made more prominent or more clear, but the Locust docs do talk about how to get custom arguments to appear in the web UI using this example:
@events.init_command_line_parser.add_listener
def _(parser):
parser.add_argument("--my-argument", type=str, env_var="LOCUST_MY_ARGUMENT", default="", help="It's working")
# Set `include_in_web_ui` to False if you want to hide from the web UI
parser.add_argument("--my-ui-invisible-argument", include_in_web_ui=False, default="I am invisible")
# Set `is_secret` to True if you want the text input to be password masked in the web UI
parser.add_argument("--my-ui-password-argument", is_secret=True, default="I am a secret")
You then can access your custom arguments in your User like this:
class WebsiteUser(HttpUser):
@task
def my_task(self):
print(f"my_argument={self.environment.parsed_options.my_argument}")
print(f"my_ui_invisible_argument={self.environment.parsed_options.my_ui_invisible_argument}")
It should be possible to add a custom argument to the web UI that you can then use to set your fixed_count
to.