I have a question about sequential sending of requests. I have an approximate version of the code that I use. I want each subsequent request to come from a new user. My generator simulates the number of requests per minute. If my generator “created” 3 requests – I want to send these requests one after another sequentially using a ‘sleep_time’, etc.
I am interested in the following questions:
- How can I manage the number of users? – An user sent a request -> a new user was spawned -> a new user sent a request
- When I create several users at once – they all send a request at the same time and only then the sleep_time is triggered. This does not suit me 🙁
- Is it possible to somehow manage one user? – When you sent a request -> spawned a new user to send the next request -> the old user was “killed/stopped”, etc.
def requests_generator():
"""
Generator function to yield N-request counts dynamically.
"""
while True:
requests = random.randint(5, 50)
sleep_time = round(60 / requests, 2)
yield requests, sleep_time
class CustomUserTaskSet(TaskSet):
requests_gen = requests_generator()
@task
def first_task(self):
group = Group()
requests_count, sleep_time = next(self.requests_gen)
for _ in range(requests_count):
group.spawn(self.apply3d)
gevent.sleep(sleep_time)
def apply3d(self):
response = self.client.post("/ENDPOINT", headers=headers)
logging.info(response.status_code)
class CustomUser(HttpUser):
tasks = [CustomUserTaskSet]