forked from ucbrise/clipper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_client.py
More file actions
61 lines (54 loc) · 1.87 KB
/
example_client.py
File metadata and controls
61 lines (54 loc) · 1.87 KB
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
from __future__ import print_function
import json
import requests
from datetime import datetime
import time
import numpy as np
def update(host, uid, x, y):
url = "http://%s:1337/example_app/update" % host
req_json = json.dumps({
'uid': uid,
'input': list(x),
'label': float(y),
'model_name': 'example_model',
'model_version': 1
})
headers = {'Content-type': 'application/json'}
start = datetime.now()
r = requests.post(url, headers=headers, data=req_json)
end = datetime.now()
latency = (end - start).total_seconds() * 1000.0
print("'%s', %f ms" % (r.text, latency))
def predict(host, uid, x):
url = "http://%s:1337/example_app/predict" % host
req_json = json.dumps({'uid': uid, 'input': list(x)})
headers = {'Content-type': 'application/json'}
start = datetime.now()
r = requests.post(url, headers=headers, data=req_json)
end = datetime.now()
latency = (end - start).total_seconds() * 1000.0
print("'%s', %f ms" % (r.text, latency))
def add_mnist_app(host):
url = "http://%s:1338/admin/add_app" % host
req_json = json.dumps({
"name": "example_app",
"candidate_models": [{"model_name": "example_model", "model_version": 1}],
"input_type": "doubles",
"output_type": "double",
"selection_policy": "simple_policy",
"latency_slo_micros": 20000
})
headers = {'Content-type': 'application/json'}
start = datetime.now()
r = requests.post(url, headers=headers, data=req_json)
end = datetime.now()
latency = (end - start).total_seconds() * 1000.0
print("'%s', %f ms" % (r.text, latency))
if __name__ == '__main__':
add_mnist_app("localhost")
time.sleep(1.0)
uid = 4
while True:
# mnist_update(uid, x[example_num], float(y[example_num]))
predict("localhost", uid, np.random.random(1000))
time.sleep(0.2)