-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathnumpy.py
More file actions
executable file
·150 lines (111 loc) · 3.27 KB
/
Copy pathnumpy.py
File metadata and controls
executable file
·150 lines (111 loc) · 3.27 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
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
140
141
142
143
144
145
146
147
148
#! /usr/bin/python3
from time import time, sleep
from subprocess import Popen, call
from tempfile import mkdtemp
import os
import copy
import json
import requests
def post(path, data=None):
return requests.post('http://localhost:5000/'+path, json.dumps(data))
ARG_SIZE=10000
arg = [[x for x in range(ARG_SIZE)] for _ in range(1)]
WASM=True
DOCKER=True
MANY=1000
OLDIR=os.path.abspath("./test-dir")
OL_REGISTRY=os.path.abspath("./test-registry")
if WASM:
print("# WASM")
print("Single")
p = Popen(["./ol-wasm"])
sleep(0.1)
start = time()
post("run/numpy", arg)
end = time()
elapsed = end - start
print("Elapsed: %f s" % (elapsed))
p.kill()
print("Many (cold)")
p = Popen(["./ol-wasm"])
sleep(0.1)
start = time()
for _ in range(MANY):
post("run/numpy", arg)
end = time()
elapsed = end - start
print("Elapsed: %fs (%fs per request)" % (elapsed, elapsed/MANY))
p.kill()
print("Many (warm)")
p = Popen(["./ol-wasm"])
sleep(0.1)
post("run/numpy", arg)
start = time()
for _ in range(MANY):
post("run/numpy", arg)
end = time()
elapsed = end - start
print("Elapsed: %fs (%fs per request)" % (elapsed, elapsed/MANY))
p.kill()
if DOCKER:
def put_conf(conf):
global curr_conf
with open(os.path.join(OLDIR, "config.json"), "w") as f:
json.dump(conf, f, indent=2)
curr_conf = conf
def update_config(**keywords):
with open(os.path.join(OLDIR, "config.json")) as f:
orig = json.load(f)
new = copy.deepcopy(orig)
for k in keywords:
if not k in new:
raise Exception("unknown config param: %s" % k)
if type(keywords[k]) == dict:
for k2 in keywords[k]:
new[k][k2] = keywords[k][k2]
else:
new[k] = keywords[k]
put_conf(new)
print("# DOCKER")
call(["./ol", "kill"])
print("Single")
d = "./test-dir/"# mkdtemp()+"/ol/"
call(["./ol", "new", "-p="+d])
update_config(registry=OL_REGISTRY)
call(["./ol", "worker", "-p="+d, "--detach"])
sleep(0.1)
start = time()
r = post("run/numpy16", arg)
end = time()
if r.status_code != 200:
raise Exception("STATUS %d: %s" % (r.status_code, r.text))
elapsed = end - start
print("Elapsed: %f s" % (elapsed))
call(["./ol", "kill"])
print("Many (cold)")
d = "./test-dir/"# mkdtemp()+"/ol"
call(["./ol", "new", "-p="+d])
update_config(registry=OL_REGISTRY)
p = Popen(["./ol", "worker", "--detach", "-p="+d])
sleep(0.1)
start = time()
for _ in range(MANY):
post("run/numpy16", arg)
end = time()
elapsed = end - start
print("Elapsed: %fs (%fs per req)" % (elapsed, elapsed/MANY))
call(["./ol", "kill"])
print("Many (warm)")
d = "./test-dir/"# mkdtemp()+"/ol"
call(["./ol", "new", "-p="+d])
update_config(registry=OL_REGISTRY)
p = Popen(["./ol", "worker", "--detach", "-p="+d])
sleep(0.1)
post("run/numpy16", arg)
start = time()
for _ in range(MANY):
post("run/numpy16", arg)
end = time()
elapsed = end - start
print("Elapsed: %fs (%fs per req)" % (elapsed, elapsed/MANY))
call(["./ol", "kill"])