Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
8e7ef675
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看板
提交
8e7ef675
编写于
5月 06, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add grpc
上级
4087909e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
5 deletion
+56
-5
python/examples/imdb/test_py_server.py
python/examples/imdb/test_py_server.py
+1
-0
python/paddle_serving_server/pserving.py
python/paddle_serving_server/pserving.py
+55
-5
未找到文件。
python/examples/imdb/test_py_server.py
浏览文件 @
8e7ef675
...
@@ -57,4 +57,5 @@ pyserver.add_cnannel(combine_out_channel)
...
@@ -57,4 +57,5 @@ pyserver.add_cnannel(combine_out_channel)
pyserver
.
add_op
(
cnn_op
)
pyserver
.
add_op
(
cnn_op
)
pyserver
.
add_op
(
bow_op
)
pyserver
.
add_op
(
bow_op
)
pyserver
.
add_op
(
combine_op
)
pyserver
.
add_op
(
combine_op
)
pyserver
.
prepare_server
(
port
=
8080
,
worker_num
=
4
)
pyserver
.
run_server
()
pyserver
.
run_server
()
python/paddle_serving_server/pserving.py
浏览文件 @
8e7ef675
...
@@ -18,6 +18,7 @@ import queue
...
@@ -18,6 +18,7 @@ import queue
import
os
import
os
import
paddle_serving_server
import
paddle_serving_server
from
paddle_serving_client
import
Client
from
paddle_serving_client
import
Client
from
concurrent
import
futures
import
grpc
import
grpc
import
general_python_service_pb2
import
general_python_service_pb2
import
general_python_service_pb2_grpc
import
general_python_service_pb2_grpc
...
@@ -82,11 +83,20 @@ class Op(object):
...
@@ -82,11 +83,20 @@ class Op(object):
self
.
_client
.
connect
([
server_name
])
self
.
_client
.
connect
([
server_name
])
self
.
_fetch_names
=
fetch_names
self
.
_fetch_names
=
fetch_names
def
with_serving
(
self
):
return
self
.
_client
is
not
None
def
get_inputs
(
self
):
return
self
.
_inputs
def
set_inputs
(
self
,
channels
):
def
set_inputs
(
self
,
channels
):
if
not
isinstance
(
channels
,
list
):
if
not
isinstance
(
channels
,
list
):
raise
TypeError
(
'channels must be list type'
)
raise
TypeError
(
'channels must be list type'
)
self
.
_inputs
=
channels
self
.
_inputs
=
channels
def
get_outputs
(
self
):
return
self
.
_outputs
def
set_outputs
(
self
,
channels
):
def
set_outputs
(
self
,
channels
):
if
not
isinstance
(
channels
,
list
):
if
not
isinstance
(
channels
,
list
):
raise
TypeError
(
'channels must be list type'
)
raise
TypeError
(
'channels must be list type'
)
...
@@ -114,7 +124,7 @@ class Op(object):
...
@@ -114,7 +124,7 @@ class Op(object):
input_data
.
append
(
channel
.
front
())
input_data
.
append
(
channel
.
front
())
data
=
self
.
preprocess
(
input_data
)
data
=
self
.
preprocess
(
input_data
)
if
self
.
_client
is
not
None
:
if
self
.
with_serving
()
:
fetch_map
=
self
.
midprocess
(
data
)
fetch_map
=
self
.
midprocess
(
data
)
output_data
=
self
.
postprocess
(
fetch_map
)
output_data
=
self
.
postprocess
(
fetch_map
)
else
:
else
:
...
@@ -124,11 +134,25 @@ class Op(object):
...
@@ -124,11 +134,25 @@ class Op(object):
channel
.
push
(
output_data
)
channel
.
push
(
output_data
)
class
GeneralPythonService
(
general_python_service_pb2_grpc
.
GeneralPythonService
):
def
__init__
(
self
,
channel
):
self
.
_channel
=
channel
def
Request
(
self
,
request
,
context
):
pass
def
Response
(
self
,
request
,
context
):
pass
class
PyServer
(
object
):
class
PyServer
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
_channels
=
[]
self
.
_channels
=
[]
self
.
_ops
=
[]
self
.
_ops
=
[]
self
.
_op_threads
=
[]
self
.
_op_threads
=
[]
self
.
_port
=
None
self
.
_worker_num
=
None
def
add_channel
(
self
,
channel
):
def
add_channel
(
self
,
channel
):
self
.
_channels
.
append
(
channel
)
self
.
_channels
.
append
(
channel
)
...
@@ -139,16 +163,42 @@ class PyServer(object):
...
@@ -139,16 +163,42 @@ class PyServer(object):
def
gen_desc
(
self
):
def
gen_desc
(
self
):
pass
pass
def
prepare_server
(
self
,
port
,
worker_num
):
self
.
_port
=
port
self
.
_worker_num
=
worker_num
self
.
gen_desc
()
def
run_server
(
self
):
def
run_server
(
self
):
inputs
=
[]
outputs
=
[]
for
op
in
self
.
_ops
:
for
op
in
self
.
_ops
:
self
.
prepare_server
(
op
)
inputs
+=
op
.
get_inputs
()
outputs
+=
op
.
get_outputs
()
if
op
.
with_serving
():
self
.
prepare_serving
(
op
)
th
=
multiprocessing
.
Process
(
target
=
op
.
start
,
args
=
(
op
,
))
th
=
multiprocessing
.
Process
(
target
=
op
.
start
,
args
=
(
op
,
))
th
.
start
()
th
.
start
()
self
.
_op_threads
.
append
(
th
)
self
.
_op_threads
.
append
(
th
)
for
th
in
self
.
_op_threads
:
th
.
join
()
def
prepare_server
(
self
,
op
):
input_channel
=
[]
for
channel
in
inputs
:
if
channel
not
in
outputs
:
input_channel
.
append
(
channel
)
if
len
(
input_channel
)
!=
1
:
raise
Exception
(
"input_channel more than 1 or no input_channel"
)
server
=
grpc
.
server
(
futures
.
ThreadPoolExecutor
(
max_workers
=
self
.
_worker_num
))
general_python_service_pb2_grpc
.
add_GeneralPythonService_to_server
(
GeneralPythonService
(
input_channel
[
0
]),
server
)
server
.
start
()
try
:
for
th
in
self
.
_op_threads
:
th
.
join
()
except
KeyboardInterrupt
:
server
.
stop
(
0
)
def
prepare_serving
(
self
,
op
):
model_path
=
op
.
_server_model
model_path
=
op
.
_server_model
port
=
op
.
_server_port
port
=
op
.
_server_port
device
=
op
.
_device
device
=
op
.
_device
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录