Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
171338d8
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1181
Star
22014
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
171338d8
编写于
11月 02, 2020
作者:
P
Ping Xiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add a demo for inserting data with python multiple threads
上级
e2cc48af
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
83 addition
and
0 deletion
+83
-0
tests/pytest/insert/restfulInsert.py
tests/pytest/insert/restfulInsert.py
+83
-0
未找到文件。
tests/pytest/insert/restfulInsert.py
0 → 100644
浏览文件 @
171338d8
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
requests
import
threading
import
random
import
time
class
RestfulInsert
:
def
init
(
self
):
self
.
header
=
{
'Authorization'
:
'Basic cm9vdDp0YW9zZGF0YQ=='
}
self
.
url
=
"http://127.0.0.1:6041/rest/sql"
self
.
ts
=
1500000000000
self
.
numOfThreads
=
20
self
.
numOfTables
=
10000
self
.
recordsPerTable
=
10000
self
.
batchSize
=
1000
self
.
tableNamePerfix
=
't'
def
createTable
(
self
,
threadID
):
tablesPerThread
=
int
(
self
.
numOfTables
/
self
.
numOfThreads
)
print
(
"create table %d to %d"
%
(
tablesPerThread
*
threadID
,
tablesPerThread
*
(
threadID
+
1
)
-
1
))
for
i
in
range
(
tablesPerThread
):
tableID
=
threadID
*
tablesPerThread
name
=
'beijing'
if
tableID
%
2
==
0
else
'shanghai'
data
=
"create table test.%s%d using test.meters tags(%d, '%s')"
%
(
self
.
tableNamePerfix
,
tableID
+
i
,
tableID
+
i
,
name
)
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
def
insertData
(
self
,
threadID
):
print
(
"thread %d started"
%
threadID
)
tablesPerThread
=
int
(
self
.
numOfTables
/
self
.
numOfThreads
)
for
i
in
range
(
tablesPerThread
):
tableID
=
i
+
threadID
*
tablesPerThread
start
=
self
.
ts
for
j
in
range
(
int
(
self
.
recordsPerTable
/
self
.
batchSize
)):
data
=
"insert into test.%s%d values"
%
(
self
.
tableNamePerfix
,
tableID
)
for
k
in
range
(
self
.
batchSize
):
data
+=
"(%d, %d, %d, %d)"
%
(
start
+
j
*
self
.
batchSize
+
k
,
random
.
randint
(
1
,
100
),
random
.
randint
(
1
,
100
),
random
.
randint
(
1
,
100
))
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
def
run
(
self
):
data
=
"drop database if exists test"
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
data
=
"create database test"
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
data
=
"create table test.meters(ts timestamp, f1 int, f2 int, f3 int) tags(id int, loc nchar(20))"
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
threads
=
[]
startTime
=
time
.
time
()
for
i
in
range
(
self
.
numOfThreads
):
thread
=
threading
.
Thread
(
target
=
self
.
createTable
,
args
=
(
i
,))
thread
.
start
()
threads
.
append
(
thread
)
for
i
in
range
(
self
.
numOfThreads
):
threads
[
i
].
join
()
print
(
"createing %d tables takes %d seconds"
%
(
self
.
numOfTables
,
(
time
.
time
()
-
startTime
)))
print
(
"inserting data ======="
)
threads
=
[]
startTime
=
time
.
time
()
for
i
in
range
(
self
.
numOfThreads
):
thread
=
threading
.
Thread
(
target
=
self
.
insertData
,
args
=
(
i
,))
thread
.
start
()
threads
.
append
(
thread
)
for
i
in
range
(
self
.
numOfThreads
):
threads
[
i
].
join
()
print
(
"inserting %d records takes %d seconds"
%
(
self
.
numOfTables
*
self
.
recordsPerTable
,
(
time
.
time
()
-
startTime
)))
ri
=
RestfulInsert
()
ri
.
init
()
ri
.
run
()
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录