Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
acd27083
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
acd27083
编写于
12月 17, 2020
作者:
Z
zyyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change
上级
22f38e54
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
50 addition
and
52 deletion
+50
-52
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosdemoApplication.java
.../main/java/com/taosdata/taosdemo/TaosdemoApplication.java
+6
-0
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
...osdata/taosdemo/components/TaosDemoCommandLineRunner.java
+21
-24
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
...n/java/com/taosdata/taosdemo/service/SubTableService.java
+18
-25
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
...s/JDBC/taosdemo/src/main/resources/application.properties
+5
-3
未找到文件。
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/TaosdemoApplication.java
浏览文件 @
acd27083
package
com.taosdata.taosdemo
;
import
com.zaxxer.hikari.HikariDataSource
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
javax.sql.DataSource
;
@MapperScan
(
basePackages
=
{
"com.taosdata.taosdemo.mapper"
})
@SpringBootApplication
...
...
@@ -10,6 +15,7 @@ public class TaosdemoApplication {
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
TaosdemoApplication
.
class
,
args
);
}
}
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/components/TaosDemoCommandLineRunner.java
浏览文件 @
acd27083
...
...
@@ -15,10 +15,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
import
javax.sql.DataSource
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.util.*
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
@Component
...
...
@@ -33,17 +36,13 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
private
SubTableService
subTableService
;
private
SuperTableMeta
superTableMeta
;
// private List<SubTableMeta> subTableMetaList;
// private List<SubTableValue> subTableValueList;
// private List<List<SubTableValue>> dataList;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
// 读配置参数
JdbcTaosdemoConfig
config
=
new
JdbcTaosdemoConfig
(
args
);
boolean
isHelp
=
Arrays
.
asList
(
args
).
contains
(
"--help"
);
if
(
isHelp
||
config
.
host
==
null
||
config
.
host
.
isEmpty
()
)
{
if
(
isHelp
)
{
JdbcTaosdemoConfig
.
printHelp
();
System
.
exit
(
0
);
}
...
...
@@ -100,8 +99,6 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
}
private
void
insertTask
(
JdbcTaosdemoConfig
config
)
{
long
start
=
System
.
currentTimeMillis
();
long
numOfTables
=
config
.
numOfTables
;
int
numOfTablesPerSQL
=
config
.
numOfTablesPerSQL
;
long
numOfRowsPerTable
=
config
.
numOfRowsPerTable
;
...
...
@@ -118,7 +115,11 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
if
(
numOfTables
<
numOfTablesPerSQL
)
numOfTablesPerSQL
=
(
int
)
numOfTables
;
long
timeCost
=
0
;
ExecutorService
executors
=
Executors
.
newFixedThreadPool
(
config
.
numOfThreadsForInsert
);
List
<
Future
<
Integer
>>
futureList
=
new
ArrayList
<>();
long
start
=
System
.
currentTimeMillis
();
long
affectRows
=
0
;
// row
for
(
long
rowCnt
=
0
;
rowCnt
<
numOfRowsPerTable
;
)
{
...
...
@@ -135,25 +136,22 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
}
/***********************************************/
long
startTime
=
config
.
startTime
+
rowCnt
*
config
.
timeGap
;
// for (int i = 0; i < tableSize; i++) {
// System.out.print(config.prefixOfTable + (tableCnt + i + 1) + ", tableSize: " + tableSize + ", rowSize: " + rowSize);
// System.out.println(", startTime: " + TimeStampUtil.longToDatetime(startTime) + ",timeGap: " + config.timeGap);
// }
// 生成数据
List
<
SubTableValue
>
data
=
SubTableValueGenerator
.
generate
(
superTableMeta
,
config
.
prefixOfTable
,
tableCnt
,
tableSize
,
rowSize
,
startTime
,
config
.
timeGap
);
// List<SubTableValue> data = SubTableValueGenerator.generate(subTableMetaList, tableCnt, tableSize, rowSize, startTime, config.timeGap);
// 乱序
if
(
config
.
order
!=
0
)
{
SubTableValueGenerator
.
disrupt
(
data
,
config
.
rate
,
config
.
range
);
}
// insert
if
(
config
.
autoCreateTable
)
{
long
a
=
System
.
currentTimeMillis
();
subTableService
.
insertAutoCreateTable
(
data
,
config
.
numOfThreadsForInsert
,
config
.
frequency
);
long
b
=
System
.
currentTimeMillis
();
timeCost
+=
(
b
-
a
);
Future
<
Integer
>
future
=
executors
.
submit
(()
->
subTableService
.
insertAutoCreateTable
(
data
));
try
{
affectRows
+=
future
.
get
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
catch
(
ExecutionException
e
)
{
e
.
printStackTrace
();
}
}
else
{
subTableService
.
insert
(
data
,
config
.
numOfThreadsForInsert
,
config
.
frequency
);
}
...
...
@@ -162,8 +160,9 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
}
rowCnt
+=
rowSize
;
}
executors
.
shutdown
();
long
end
=
System
.
currentTimeMillis
();
logger
.
info
(
">>> insert "
+
affectRows
+
" rows with time cost: "
+
(
end
-
start
)
+
"ms"
);
/*********************************************************************************/
// 批量插入,自动建表
// dataList.stream().forEach(subTableValues -> {
...
...
@@ -178,8 +177,6 @@ public class TaosDemoCommandLineRunner implements CommandLineRunner {
// subTableService.insert(subTableMetaList, config.numOfTables, config.tablePrefix, config.numOfThreadsForInsert, config.frequency);
// }
long
end
=
System
.
currentTimeMillis
();
logger
.
info
(
">>> total : "
+
(
end
-
start
)
+
" ms, insert : "
+
(
timeCost
)
+
" ms."
);
}
private
void
prepareMetaData
(
JdbcTaosdemoConfig
config
)
{
...
...
tests/examples/JDBC/taosdemo/src/main/java/com/taosdata/taosdemo/service/SubTableService.java
浏览文件 @
acd27083
...
...
@@ -4,6 +4,7 @@ import com.taosdata.taosdemo.domain.*;
import
com.taosdata.taosdemo.mapper.SubTableMapper
;
import
com.taosdata.taosdemo.service.data.SubTableMetaGenerator
;
import
com.taosdata.taosdemo.utils.TimeStampUtil
;
import
com.zaxxer.hikari.pool.HikariPool
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -85,12 +86,17 @@ public class SubTableService extends AbstractService {
}
// 插入:多线程,多表, 自动建表
public
int
insertAutoCreateTable
(
List
<
SubTableValue
>
subTableValues
,
int
threadSize
,
int
frequency
)
{
ExecutorService
executor
=
Executors
.
newFixedThreadPool
(
threadSize
);
Future
<
Integer
>
future
=
executor
.
submit
(()
->
insertAutoCreateTable
(
subTableValues
));
executor
.
shutdown
();
return
getAffectRows
(
future
);
}
// public int insertAutoCreateTable(List<SubTableValue> subTableValues, int threadSize, int frequency) {
// long a = System.currentTimeMillis();
// ExecutorService executor = Executors.newFixedThreadPool(threadSize);
// long b = System.currentTimeMillis();
// Future<Integer> future = executor.submit(() -> insertAutoCreateTable(subTableValues));
// executor.shutdown();
// int affectRows = getAffectRows(future);
// long c = System.currentTimeMillis();
// logger.info(">>> total : " + (c - a) + " ms, thread: " + (b - a) + " ms, insert : " + (c - b) + " ms.");
// return affectRows;
// }
// 插入:单表,insert into xxx values(),()...
public
int
insert
(
SubTableValue
subTableValue
)
{
...
...
@@ -114,31 +120,18 @@ public class SubTableService extends AbstractService {
// 插入:多表,自动建表, insert into xxx using XXX tags(...) values(),()... xxx using XXX tags(...) values(),()...
public
int
insertAutoCreateTable
(
List
<
SubTableValue
>
subTableValues
)
{
Connection
connection
=
null
;
Statement
statement
=
null
;
int
affectRows
=
0
;
try
{
connection
=
dataSource
.
getConnection
();
// String sql = sqlSessionFactory.getConfiguration()
// .getMappedStatement("com.taosdata.taosdemo.mapper.SubTableMapper.insertMultiTableMultiValuesUsingSuperTable")
// .getBoundSql(subTableValues)
// .getSql();
Connection
connection
=
dataSource
.
getConnection
();
String
sql
=
sql
(
subTableValues
);
logger
.
info
(
">>> SQL : "
+
sql
);
statement
=
connection
.
createStatement
();
//
logger.info(">>> SQL : " + sql);
Statement
statement
=
connection
.
createStatement
();
affectRows
=
statement
.
executeUpdate
(
sql
);
statement
.
close
();
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
statement
!=
null
)
{
statement
.
close
();
}
if
(
connection
!=
null
)
connection
.
close
();
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
return
affectRows
;
// return mapper.insertMultiTableMultiValuesUsingSuperTable(subTableValues);
...
...
tests/examples/JDBC/taosdemo/src/main/resources/application.properties
浏览文件 @
acd27083
...
...
@@ -10,7 +10,9 @@ spring.datasource.password=taosdata
#spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
#spring.datasource.username=root
#spring.datasource.password=taosdata
spring.datasource.hikari.maximum-pool-size
=
1
0
spring.datasource.hikari.minimum-idle
=
1
0
spring.datasource.hikari.maximum-pool-size
=
50
0
spring.datasource.hikari.minimum-idle
=
50
0
spring.datasource.hikari.max-lifetime
=
0
logging.level.com.taosdata.taosdemo.mapper
=
error
\ No newline at end of file
logging.level.com.taosdata.taosdemo.mapper
=
error
server.port
=
8888
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录