2021年3月2日星期二

Not able to simulate 2 users after every 5 seconds at spawn_rate of 2 users/seconds in locust python

Tried below approach, it spawns 2 users every 5 seconds but spawn_rate is 1 user every second. How to increase the spawn rate?

https://docs.locust.io/en/stable/writing-a-locustfile.html

required spawn_rate = 2 users/per second required total users = 10

import logging  import math  from urllib.parse import urljoin    from locust import SequentialTaskSet, task, HttpUser, LoadTestShape  from locust.exception import StopUser    class LoadTest(SequentialTaskSet):    @task  def get_oauth_token(self):      logging.info("Oauth Token request")    @task  def get_output(self):      logging.info("task 2")    @task  def stop(self):      logging.info("Stopping user")      raise StopUser()      class ApiUser(HttpUser):      tasks = [LoadTest]      host = 'hosturl'    class StepLoadShape(LoadTestShape):      """      A step load shape      Keyword arguments:          step_time -- Time between steps          step_load -- User increase amount at each step          spawn_rate -- Users to stop/start per second at every step          time_limit -- Time limit in seconds      """      spawn_rate = 0.4 # Means 2 users every 5 seconds      time_limit = 600 # 10 mins      step_time = 600  # 10 mins      step_load = 10   # Total load 10    def tick(self):      run_time = self.get_run_time()        if run_time > self.time_limit:          return None        current_step = math.floor(run_time / self.step_time) + 1      return (current_step * self.step_load, self.spawn_rate)  

Tried stage shape from documentation, but locust stops after spawning first two users.

stages = [      {"duration": 25, "users": 2, "spawn_rate": 2},      {"duration": 20, "users": 2, "spawn_rate": 2},      {"duration": 15, "users": 2, "spawn_rate": 2},      {"duration": 10, "users": 2, "spawn_rate": 2},      {"duration": 5, "users": 2, "spawn_rate": 2},  ]    def tick(self):      run_time = self.get_run_time()        for stage in self.stages:          if run_time < stage["duration"]:              tick_data = (stage["users"], stage["spawn_rate"])              return tick_data        return None  

Any solution?

https://stackoverflow.com/questions/66451010/not-able-to-simulate-2-users-after-every-5-seconds-at-spawn-rate-of-2-users-seco March 03, 2021 at 12:55PM

没有评论:

发表评论