-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocust_fail.py
44 lines (30 loc) · 1.1 KB
/
locust_fail.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
# A small "locustfile" which simulates Kazoo errors; shows the impact
# of numerous failures on reported latency.
#
# Compare by setting `--exception-behavior` to `log_failure` (default)
# or `try_suppress` or in `parameterized-locust.sh`.
import random
import gevent
from locust import task
from zk_locust import ZKLocust, ZKLocustTaskSet, LocustTimer
from locust_extra.stats import register_extra_stats
from zk_metrics import register_zk_metrics
import kazoo.exceptions
register_extra_stats()
register_zk_metrics()
class FakeKazooFail(kazoo.exceptions.KazooException):
pass
class MostlyFailTaskSet(ZKLocustTaskSet):
def __init__(self, *args, **kwargs):
super(MostlyFailTaskSet, self).__init__(*args, **kwargs)
self._rg = random.Random(1571644455)
@task
def mostly_fail_task(self):
p_err = 3 / 4
with LocustTimer('op', 'mostly_fail'):
if self._rg.random() < p_err: # random() is uniform [0, 1).
raise FakeKazooFail()
else:
gevent.sleep(0.1)
class MostlyFailLocust(ZKLocust):
task_set = MostlyFailTaskSet