0

I am trying to load test a HTTP URL(Dynamic) using Locust.io. I already have the python scripts that will make a GET call to the URL. The challenge i am facing is, the urls and the number of users are dynamic and are read from a CSV file.

For example, Here is how the input of the load testing will look like:

Input.csv:

============

URLs          No of users to simulate
=============================================
URL 1               1000
URL 2               5000
URL 3               2000
URL 4               1000

Each url in the CSV is unique and the number of users to simulate change for every url. i would like to use the locust load testing in distributed mode.

For example, Locust master will read URL 1 and send it to Slave 1 to simulate 1000 users. and then pick URL2 and send it to Slave 2 to simulate 5000 users.

how do i achieve this using locust? can someone throw some light?

enderland
  • 13,825
  • 17
  • 98
  • 152
janvi
  • 1
  • 3

2 Answers2

0

Locust doesn't support this the way you are thinking. Locust weights tasks rather than users, so you give a relative weight to the tasks you want to exercise (your urls in your above).

What you probably want to do is weight the tasks themselves this way using a TaskSet:

class MyTaskSet(TaskSet):
    @task(1)
    def one(self):
        self.client.get("url 1")

    @task(5)
    def two(self):
        self.client.get("url 2")

    @task(2)
    def three(self):
        self.client.get("url 3")

    @task(1)
    def three(self):
        self.client.get("url 4")

You can have code to parse and read your file (which is not csv in format by the way though you've named it such?) ahead of this in your locust file and pass this to the task decorator and urls.

enderland
  • 13,825
  • 17
  • 98
  • 152
  • Hi Elysian, Thanks for taking time to answer. I have more than 50,000 different urls. how can i create tasks for each url? is there any other better way? – janvi May 09 '18 at 21:08
  • @janvi I would create separate tasks for the different weights u have, hopefully _much_ less than 50K, and then have each task query a random url for it's "bucket" on each callback. – Jonas Bergström Mar 15 '19 at 10:19
0

use locust LoadTestShape: https://docs.locust.io/en/stable/generating-custom-load-shape.html

class MyCustomShape(LoadTestShape): time_limit = 600 spawn_rate = 20

def tick(self):
    run_time = self.get_run_time()

    if run_time < self.time_limit:
        # User count rounded to nearest hundred.
        user_count = round(run_time, -2)
        return (user_count, spawn_rate)

    return None