Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ad042ede
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
ad042ede
编写于
7月 02, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
docs: java example
上级
d7d98a26
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
16 deletion
+24
-16
docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java
...in/java/com/taos/example/highvolume/FastWriteExample.java
+2
-1
docs/examples/java/src/main/java/com/taos/example/highvolume/ReadTask.java
...a/src/main/java/com/taos/example/highvolume/ReadTask.java
+13
-10
docs/zh/07-develop/03-insert-data/05-high-volume.md
docs/zh/07-develop/03-insert-data/05-high-volume.md
+9
-5
未找到文件。
docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java
浏览文件 @
ad042ede
...
...
@@ -8,6 +8,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.LinkedBlockingDeque
;
/**
* Prepare target database.
...
...
@@ -57,7 +58,7 @@ class DataBaseMonitor {
public
class
FastWriteExample
{
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
FastWriteExample
.
class
);
final
static
int
taskQueueCapacity
=
10
00
;
final
static
int
taskQueueCapacity
=
Integer
.
MAX_VALUE
/
1
00
;
final
static
List
<
BlockingQueue
<
String
>>
taskQueues
=
new
ArrayList
<>();
final
static
List
<
ReadTask
>
readTasks
=
new
ArrayList
<>();
final
static
List
<
WriteTask
>
writeTasks
=
new
ArrayList
<>();
...
...
docs/examples/java/src/main/java/com/taos/example/highvolume/ReadTask.java
浏览文件 @
ad042ede
...
...
@@ -12,11 +12,11 @@ import java.util.concurrent.BlockingQueue;
*/
class
MockDataSource
implements
Iterator
{
private
String
tbNamePrefix
;
private
int
tableCount
=
100
;
private
int
totalRowsPerTable
=
1000000
;
private
int
tableCount
=
100
0
;
private
long
maxRowsPerTable
=
1000000000L
;
// 100 milliseconds between two neighbouring rows.
long
startMs
=
System
.
currentTimeMillis
()
-
total
RowsPerTable
*
100
;
long
startMs
=
System
.
currentTimeMillis
()
-
max
RowsPerTable
*
100
;
private
int
currentRow
=
0
;
private
int
currentTbId
=
-
1
;
...
...
@@ -37,7 +37,7 @@ class MockDataSource implements Iterator {
currentTbId
=
0
;
currentRow
+=
1
;
}
return
currentRow
<
total
RowsPerTable
;
return
currentRow
<
max
RowsPerTable
;
}
@Override
...
...
@@ -61,24 +61,27 @@ class ReadTask implements Runnable {
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ReadTask
.
class
);
private
final
int
taskId
;
private
final
List
<
BlockingQueue
<
String
>>
taskQueues
;
private
final
int
queueCount
;
private
boolean
active
=
true
;
public
ReadTask
(
int
readTaskId
,
List
<
BlockingQueue
<
String
>>
queues
)
{
this
.
taskId
=
readTaskId
;
this
.
taskQueues
=
queues
;
this
.
queueCount
=
queues
.
size
();
}
/**
*
Hash
data received to different queues.
* Here we use the
hashcode of table name for demo
.
*
Assign
data received to different queues.
* Here we use the
suffix number in table name
.
* You are expected to define your own rule in practice.
*
* @param line record received
* @return which queue to use
*/
public
int
getQueueId
(
String
line
)
{
String
tbName
=
line
.
substring
(
0
,
line
.
indexOf
(
','
));
return
Math
.
abs
(
tbName
.
hashCode
())
%
taskQueues
.
size
();
String
tbName
=
line
.
substring
(
0
,
line
.
indexOf
(
','
));
// For example: tb1_101
String
suffixNumber
=
tbName
.
split
(
"_"
)[
1
];
return
Integer
.
parseInt
(
suffixNumber
)
%
this
.
queueCount
;
}
@Override
...
...
@@ -91,8 +94,8 @@ class ReadTask implements Runnable {
int
queueId
=
getQueueId
(
line
);
taskQueues
.
get
(
queueId
).
put
(
line
);
}
}
catch
(
Interrupted
Exception
e
)
{
e
.
printStackTrace
(
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"Read Task Error"
,
e
);
}
}
...
...
docs/zh/07-develop/03-insert-data/05-high-volume.md
浏览文件 @
ad042ede
...
...
@@ -23,11 +23,14 @@ title: 高效写入
### 主程序
主程序负责创建队列,并启动读线程和写线程。
```
java title="主程序"
{{#include docs/examples/java/src/main/java/com/taos/example/highvolume/FastWriteExample.java:main}}
```
### 读任务的实现
<details>
<summary>
读任务的实现
</summary>
...
...
@@ -49,6 +52,8 @@ title: 高效写入
### SQLWriter 类的实现
SQLWriter 类封装了拼 SQL 和写数据的逻辑。注意,所有的表都没有提前创建,而是写入出错的时候,再以超级表为模板建表,然后重现执行 INSERT 语句。
```
java
{{
#
include
docs
/
examples
/
java
/
src
/
main
/
java
/
com
/
taos
/
example
/
highvolume
/
SQLWriter
.
java
:
SQLWriter
}}
```
...
...
@@ -74,13 +79,12 @@ title: 高效写入
```
5.
用 java 命令启动示例程序
```
java -classpath lib/*:javaexample-1.0.jar com.taos.example.highvolume.FastWriteExample
java -classpath lib/*:javaexample-1.0.jar com.taos.example.highvolume.FastWriteExample
<read_thread_count> <white_thread_count>
```
## Python 示例程序
在 Python 示例程序中采用参数绑定的写入方式。
在 Python 示例程序中采用参数绑定的写入方式。(开发中)
<!--
```python title="Python 示例程序"
```
python title="Python 示例程序"
developing
```
```
-->
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录