Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
61ed03a0
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
61ed03a0
编写于
4月 22, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
auto find available port
上级
7f5e3af1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
9 deletion
+45
-9
python/paddle_serving_server/__init__.py
python/paddle_serving_server/__init__.py
+1
-0
python/paddle_serving_server/web_service.py
python/paddle_serving_server/web_service.py
+19
-2
python/paddle_serving_server_gpu/web_service.py
python/paddle_serving_server_gpu/web_service.py
+25
-7
未找到文件。
python/paddle_serving_server/__init__.py
浏览文件 @
61ed03a0
...
...
@@ -260,6 +260,7 @@ class Server(object):
self
.
_prepare_resource
(
workdir
)
self
.
_prepare_engine
(
self
.
model_config_path
,
device
)
self
.
_prepare_infer_service
(
port
)
self
.
port
=
port
self
.
workdir
=
workdir
infer_service_fn
=
"{}/{}"
.
format
(
workdir
,
self
.
infer_service_fn
)
...
...
python/paddle_serving_server/web_service.py
浏览文件 @
61ed03a0
...
...
@@ -18,6 +18,8 @@ from flask import Flask, request, abort
from
multiprocessing
import
Pool
,
Process
from
paddle_serving_server
import
OpMaker
,
OpSeqMaker
,
Server
from
paddle_serving_client
import
Client
from
contextlib
import
closing
import
socket
class
WebService
(
object
):
...
...
@@ -41,19 +43,34 @@ class WebService(object):
server
.
set_num_threads
(
16
)
server
.
load_model_config
(
self
.
model_config
)
server
.
prepare_server
(
workdir
=
self
.
workdir
,
port
=
self
.
port
+
1
,
device
=
self
.
device
)
workdir
=
self
.
workdir
,
port
=
self
.
port
_list
[
0
]
,
device
=
self
.
device
)
server
.
run_server
()
def
port_is_available
(
self
,
port
):
with
closing
(
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
))
as
sock
:
sock
.
settimeout
(
2
)
result
=
sock
.
connect_ex
((
'0.0.0.0'
,
port
))
if
result
!=
0
:
return
True
else
:
return
False
def
prepare_server
(
self
,
workdir
=
""
,
port
=
9393
,
device
=
"cpu"
):
self
.
workdir
=
workdir
self
.
port
=
port
self
.
device
=
device
default_port
=
6000
self
.
port_list
=
[]
for
i
in
range
(
1000
):
if
self
.
port_is_available
(
default_port
+
i
):
self
.
port_list
.
append
(
default_port
+
i
)
break
def
_launch_web_service
(
self
):
self
.
client_service
=
Client
()
self
.
client_service
.
load_client_config
(
"{}/serving_server_conf.prototxt"
.
format
(
self
.
model_config
))
self
.
client_service
.
connect
([
"0.0.0.0:{}"
.
format
(
self
.
port
+
1
)])
self
.
client_service
.
connect
([
"0.0.0.0:{}"
.
format
(
self
.
port
_list
[
0
]
)])
def
get_prediction
(
self
,
request
):
if
not
request
.
json
:
...
...
python/paddle_serving_server_gpu/web_service.py
浏览文件 @
61ed03a0
...
...
@@ -13,14 +13,15 @@
# limitations under the License.
from
flask
import
Flask
,
request
,
abort
from
paddle_serving_server_gpu
import
OpMaker
,
OpSeqMaker
,
Server
import
paddle_serving_server_gpu
as
serving
from
contextlib
import
closing
from
multiprocessing
import
Pool
,
Process
,
Queue
from
paddle_serving_client
import
Client
from
paddle_serving_server_gpu
import
OpMaker
,
OpSeqMaker
,
Server
from
paddle_serving_server_gpu.serve
import
start_multi_card
import
socket
import
sys
import
numpy
as
np
import
paddle_serving_server_gpu
as
serving
class
WebService
(
object
):
...
...
@@ -66,22 +67,39 @@ class WebService(object):
def
_launch_rpc_service
(
self
,
service_idx
):
self
.
rpc_service_list
[
service_idx
].
run_server
()
def
port_is_available
(
self
,
port
):
with
closing
(
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
))
as
sock
:
sock
.
settimeout
(
2
)
result
=
sock
.
connect_ex
((
'0.0.0.0'
,
port
))
if
result
!=
0
:
return
True
else
:
return
False
def
prepare_server
(
self
,
workdir
=
""
,
port
=
9393
,
device
=
"gpu"
,
gpuid
=
0
):
self
.
workdir
=
workdir
self
.
port
=
port
self
.
device
=
device
self
.
gpuid
=
gpuid
self
.
port_list
=
[]
default_port
=
6000
for
i
in
range
(
1000
):
if
self
.
port_is_available
(
default_port
+
i
):
self
.
port_list
.
append
(
default_port
+
i
)
if
len
(
self
.
port_list
)
>
len
(
self
.
gpus
):
break
if
len
(
self
.
gpus
)
==
0
:
# init cpu service
self
.
rpc_service_list
.
append
(
self
.
default_rpc_service
(
self
.
workdir
,
self
.
port
+
1
,
-
1
,
thread_num
=
10
))
self
.
workdir
,
self
.
port
_list
[
0
]
,
-
1
,
thread_num
=
10
))
else
:
for
i
,
gpuid
in
enumerate
(
self
.
gpus
):
self
.
rpc_service_list
.
append
(
self
.
default_rpc_service
(
"{}_{}"
.
format
(
self
.
workdir
,
i
),
self
.
port
+
1
+
i
,
self
.
port
_list
[
i
]
,
gpuid
,
thread_num
=
10
))
...
...
@@ -93,9 +111,9 @@ class WebService(object):
endpoints
=
""
if
gpu_num
>
0
:
for
i
in
range
(
gpu_num
):
endpoints
+=
"127.0.0.1:{},"
.
format
(
self
.
port
+
i
+
1
)
endpoints
+=
"127.0.0.1:{},"
.
format
(
self
.
port
_list
[
i
]
)
else
:
endpoints
=
"127.0.0.1:{}"
.
format
(
self
.
port
+
1
)
endpoints
=
"127.0.0.1:{}"
.
format
(
self
.
port
_list
[
0
]
)
self
.
client
.
connect
([
endpoints
])
def
get_prediction
(
self
,
request
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录