Skip to content

Commit

Permalink
combined load shape
Browse files Browse the repository at this point in the history
  • Loading branch information
iljarotar committed Jan 17, 2024
1 parent 0d97333 commit 96e9e46
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
Binary file added locust/__pycache__/combined_load.cpython-311.pyc
Binary file not shown.
51 changes: 51 additions & 0 deletions locust/combined_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from locust import LoadTestShape
import math

class CombinedLoadShape(LoadTestShape):
irregular_load_duration = 3600
high_load_duration = 2400
steady_load_duration = 4800
duration = irregular_load_duration + high_load_duration + steady_load_duration

high_load_spawn_rate = 0.1
high_load_users = 300
steady_load_spawn_rate = 0.5
steady_load_users = 100

irregular_users_numbers = [
10, 90, 24, 75, 38, 99, 14,
46, 62, 23, 71, 12, 76, 53,
19, 94, 64, 72, 23, 86, 16,
85, 34, 26, 23, 95, 12, 43,
90, 54, 23, 81, 45, 23, 91,
74, 29, 56, 74, 100, 8, 34
]

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

if run_time >= self.duration:
return None

if run_time <= self.irregular_load_duration:
index = math.floor(run_time/self.irregular_load_duration * len(self.irregular_users_numbers))
return (self.irregular_users_numbers[index], self.irregular_users_numbers[index])

if run_time <= high_load_duration:
if (run_time - self.irregular_load_duration) <= self.high_load_duration / 2:
users = math.floor((run_time - self.irregular_load_duration) * self.high_load_spawn_rate)
return (min(users, self.high_load_users), self.high_load_spawn_rate)

remaining_time = self.high_load_duration - (run_time - self.irregular_load_duration)
users = math.floor(remaining_time * self.high_load_spawn_rate)
return (min(users, self.high_load_users), self.high_load_spawn_rate)

check_point = self.irregular_load_duration + self.high_load_duration

if (run_time - check_point) <= self.steady_load_duration / 2:
users = math.floor((run_time - check_point) * self.steady_load_spawn_rate)
return (min(users, self.steady_load_users), self.steady_load_spawn_rate)

remaining_time = self.duration - run_time
users = math.floor(remaining_time * self.steady_load_spawn_rate)
return (min(users, self.steady_load_users), self.steady_load_spawn_rate)
1 change: 0 additions & 1 deletion locust/irregular_load.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from locust import LoadTestShape
import random
import math

class IrregularLoadShape(LoadTestShape):
Expand Down
4 changes: 1 addition & 3 deletions locust/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ fi

echo "starting locust at $host"

locust $headless -H $host -f locustfile.py,irregular_load.py
locust $headless -H $host -f locustfile.py,high_load.py
locust $headless -H $host -f locustfile.py,steady_load.py
locust $headless -H $host -f locustfile.py,combined_load.py

0 comments on commit 96e9e46

Please sign in to comment.