Different data set for each thread in locust / Thread control in locust

965 Views Asked by At

I want to load test a distributed application and I decided to go with Locust. The problem I am facing is that there are number of different inputs to this application and I to avoid the repetition of these inputs.

For example: Lets consider there are 4 inputs (A,B,C,D). Now I am reading these inputs from a file and posting on the application's API. The problem is that if I have a task to post input A to the API, all the threads that I spawn will post "A" to the API, making it repetitive. I want a mechanism where I can feed different inputs to the different threads(users) that get spawned.

Is there a way so that I can either get control of the threads(users) or simply feed them different inputs?

2

There are 2 best solutions below

0
On

You may be able to use the running User’s greenlet identifier

import greenlet
...
(inside your task)
id = greenlet.getcurrent().minimal_ident

They are not unique across locust workers, but maybe you arent running distributed.

0
On

I had the same problem, and found an article on medium.com (written by Karol Brenja) that explored the subject. The code in the article doesn't work as-is with the latest version (as of writing, being 1.4.4) of locust.

In short:

  1. Start ZMQ "server" on master/local node in greenlet, queue test data (A, B, C, D)
  2. Connect to the server on master from the worker
  3. Server responds with one of the inputs on the queue
  4. Worker runs task with the testdata

This also works in local mode, as long as testdata isn't requested in blocking mode.