-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathbenchmark_http_client_batch.py
executable file
·61 lines (43 loc) · 1.14 KB
/
benchmark_http_client_batch.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
#!/usr/bin/env python
import requests
import time
def main():
benchmark(1)
time.sleep(3)
benchmark(16)
time.sleep(3)
benchmark(128)
time.sleep(3)
benchmark(1024)
time.sleep(3)
benchmark(8192)
time.sleep(3)
benchmark(65536)
time.sleep(3)
benchmark(524288)
time.sleep(3)
benchmark(4194304)
def benchmark(batch_size):
print("Start benchmark for batch size: {}".format(batch_size))
endpoint = "http://127.0.0.1:8500"
batch_data = [1 for i in range(batch_size)]
input_data = {"data": {"keys": [batch_data]}}
if batch_size == 4194304:
start_time = time.time()
for i in range(10):
result = requests.post(endpoint, json=input_data)
end_time = time.time()
elif batch_size == 524288 or batch_size == 65536:
start_time = time.time()
for i in range(100):
result = requests.post(endpoint, json=input_data)
end_time = time.time()
else:
start_time = time.time()
for i in range(1000):
result = requests.post(endpoint, json=input_data)
end_time = time.time()
print("Cost time: {}".format(end_time - start_time))
print(result)
if __name__ == "__main__":
main()