-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathload-test-grpc.py
139 lines (121 loc) · 4.63 KB
/
load-test-grpc.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from dataclasses import dataclass
from urllib import response
from barazmoon import MLServerAsyncGrpc
from barazmoon import Data
from datasets import load_dataset
import asyncio
import time
import numpy as np
import mlserver.types as types
load = 1
test_duration = 1
variant = 0
platform = "seldon"
mode = "exponential"
# INFO this scripts is using https://github.com/reconfigurable-ml-pipeline/load_tester/tree/saeed
# for load testing, can be substituted with any other load test scripts
# single node inference
if platform == "seldon":
endpoint = "localhost:32000"
deployment_name = "router"
model = "router"
namespace = "default"
metadata = [("seldon", deployment_name), ("namespace", namespace)]
elif platform == "mlserver":
endpoint = "localhost:8081"
model = "router"
metadata = []
data_type = "audio"
workload = [load] * test_duration
# Data 1
ds = load_dataset(
"hf-internal-testing/librispeech_asr_demo", "clean", split="validation"
)
data = ds[0]["audio"]["array"]
data_shape = [len(data)]
custom_parameters = {"custom_1": "test_1"}
data_1 = Data(data=data, data_shape=data_shape, custom_parameters=custom_parameters)
# Data 2
ds = load_dataset(
"hf-internal-testing/librispeech_asr_demo", "clean", split="validation"
)
data = ds[0]["audio"]["array"]
data_shape = [len(data)]
custom_parameters = {"custom_2": "test_2"}
data_2 = Data(data=data, data_shape=data_shape, custom_parameters=custom_parameters)
# Data list
data = []
data.append(data_1)
data.append(data_2)
start_time = time.time()
load_tester = MLServerAsyncGrpc(
endpoint=endpoint,
metadata=metadata,
workload=workload,
model=model,
data=data,
mode=mode, # options - step, equal, exponential
data_type=data_type,
benchmark_duration=1,
)
responses = asyncio.run(load_tester.start())
print(f"{(time.time() - start_time):2.2}s spent in total")
import matplotlib.pyplot as plt
import numpy as np
# Through away initial seconds results
# responses = responses[3:]
# # roundtrip latency
# roundtrip_lat = []
# for sec_resps in responses:
# for resp in sec_resps:
# request_times = resp['times']['request']
# sending_time = request_times['arrival'] - request_times['sending']
# roundtrip_lat.append(sending_time)
# fig, ax = plt.subplots()
# ax.plot(np.arange(len(roundtrip_lat)), roundtrip_lat)
# ax.set(xlabel='request id', ylabel='roundtrip latency (s)', title=f'roundtrip latency, total time={round((time.time() - start_time))}')
# ax.grid()
# fig.savefig(f"grpc-compressed-audio-{platform}_variant_{variant}-roundtrip_lat-load-{load}-test_duration-{test_duration}.png")
# plt.show()
# # sending time
# start_times = []
# for sec_resps in responses:
# for resp in sec_resps:
# times = resp['times']['request']
# sending_time = times['sending'] - start_time
# start_times.append(sending_time)
# fig, ax = plt.subplots()
# ax.plot(np.arange(len(start_times)), start_times)
# ax.set(xlabel='request id', ylabel='sending time (s)', title=f'load tester sending time, total time={round((time.time() - start_time))}')
# ax.grid()
# fig.savefig(f"grpc-compressed-audio-{platform}_variant_{variant}-sending_time-load-{load}-test_duration-{test_duration}.png")
# plt.show()
# # server arrival time
# server_arrival_time = []
# for sec_resps in responses:
# for resp in sec_resps:
# times = resp['times']
# server_recieving_time = times['models'][model]['arrival'] - start_time
# server_arrival_time.append(server_recieving_time)
# fig, ax = plt.subplots()
# ax.plot(np.arange(len(server_arrival_time)), server_arrival_time)
# ax.set(xlabel='request id', ylabel='server arrival time (s)', title=f'Server recieving time of requests, total time={round((time.time() - start_time))}')
# ax.grid()
# fig.savefig(f"grpc-compressed-audio-{platform}_variant_{variant}-server_arrival_time_from_start-load-{load}-test_duration-{test_duration}.png")
# plt.show()
# server arrival latency
# server_arrival_latency = []
# for sec_resps in responses:
# for resp in sec_resps:
# times = resp['times']
# server_recieving_time = times['models'][model]['arrival'] - times['request']['sending']
# server_arrival_latency.append(server_recieving_time)
# fig, ax = plt.subplots()
# ax.plot(np.arange(len(server_arrival_latency)), server_arrival_latency)
# ax.set(xlabel='request id', ylabel='server arrival latency (s)', title=f'Server recieving latency, total time={round((time.time() - start_time))}')
# ax.grid()
# fig.savefig(f"custom-{platform}-load-{load}-test_duration-{test_duration}.png")
# plt.show()
# print(f"{np.average(server_arrival_latency)}=")
# print(responses[0][0])
# print(responses)