From e31e3884d521570eea2947bd008a41e05a1715cb Mon Sep 17 00:00:00 2001 From: dongdaxiang Date: Sat, 4 Apr 2020 17:03:50 +0800 Subject: [PATCH] make single server to download server bin, and other processes should wait until server bin is available --- python/paddle_serving_server/__init__.py | 1 + python/paddle_serving_server_gpu/__init__.py | 21 ++++++++++++++++--- .../paddle_serving_server_gpu/web_service.py | 15 ++++++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/python/paddle_serving_server/__init__.py b/python/paddle_serving_server/__init__.py index d893861e..08f3febc 100644 --- a/python/paddle_serving_server/__init__.py +++ b/python/paddle_serving_server/__init__.py @@ -211,6 +211,7 @@ class Server(object): tar_name = floder_name + ".tar.gz" bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name self.server_path = os.path.join(self.module_path, floder_name) + if not os.path.exists(self.server_path): print('Frist time run, downloading PaddleServing components ...') r = os.system('wget ' + bin_url + ' --no-check-certificate') diff --git a/python/paddle_serving_server_gpu/__init__.py b/python/paddle_serving_server_gpu/__init__.py index 3dd330b1..abe93a1c 100644 --- a/python/paddle_serving_server_gpu/__init__.py +++ b/python/paddle_serving_server_gpu/__init__.py @@ -20,6 +20,7 @@ import google.protobuf.text_format import tarfile import socket import paddle_serving_server_gpu as paddle_serving_server +import time from .version import serving_server_version from contextlib import closing import argparse @@ -215,11 +216,21 @@ class Server(object): os.chdir(self.module_path) need_download = False device_version = "serving-gpu-" - floder_name = device_version + serving_server_version - tar_name = floder_name + ".tar.gz" + folder_name = device_version + serving_server_version + tar_name = folder_name + ".tar.gz" bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name - self.server_path = os.path.join(self.module_path, floder_name) + self.server_path = os.path.join(self.module_path, folder_name) + + download_flag = "{}/{}.is_download".format(self.module_path, + folder_name) + if os.path.exists(download_flag): + os.chdir(self.cur_path) + self.bin_path = self.server_path + "/serving" + return + if not os.path.exists(self.server_path): + os.system("touch {}/{}.is_download".format(self.module_path, + folder_name)) print('Frist time run, downloading PaddleServing components ...') r = os.system('wget ' + bin_url + ' --no-check-certificate') if r != 0: @@ -318,4 +329,8 @@ class Server(object): self.gpuid,) print("Going to Run Comand") print(command) + # wait for other process to download server bin + while not os.path.exists(self.server_path): + time.sleep(1) + os.system(command) diff --git a/python/paddle_serving_server_gpu/web_service.py b/python/paddle_serving_server_gpu/web_service.py index db0db25d..5d507c94 100755 --- a/python/paddle_serving_server_gpu/web_service.py +++ b/python/paddle_serving_server_gpu/web_service.py @@ -66,6 +66,12 @@ class WebService(object): return server def _launch_rpc_service(self, service_idx): + if service_idx == 0: + self.rpc_service_list[service_idx].check_local_bin() + if not self.rpc_service_list[service_idx].use_local_bin: + self.rpc_service_list[service_idx].download_bin() + else: + time.sleep(3) self.rpc_service_list[service_idx].run_server() def prepare_server(self, workdir="", port=9393, device="gpu", gpuid=0): @@ -160,15 +166,6 @@ class WebService(object): if not isinstance(result, dict) and result == -1: result = {"result": "Request Value Error"} return result - ''' - feed, fetch = self.preprocess(request.json, request.json["fetch"]) - if "fetch" in feed: - del feed["fetch"] - fetch_map = client.predict(feed=feed, fetch=fetch) - fetch_map = self.postprocess( - feed=request.json, fetch=fetch, fetch_map=fetch_map) - return fetch_map - ''' app_instance.run(host="0.0.0.0", port=self.port, -- GitLab