Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
2c7d8f56
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看板
提交
2c7d8f56
编写于
8月 06, 2020
作者:
B
barriery
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add id-generator into util module
上级
3c500fa3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
13 deletion
+71
-13
python/pipeline/dag.py
python/pipeline/dag.py
+5
-11
python/pipeline/util.py
python/pipeline/util.py
+66
-2
未找到文件。
python/pipeline/dag.py
浏览文件 @
2c7d8f56
...
...
@@ -29,7 +29,7 @@ from .operator import Op, RequestOp, ResponseOp, VirtualOp
from
.channel
import
(
ThreadChannel
,
ProcessChannel
,
ChannelData
,
ChannelDataEcode
,
ChannelDataType
,
ChannelStopError
)
from
.profiler
import
TimeProfiler
,
PerformanceTracer
from
.util
import
NameGenerator
from
.util
import
NameGenerator
,
ThreadIdGenerator
from
.proto
import
pipeline_service_pb2
_LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -74,9 +74,9 @@ class DAGExecutor(object):
if
self
.
_tracer
is
not
None
:
self
.
_tracer
.
start
()
self
.
_id_
lock
=
threading
.
Lock
()
self
.
_id_counter
=
0
self
.
_reset_max_id
=
1000000000000000000
self
.
_id_
generator
=
ThreadIdGenerator
(
max_id
=
1000000000000000000
,
base_counter
=
0
,
step
=
1
)
self
.
_cv_pool
=
{}
self
.
_cv_for_cv_pool
=
threading
.
Condition
()
self
.
_fetch_buffer
=
{}
...
...
@@ -98,13 +98,7 @@ class DAGExecutor(object):
_LOGGER
.
info
(
"[DAG Executor] Stop"
)
def
_get_next_data_id
(
self
):
data_id
=
None
with
self
.
_id_lock
:
if
self
.
_id_counter
>=
self
.
_reset_max_id
:
_LOGGER
.
info
(
"[DAG Executor] Reset request id"
)
self
.
_id_counter
-=
self
.
_reset_max_id
data_id
=
self
.
_id_counter
self
.
_id_counter
+=
1
data_id
=
self
.
_id_generator
.
next
()
cond_v
=
threading
.
Condition
()
with
self
.
_cv_for_cv_pool
:
self
.
_cv_pool
[
data_id
]
=
cond_v
...
...
python/pipeline/util.py
浏览文件 @
2c7d8f56
...
...
@@ -13,13 +13,77 @@
# limitations under the License.
import
sys
import
logging
import
threading
import
multiprocessing
_LOGGER
=
logging
.
getLogger
(
__name__
)
class
NameGenerator
(
object
):
# use unsafe-id-generator
def
__init__
(
self
,
prefix
):
self
.
_idx
=
-
1
self
.
_prefix
=
prefix
self
.
_id_generator
=
UnsafeIdGenerator
(
1000000000000000000
)
def
next
(
self
):
next_id
=
self
.
_id_generator
.
next
()
return
"{}{}"
.
format
(
self
.
_prefix
,
next_id
)
class
UnsafeIdGenerator
(
object
):
def
__init__
(
self
,
max_id
,
base_counter
=
0
,
step
=
1
):
self
.
_base_counter
=
base_counter
self
.
_counter
=
self
.
_base_counter
self
.
_step
=
step
self
.
_max_id
=
max_id
# for reset
def
next
(
self
):
if
self
.
_counter
>=
self
.
_max_id
:
self
.
_counter
=
self
.
_base_counter
_LOGGER
.
info
(
"Reset Id: {}"
.
format
(
self
.
_counter
))
next_id
=
self
.
_counter
self
.
_counter
+=
self
.
_step
return
next_id
class
ThreadIdGenerator
(
UnsafeIdGenerator
):
def
__init__
(
self
,
max_id
,
base_counter
=
0
,
step
=
1
,
lock
=
None
):
# if you want to use your lock, you may need to use Reentrant-Lock
self
.
_lock
=
lock
if
self
.
_lock
is
None
:
self
.
_lock
=
threading
.
Lock
()
super
(
ThreadIdGenerator
,
self
).
__init__
(
max_id
,
base_counter
,
step
)
def
next
(
self
):
next_id
=
None
with
self
.
_lock
:
if
self
.
_counter
>=
self
.
_max_id
:
self
.
_counter
=
self
.
_base_counter
_LOGGER
.
info
(
"Reset Id: {}"
.
format
(
self
.
_counter
))
next_id
=
self
.
_counter
self
.
_counter
+=
self
.
_step
return
next_id
class
ProcessIdGenerator
(
UnsafeIdGenerator
):
def
__init__
(
self
,
max_id
,
base_counter
=
0
,
step
=
1
,
lock
=
None
):
# if you want to use your lock, you may need to use Reentrant-Lock
self
.
_lock
=
lock
if
self
.
_lock
is
None
:
self
.
_lock
=
multiprocessing
.
Lock
()
self
.
_base_counter
=
base_counter
self
.
_counter
=
multiprocessing
.
Manager
().
Value
(
'i'
,
0
)
self
.
_step
=
step
self
.
_max_id
=
max_id
def
next
(
self
):
self
.
_idx
+=
1
return
"{}{}"
.
format
(
self
.
_prefix
,
self
.
_idx
)
next_id
=
None
with
self
.
_lock
:
if
self
.
_counter
.
value
>=
self
.
_max_id
:
self
.
_counter
.
value
=
self
.
_base_counter
_LOGGER
.
info
(
"Reset Id: {}"
.
format
(
self
.
_counter
.
value
))
next_id
=
self
.
_counter
.
value
self
.
_counter
.
value
+=
self
.
_step
return
next_id
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录