Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
700bd8f2
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
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看板
提交
700bd8f2
编写于
12月 19, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add sql test that setup stable and insert data
上级
4df259b7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
135 addition
and
0 deletion
+135
-0
tests/examples/c/CMakeLists.txt
tests/examples/c/CMakeLists.txt
+2
-0
tests/examples/c/sqlsml.c
tests/examples/c/sqlsml.c
+133
-0
未找到文件。
tests/examples/c/CMakeLists.txt
浏览文件 @
700bd8f2
...
@@ -7,6 +7,8 @@ IF (TD_LINUX)
...
@@ -7,6 +7,8 @@ IF (TD_LINUX)
TARGET_LINK_LIBRARIES
(
demo taos_static trpc tutil pthread
)
TARGET_LINK_LIBRARIES
(
demo taos_static trpc tutil pthread
)
ADD_EXECUTABLE
(
sml schemaless.c
)
ADD_EXECUTABLE
(
sml schemaless.c
)
TARGET_LINK_LIBRARIES
(
sml taos_static trpc tutil pthread
)
TARGET_LINK_LIBRARIES
(
sml taos_static trpc tutil pthread
)
ADD_EXECUTABLE
(
sqlsml sqlsml.c
)
TARGET_LINK_LIBRARIES
(
sqlsml taos_static trpc tutil pthread
)
ADD_EXECUTABLE
(
subscribe subscribe.c
)
ADD_EXECUTABLE
(
subscribe subscribe.c
)
TARGET_LINK_LIBRARIES
(
subscribe taos_static trpc tutil pthread
)
TARGET_LINK_LIBRARIES
(
subscribe taos_static trpc tutil pthread
)
ADD_EXECUTABLE
(
epoll epoll.c
)
ADD_EXECUTABLE
(
epoll epoll.c
)
...
...
tests/examples/c/sqlsml.c
0 → 100644
浏览文件 @
700bd8f2
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "taos.h" // TAOS header file
#include "taoserror.h"
#include "os.h"
bool
verbose
=
false
;
bool
describeTableFirst
=
false
;
typedef
struct
{
TAOS
*
taos
;
int
numThreads
;
int
threadId
;
int
numSTables
;
}
SThreadArgs
;
static
int
executeSql
(
TAOS
*
taos
,
char
*
command
)
{
if
(
verbose
)
{
printf
(
"sql: %s
\n
"
,
command
);
}
TAOS_RES
*
pSql
=
NULL
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
pSql
=
taos_query
(
taos
,
command
);
code
=
taos_errno
(
pSql
);
if
(
code
!=
0
)
{
if
(
verbose
)
fprintf
(
stderr
,
"Failed to run %s, reason: %s
\n
"
,
command
,
taos_errstr
(
pSql
));
taos_free_result
(
pSql
);
return
code
;
}
taos_free_result
(
pSql
);
return
0
;
}
void
*
threadFunc
(
void
*
args
)
{
char
*
sqlDescribeSTable
=
"describe st%d"
;
char
*
sqlCreateSTable
=
"create table st%d (ts timestamp, value double) "
"tags(t0 nchar(20), t1 nchar(20), t2 nchar(20), t3 nchar(20), t4 nchar(20), "
"t5 nchar(20), t6 nchar(20), t7 nchar(20), t8 nchar(20), t9 nchar(20))"
;
char
*
sqlInsertData
=
"insert into t%d using st%d tags('t%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d', 't%d') values(%lld, %d.%d)"
;
SThreadArgs
*
param
=
args
;
int
interval
=
param
->
numSTables
/
param
->
numThreads
;
if
(
param
->
numSTables
%
param
->
numThreads
!=
0
)
{
++
interval
;
}
int
start
=
param
->
threadId
*
interval
;
int
end
=
(
param
->
threadId
+
1
)
*
interval
>
param
->
numSTables
?
param
->
numSTables
:
(
param
->
threadId
+
1
)
*
interval
;
int
r
=
rand
();
for
(
int
i
=
start
;
i
<
end
;
++
i
)
{
int
tableId
=
i
;
char
sql0
[
1024
]
=
{
0
};
char
sql1
[
1024
]
=
{
0
};
char
sql2
[
1024
]
=
{
0
};
sprintf
(
sql0
,
sqlDescribeSTable
,
tableId
);
sprintf
(
sql1
,
sqlCreateSTable
,
tableId
);
time_t
ct
=
time
(
0
);
int64_t
ts
=
ct
*
1000
;
sprintf
(
sql2
,
sqlInsertData
,
tableId
,
tableId
,
r
,
r
,
r
,
r
,
r
,
r
,
r
,
r
,
r
,
r
,
ts
+
tableId
,
r
,
r
);
if
(
describeTableFirst
)
{
executeSql
(
param
->
taos
,
sql0
);
}
executeSql
(
param
->
taos
,
sql1
);
executeSql
(
param
->
taos
,
sql2
);
}
return
NULL
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
numSTables
=
20000
;
int
numThreads
=
32
;
// connect to server
if
(
argc
>
1
)
{
numSTables
=
atoi
(
argv
[
1
]);
}
if
(
argc
>
2
)
{
numThreads
=
atoi
(
argv
[
2
]);
}
if
(
argc
>
3
)
{
describeTableFirst
=
atoi
(
argv
[
3
])
?
true
:
false
;
}
if
(
argc
>
4
)
{
verbose
=
atoi
(
argv
[
4
])
?
true
:
false
;
}
TAOS
*
taos
=
taos_connect
(
NULL
,
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to server, reason:%s
\n
"
,
"null taos"
/*taos_errstr(taos)*/
);
exit
(
1
);
}
executeSql
(
taos
,
"drop database if exists sqlsml"
);
executeSql
(
taos
,
"create database sqlsml"
);
executeSql
(
taos
,
"use sqlsml"
);
pthread_t
*
tids
=
calloc
(
numThreads
,
sizeof
(
pthread_t
));
SThreadArgs
*
threadArgs
=
calloc
(
numThreads
,
sizeof
(
SThreadArgs
));
for
(
int
i
=
0
;
i
<
numThreads
;
++
i
)
{
threadArgs
[
i
].
numSTables
=
numSTables
;
threadArgs
[
i
].
numThreads
=
numThreads
;
threadArgs
[
i
].
threadId
=
i
;
threadArgs
[
i
].
taos
=
taos
;
}
int64_t
begin
=
taosGetTimestampUs
();
for
(
int
i
=
0
;
i
<
numThreads
;
++
i
)
{
pthread_create
(
tids
+
i
,
NULL
,
threadFunc
,
threadArgs
+
i
);
}
for
(
int
i
=
0
;
i
<
numThreads
;
++
i
)
{
pthread_join
(
tids
[
i
],
NULL
);
}
int64_t
end
=
taosGetTimestampUs
();
printf
(
"TIME: %ld
\n
"
,
end
-
begin
);
printf
(
"THROUGHPUT: %d
\n
"
,
(
int
)((
numSTables
*
1e6
)
/
(
end
-
begin
)));
free
(
threadArgs
);
free
(
tids
);
taos_close
(
taos
);
taos_cleanup
();
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录