Skip to content

Commit

Permalink
Merge pull request #2428 from locustio/fix-incorrect-first-wait-time-…
Browse files Browse the repository at this point in the history
…for-constant_pacing

Fix too long first wait time for constant_pacing (and constant_throughput)
  • Loading branch information
cyberw authored Oct 19, 2023
2 parents 2700a5d + 0e10e59 commit 0d1c03a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 2 additions & 0 deletions locust/user/users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations
from typing import Callable, Dict, List, Optional, final

import time
from gevent import GreenletExit, greenlet
from gevent.pool import Group
from urllib3 import PoolManager
Expand Down Expand Up @@ -119,6 +120,7 @@ def __init__(self, environment):
self._greenlet: greenlet.Greenlet = None
self._group: Group
self._taskset_instance: TaskSet = None
self._cp_last_run = time.time() # used by constant_pacing wait_time

def on_start(self):
"""
Expand Down
15 changes: 6 additions & 9 deletions locust/user/wait_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ def my_task(self):
"""

def wait_time_func(self):
if not hasattr(self, "_cp_last_run"):
self._cp_last_wait_time = wait_time
self._cp_last_run = time()
return wait_time
else:
run_time = time() - self._cp_last_run - self._cp_last_wait_time
self._cp_last_wait_time = max(0, wait_time - run_time)
self._cp_last_run = time()
return self._cp_last_wait_time
if not hasattr(self, "_cp_last_wait_time"):
self._cp_last_wait_time = 0
run_time = time() - self._cp_last_run - self._cp_last_wait_time
self._cp_last_wait_time = max(0, wait_time - run_time)
self._cp_last_run = time()
return self._cp_last_wait_time

return wait_time_func

Expand Down

0 comments on commit 0d1c03a

Please sign in to comment.