Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ca9a65d7
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ca9a65d7
编写于
7月 14, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: mockdatasoruce.py
上级
9fac17d6
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
70 addition
and
46 deletion
+70
-46
docs/examples/python/highvolume_faster_queue.py
docs/examples/python/highvolume_faster_queue.py
+7
-46
docs/examples/python/mockdatasoruce.py
docs/examples/python/mockdatasoruce.py
+63
-0
未找到文件。
docs/examples/python/highvolume_faster_queue.py
浏览文件 @
ca9a65d7
...
...
@@ -9,6 +9,7 @@ import time
import
os
from
multiprocessing
import
Process
from
faster_fifo
import
Queue
from
mockdatasoruce
import
MockDataSource
from
queue
import
Empty
from
typing
import
List
...
...
@@ -40,57 +41,17 @@ def get_connection():
return
taos
.
connect
(
host
=
host
,
port
=
int
(
port
),
user
=
user
,
password
=
password
)
# ANCHOR: MockDataSource
class
MockDataSource
:
location
=
[
"LosAngeles"
,
"SanDiego"
,
"Hollywood"
,
"Compton"
,
"San Francisco"
]
current
=
[
8.8
,
10.7
,
9.9
,
8.9
,
9.4
]
voltage
=
[
119
,
116
,
111
,
113
,
118
]
phase
=
[
0.32
,
0.34
,
0.33
,
0.329
,
0.141
]
max_rows_per_table
=
10
**
9
def
__init__
(
self
,
tb_name_prefix
,
table_count
):
self
.
table_name_prefix
=
tb_name_prefix
self
.
table_count
=
table_count
self
.
start_ms
=
round
(
time
.
time
()
*
1000
)
-
self
.
max_rows_per_table
*
100
def
__iter__
(
self
):
self
.
row
=
0
self
.
table_id
=
-
1
return
self
def
__next__
(
self
):
"""
next 100 rows of current table
"""
self
.
table_id
+=
1
if
self
.
table_id
==
self
.
table_count
:
self
.
table_id
=
0
if
self
.
row
>=
self
.
max_rows_per_table
:
raise
StopIteration
rows
=
[]
while
len
(
rows
)
<
100
:
self
.
row
+=
1
ts
=
self
.
start_ms
+
100
*
self
.
row
group_id
=
self
.
table_id
%
5
if
self
.
table_id
%
5
==
0
else
self
.
table_id
%
5
+
1
tb_name
=
self
.
table_name_prefix
+
'_'
+
str
(
self
.
table_id
)
ri
=
self
.
row
%
5
rows
.
append
(
f
"
{
tb_name
}
,
{
ts
}
,
{
self
.
current
[
ri
]
}
,
{
self
.
voltage
[
ri
]
}
,
{
self
.
phase
[
ri
]
}
,
{
self
.
location
[
ri
]
}
,
{
group_id
}
"
)
return
self
.
table_id
,
rows
# ANCHOR_END: MockDataSource
# ANCHOR: read
def
run_read_task
(
task_id
:
int
,
task_queues
:
List
[
Queue
]):
table_count_per_task
=
TABLE_COUNT
//
READ_TASK_COUNT
data_source
=
MockDataSource
(
f
"tb
{
task_id
}
"
,
table_count_per_task
)
try
:
for
table_id
,
rows
in
data_source
:
for
batch
in
data_source
:
for
table_id
,
row
in
batch
:
# hash data to different queue
i
=
table_id
%
len
(
task_queues
)
# block putting forever when the queue is full
task_queues
[
i
].
put_many
(
rows
,
block
=
True
,
timeout
=-
1
)
task_queues
[
i
].
put
(
row
,
block
=
True
,
timeout
=-
1
)
except
KeyboardInterrupt
:
pass
...
...
docs/examples/python/mockdatasoruce.py
0 → 100644
浏览文件 @
ca9a65d7
import
time
class
MockDataSource
:
samples
=
[
"LosAngeles,0,8.8,119,0.32"
,
"SanDiego,1,10.7,116,0.34"
,
"Hollywood,2,9.9,111,0.33"
,
"Compton,3,8.9,113,0.329"
,
"San Francisco,4,9.4,118,0.141"
]
def
__init__
(
self
,
tb_name_prefix
,
table_count
):
self
.
table_name_prefix
=
tb_name_prefix
+
"_"
self
.
table_count
=
table_count
self
.
max_rows
=
10000000
self
.
start_ms
=
round
(
time
.
time
()
*
1000
)
-
self
.
max_rows
*
100
self
.
data
=
self
.
_init_data
()
def
_init_data
(
self
):
lines
=
self
.
samples
*
(
self
.
table_count
//
5
+
1
)
data
=
[]
for
i
in
range
(
self
.
table_count
):
table_name
=
self
.
table_name_prefix
+
str
(
i
)
# tbName,location,groupId,current,voltage,phase
row
=
table_name
+
','
+
lines
[
i
]
data
.
append
((
i
,
row
))
# tableId, row
return
data
def
__iter__
(
self
):
self
.
row
=
0
return
self
def
__next__
(
self
):
"""
next row for each table.
[(tableId, row),(tableId, row)]
"""
self
.
row
+=
1
ts
=
self
.
start_ms
+
100
*
self
.
row
# just add timestamp to each row
return
map
(
lambda
t
:
(
t
[
0
],
str
(
ts
)
+
","
+
t
[
1
]),
self
.
data
)
if
__name__
==
'__main__'
:
"""
Test performance of MockDataSource
"""
from
threading
import
Thread
count
=
0
def
consume
():
global
count
for
data
in
MockDataSource
(
"1"
,
1000
):
count
+=
len
(
data
)
Thread
(
target
=
consume
).
start
()
while
True
:
time
.
sleep
(
1
)
print
(
count
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录