Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
756cf163
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看板
提交
756cf163
编写于
3月 14, 2021
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix benchmark
上级
4da842a9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
31 deletion
+52
-31
python/examples/pipeline/simple_web_service/benchmark.py
python/examples/pipeline/simple_web_service/benchmark.py
+14
-11
python/examples/pipeline/simple_web_service/benchmark.sh
python/examples/pipeline/simple_web_service/benchmark.sh
+31
-5
python/examples/pipeline/simple_web_service/web_service.py
python/examples/pipeline/simple_web_service/web_service.py
+7
-15
未找到文件。
python/examples/pipeline/simple_web_service/benchmark.py
浏览文件 @
756cf163
...
...
@@ -24,7 +24,9 @@ def run_http(idx, batch_size):
print
(
"start thread ({})"
.
format
(
idx
))
url
=
"http://127.0.0.1:18082/uci/prediction"
start
=
time
.
time
()
data
=
{
"key"
:
[
"x"
],
"value"
:
[
"0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332"
]}
value
=
"0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332"
all_value
=
";"
.
join
([
value
for
i
in
range
(
batch_size
)])
data
=
{
"key"
:
[
"x"
],
"value"
:
[
all_value
]}
for
i
in
range
(
1000
):
r
=
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data
))
print
(
r
.
json
())
...
...
@@ -33,21 +35,22 @@ def run_http(idx, batch_size):
def
multithread_http
(
thread
,
batch_size
):
multi_thread_runner
=
MultiThreadRunner
()
result
=
multi_thread_runner
.
run
(
run_http
,
thread
,
batch_size
)
def
multithread_rpc
(
thraed
,
batch_size
):
multi_thread_runner
=
MultiThreadRunner
()
result
=
multi_thread_runner
.
run
(
run_http
,
thread
,
batch_size
)
def
run_rpc
(
thread
,
batch_size
):
client
=
PipelineClient
()
client
.
connect
([
'127.0.0.1:9998'
])
data
=
{
"key"
:
"x"
,
"value"
:
"0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332"
}
ret
=
client
.
predict
(
feed_dict
=
{
data
[
"key"
]:
data
[
"value"
]},
fetch
=
[
"res"
])
value
=
"0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332"
all_value
=
";"
.
join
([
value
for
i
in
range
(
batch_size
)])
data
=
{
"key"
:
"x"
,
"value"
:
all_value
}
for
i
in
range
(
1000
):
ret
=
client
.
predict
(
feed_dict
=
{
data
[
"key"
]:
data
[
"value"
]},
fetch
=
[
"res"
])
print
(
ret
)
def
multithread_rpc
(
thraed
,
batch_size
):
multi_thread_runner
=
MultiThreadRunner
()
result
=
multi_thread_runner
.
run
(
run_rpc
,
thread
,
batch_size
)
if
__name__
==
"__main__"
:
if
sys
.
argv
[
1
]
==
"yaml"
:
mode
=
sys
.
argv
[
2
]
# brpc/ local predictor
...
...
@@ -60,6 +63,6 @@ if __name__ == "__main__":
if
mode
==
"http"
:
multithread_http
(
thread
,
batch_size
)
elif
mode
==
"rpc"
:
run
_rpc
(
thread
,
batch_size
)
multithread
_rpc
(
thread
,
batch_size
)
python/examples/pipeline/simple_web_service/benchmark.sh
浏览文件 @
756cf163
# HTTP
ps
-ef
|
grep
web_service |
awk
'{print $2}'
| xargs
kill
-9
rm
-rf
PipelineServingLogs
rm
-rf
cpu_utilization.py
sleep
3
python3 benchmark.py yaml local_predictor 1
for
thread_num
in
1 8 32
for
thread_num
in
1
do
for
batch_size
in
1
do
rm
-rf
PipelineServingLogs
rm
-rf
cpu_utilization.py
python3 web_service.py
>
web.log 2>&1 &
sleep
3
echo
"import psutil
\n
cpu_utilization=psutil.cpu_percent(1,False)
\n
print('CPU_UTILIZATION:', cpu_utilization)
\n
"
>
cpu_utilization.py
python3 benchmark.py run http
$thread_num
1
python3 benchmark.py run http
$thread_num
$batch_size
python3 cpu_utilization.py
echo
"------------Fit a line pipeline benchmark (Thread:
$thread_num
) (B
enchmark: 1
)"
echo
"------------Fit a line pipeline benchmark (Thread:
$thread_num
) (B
atchSize:
$batch_size
)"
tail
-n
25 PipelineServingLogs/pipeline.tracer
ps
-ef
|
grep
web_service |
awk
'{print $2}'
| xargs
kill
-9
done
done
# RPC
ps
-ef
|
grep
web_service |
awk
'{print $2}'
| xargs
kill
-9
sleep
3
python3 benchmark.py yaml local_predictor 1
for
thread_num
in
1
do
for
batch_size
in
1
do
rm
-rf
PipelineServingLogs
rm
-rf
cpu_utilization.py
python3 web_service.py
>
web.log 2>&1 &
sleep
3
echo
"import psutil
\n
cpu_utilization=psutil.cpu_percent(1,False)
\n
print('CPU_UTILIZATION:', cpu_utilization)
\n
"
>
cpu_utilization.py
python3 benchmark.py run rpc
$thread_num
$batch_size
python3 cpu_utilization.py
echo
"------------Fit a line pipeline benchmark (Thread:
$thread_num
) (BatchSize:
$batch_size
)"
tail
-n
25 PipelineServingLogs/pipeline.tracer
ps
-ef
|
grep
web_service |
awk
'{print $2}'
| xargs
kill
-9
done
done
python/examples/pipeline/simple_web_service/web_service.py
浏览文件 @
756cf163
...
...
@@ -25,32 +25,24 @@ _LOGGER = logging.getLogger()
class
UciOp
(
Op
):
def
init_op
(
self
):
self
.
separator
=
","
self
.
batch_separator
=
";"
def
preprocess
(
self
,
input_dicts
,
data_id
,
log_id
):
(
_
,
input_dict
),
=
input_dicts
.
items
()
_LOGGER
.
error
(
"UciOp::preprocess >>> log_id:{}, input:{}"
.
format
(
log_id
,
input_dict
))
x_value
=
input_dict
[
"x"
]
x_value
=
input_dict
[
"x"
].
split
(
self
.
batch_separator
)
x_lst
=
[]
for
x_val
in
x_value
:
x_lst
.
append
(
np
.
array
([
float
(
x
.
strip
())
for
x
in
x_val
.
split
(
self
.
separator
)]).
reshape
(
1
,
13
))
input_dict
[
"x"
]
=
np
.
concatenate
(
x_lst
,
axis
=
0
)
proc_dict
=
{}
if
sys
.
version_info
.
major
==
2
:
if
isinstance
(
x_value
,
(
str
,
unicode
)):
input_dict
[
"x"
]
=
np
.
array
(
[
float
(
x
.
strip
())
for
x
in
x_value
.
split
(
self
.
separator
)]).
reshape
(
1
,
13
)
_LOGGER
.
error
(
"input_dict:{}"
.
format
(
input_dict
))
else
:
if
isinstance
(
x_value
,
str
):
input_dict
[
"x"
]
=
np
.
array
(
[
float
(
x
.
strip
())
for
x
in
x_value
.
split
(
self
.
separator
)]).
reshape
(
1
,
13
)
_LOGGER
.
error
(
"input_dict:{}"
.
format
(
input_dict
))
return
input_dict
,
False
,
None
,
""
def
postprocess
(
self
,
input_dicts
,
fetch_dict
,
log_id
):
_LOGGER
.
info
(
"UciOp::postprocess >>> log_id:{}, fetch_dict:{}"
.
format
(
log_id
,
fetch_dict
))
fetch_dict
[
"price"
]
=
str
(
fetch_dict
[
"price"
]
[
0
][
0
]
)
fetch_dict
[
"price"
]
=
str
(
fetch_dict
[
"price"
])
return
fetch_dict
,
None
,
""
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录