Skip to content

Commit 2f99216

Browse files
committed
Add benchmark clients for tempalte and simplest models
1 parent 6985567 commit 2f99216

File tree

3 files changed

+69
-32
lines changed

3 files changed

+69
-32
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
3+
import time
4+
import requests
5+
6+
def main():
7+
endpoint = "http://127.0.0.1:8500"
8+
json_data = {"model_name": "default", "data": {"keys": [1, 1]} }
9+
10+
iteration = 1000
11+
start_time = time.time()
12+
13+
for i in range(iteration):
14+
result = requests.post(endpoint, json=json_data)
15+
16+
end_time = time.time()
17+
print(result.json())
18+
19+
print("Benchmark iteration: {}, time: {}".format(iteration, end_time - start_time))
20+
21+
22+
if __name__ == "__main__":
23+
main()
24+
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
import time
4+
import requests
5+
6+
def main():
7+
endpoint = "http://127.0.0.1:8500"
8+
json_data = {"model_name": "default", "data": {"keys": [[1], [1]], "features": [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]} }
9+
10+
iteration = 1000
11+
start_time = time.time()
12+
13+
for i in range(iteration):
14+
result = requests.post(endpoint, json=json_data)
15+
16+
end_time = time.time()
17+
print(result.json())
18+
19+
print("Benchmark iteration: {}, time: {}".format(iteration, end_time - start_time))
20+
21+
if __name__ == "__main__":
22+
main()
23+

simple_tensorflow_serving/server.py

+22-32
Original file line numberDiff line numberDiff line change
@@ -37,77 +37,75 @@
3737
# TODO: Remove if it does not need gunicorn
3838
parser.add_argument(
3939
"--bind",
40-
default="0.0.0.0:8500",
40+
default=os.environ.get("STFS_BIND", "0.0.0.0:8500"),
4141
help="Bind address of the server(eg. 0.0.0.0:8500)")
4242
parser.add_argument(
43-
"--host", default="0.0.0.0", help="The host of the server(eg. 0.0.0.0)")
43+
"--host", default=os.environ.get("STFS_HOST", "0.0.0.0"), help="The host of the server(eg. 0.0.0.0)")
4444
parser.add_argument(
45-
"--port", default=8500, help="The port of the server(eg. 8500)", type=int)
45+
"--port", default=int(os.environ.get("STFS_PORT", "8500")), help="The port of the server(eg. 8500)", type=int)
4646
parser.add_argument(
47-
"--enable_ssl", default=False, help="If enable RESTfull API over https")
47+
"--enable_ssl", default=bool(os.environ.get("STFS_ENABLE_SSL", "")), help="If enable RESTfull API over https")
4848
parser.add_argument(
49-
"--secret_pem", default="secret.pem", help="pem file")
49+
"--secret_pem", default=os.environ.get("STFS_SECRET_PEM", "secret.pem"), help="SSL pem file")
5050
parser.add_argument(
51-
"--secret_key", default="secret.key", help="key file")
51+
"--secret_key", default=os.environ.get("STFS_SECRET_KEY", "secret.key"), help="SSL key file")
5252
parser.add_argument(
5353
"--model_name",
54-
default="default",
54+
default=os.environ.get("STFS_MODEL_NAME", "default"),
5555
help="The name of the model(eg. default)")
5656
parser.add_argument(
5757
"--model_base_path",
58-
default="./model",
58+
default=os.environ.get("STFS_MODEL_BASE_PATH", "./model"),
5959
help="The file path of the model(eg. 8500)")
6060
parser.add_argument(
6161
"--model_platform",
62-
default="tensorflow",
62+
default=os.environ.get("STFS_MODEL_PLATFORM", "tensorflow"),
6363
help="The platform of model(eg. tensorflow)")
6464
parser.add_argument(
6565
"--model_config_file",
66-
default="",
66+
default=os.environ.get("STFS_MODEL_CONFIG_FILE", ""),
6767
help="The file of the model config(eg. '')")
6868
# TODO: type=bool not works, make it true by default if fixing exit bug
6969
parser.add_argument(
70-
"--reload_models", default="False", help="Reload models or not(eg. True)")
70+
"--reload_models", default=os.environ.get("STFS_RELOAD_MODELS", ""), help="Reload models or not(eg. True)")
7171
parser.add_argument(
7272
"--custom_op_paths",
73-
default="",
73+
default=os.environ.get("STFS_CUSTOM_OP_PATHS", ""),
7474
help="The path of custom op so files(eg. ./)")
7575
parser.add_argument(
76-
"--session_config", default="{}", help="The json of session config")
76+
"--session_config", default=os.environ.get("STFS_SESSION_CONFIG", "{}"), help="The json of session config")
7777
parser.add_argument(
7878
"--debug",
79-
default=False,
79+
default=os.environ.get("STFS_DEBUG", ""),
8080
help="Enable debug for flask or not(eg. False)",
8181
type=bool)
8282
parser.add_argument(
83-
"--log_level", default="info", help="The log level(eg. info)")
84-
parser.add_argument(
85-
"--gen_client", default="", help="Generate the client code(eg. python)")
83+
"--log_level", default=os.environ.get("STFS_LOG_LEVEL", "info"), help="The log level(eg. info)")
8684
parser.add_argument(
8785
"--enable_auth",
88-
default=False,
86+
default=os.environ.get("STFS_ENABLE_AUTH", ""),
8987
help="Enable basic auth or not(eg. False)",
9088
type=bool)
9189
parser.add_argument(
9290
"--auth_username",
93-
default="admin",
91+
default=os.environ.get("STFS_AUTH_USERNAME", "admin"),
9492
help="The username of basic auth(eg. admin)")
9593
parser.add_argument(
9694
"--auth_password",
97-
default="admin",
95+
default=os.environ.get("STFS_AUTH_PASSWORD", "admin"),
9896
help="The password of basic auth(eg. admin)")
9997
parser.add_argument(
10098
"--enable_colored_log",
101-
default=False,
99+
default=os.environ.get("STFS_ENABLE_COLORED_LOG", ""),
102100
help="Enable colored log(eg. False)",
103101
type=bool)
104102
parser.add_argument(
105-
"--enable_cors", default=True, help="Enable cors(eg. True)", type=bool)
103+
"--enable_cors", default=os.environ.get("STFS_ENABLE_CORS", "True"), help="Enable cors(eg. True)", type=bool)
106104
parser.add_argument(
107-
"--enable_b64_autoconvert", default=False, help="Enable auto convert b64 string(eg. False)", type=bool)
105+
"--enable_b64_autoconvert", default=os.environ.get("STFS_B64_AUTOCONVERT", ""), help="Enable auto convert b64 string(eg. False)", type=bool)
108106
parser.add_argument(
109107
"--download_inference_images",
110-
default=True,
108+
default=os.environ.get("STFS_DOWNLOAD_INFERENCE_IMAGES", "True"),
111109
help="Download inference images(eg. True)",
112110
type=bool)
113111

@@ -279,14 +277,6 @@ def decorated(*decorator_args, **decorator_kwargs):
279277

280278
model_name_service_map[args.model_name] = inference_service
281279

282-
# TODO(Deprecated): Generate client code and exit or not
283-
if args.gen_client != "":
284-
if args.model_platform == "tensorflow":
285-
inference_service = model_name_service_map[args.model_name]
286-
gen_client.gen_tensorflow_client(inference_service, args.gen_client,
287-
args.model_name)
288-
289-
sys.exit(0)
290280

291281
# Start thread to periodically reload models or not
292282
if args.reload_models == "True" or args.reload_models == "true":

0 commit comments

Comments
 (0)