-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_maker.py
59 lines (46 loc) · 1.29 KB
/
request_maker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import time
from locust import events
from locust.runners import WorkerRunner
from random import random
import controller_loop
env = None
monitoring = None
controller = None
method = None
data = None
headers = None
path = None
hosts = None
@events.init.add_listener
def on_locust_init(environment, **_kwargs):
global env
if not isinstance(environment.runner, WorkerRunner):
env = environment
def setup(_monitoring, _controller, _hosts, _method, _headers, _data, _path):
global monitoring, controller, hosts, method, data, path, headers
monitoring = _monitoring
controller = _controller
hosts = _hosts
method = _method
data = _data
path = _path
headers = _headers
def run(task):
cores = controller.cores
if cores < 1:
host = hosts[1]
else:
c1 = controller_loop.setCores
c2 = controller_loop.quotaCores
p = c1/(c1+c2)
host = hosts[0] if random() <= p else hosts[1]
start = time.time()
if method == "GET":
task.client.get(host+path)
elif method == "POST":
task.client.post(host+path, json=data, headers=headers)
end = time.time()
rt = end - start
t = env.shape_class.get_run_time()
users = env.runner.user_count
monitoring.tick(t, rt, users, cores)