-
Notifications
You must be signed in to change notification settings - Fork 5
/
locustfile.py
96 lines (77 loc) · 2.69 KB
/
locustfile.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from locust import *
from random import *
import json
# --------------------------------------------------------------------------- #
# Ingestion to MongoDB
# --------------------------------------------------------------------------- #
# ingestion_client_id = 0
# def next_ingestion_client_id():
# global ingestion_client_id
# ingestion_client_id += 1
# return ingestion_client_id
# class IngestionClient(TaskSet):
# def on_start(self):
# self.tyreId = str(next_ingestion_client_id())
# self.pressure = 12.0 + randint(0, 5)
# @task(4)
# def send_pressure_update(self):
# delta = random()
# if (randint(1, 2) % 2 is 0):
# self.pressure += delta
# else:
# self.pressure -= delta
# data = json.dumps({"tyreId": self.tyreId, "pressure": self.pressure})
# self.client.post("http://localhost:3000/ingest", data=data)
# @task(1)
# def get_last_five(self):
# self.client.get("http://localhost:3000/last/5/" + self.tyreId)
# class IngestionUser(HttpLocust):
# task_set = IngestionClient
# host = "localhost"
# min_wait = 5000
# max_wait = 10000
# --------------------------------------------------------------------------- #
# Edge service
# --------------------------------------------------------------------------- #
# edge_client_id = 0
# def next_edge_client_id():
# global edge_client_id
# edge_client_id += 1
# return edge_client_id
# class EdgeClient(TaskSet):
# def on_start(self):
# self.tyreId = str(next_edge_client_id())
# @task
# def ask_for_data(self):
# self.client.get("http://localhost:4000/" + self.tyreId)
# class EdgeUser(HttpLocust):
# task_set = EdgeClient
# host = "localhost"
# min_wait = 10000
# max_wait = 20000
# --------------------------------------------------------------------------- #
# Kafka ingester
# --------------------------------------------------------------------------- #
ingestion_client_id = 0
def next_ingestion_client_id():
global ingestion_client_id
ingestion_client_id += 1
return ingestion_client_id
class IngestionClient(TaskSet):
def on_start(self):
self.tyreId = str(next_ingestion_client_id())
self.pressure = 12.0 + randint(0, 5)
@task
def send_pressure_update(self):
delta = random()
if (randint(1, 2) % 2 is 0):
self.pressure += delta
else:
self.pressure -= delta
data = json.dumps({"tyreId": self.tyreId, "pressure": self.pressure})
self.client.post("http://localhost:7000/ingest", data=data)
class IngestionUser(HttpLocust):
task_set = IngestionClient
host = "localhost"
min_wait = 5000
max_wait = 10000