-
Notifications
You must be signed in to change notification settings - Fork 191
/
Copy pathbenchmark_http_client.py
executable file
·41 lines (28 loc) · 1 KB
/
benchmark_http_client.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
#!/usr/bin/env python
import requests
import time
def main():
benchmark("simple_tensorflow_serving_flask")
time.sleep(3)
benchmark("simple_tensorflow_serving_uwsgi")
time.sleep(3)
benchmark("tensorflow_serving_restful")
def benchmark(benchmark_type):
print("Start benchmark for {}".format(benchmark_type))
if benchmark_type == "simple_tensorflow_serving_flask":
endpoint = "http://127.0.0.1:8500"
input_data = {"data": {"keys": [[1]]}}
elif benchmark_type == "simple_tensorflow_serving_uwsgi":
endpoint = "http://127.0.0.1:8501"
input_data = {"data": {"keys": [[1]]}}
elif benchmark_type == "tensorflow_serving_restful":
endpoint = "http://127.0.0.1:8503/v1/models/default/versions/1:predict"
input_data = {"instances": [{"keys": 1}]}
start_time = time.time()
for i in range(100):
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()