taosBenchmark
簡介
taosBenchmark 是一個用于 TDengine 的性能測試的應用程序。taosBenchmark 可以測試 TDengine 的插入、查詢和訂閱功能,它可以模擬由大量設備產生的大量數據,還可以靈活地控制列的數量,數據類型、線程等。以前叫 taosdemo,現在改名為為 taosBenchmark,安裝包提供 taosdemo 作為 taosBenchmark 的軟鏈接。 配置,一種是命令行配置,另一種是JSON文件。
CLI
| 選項名稱 | 描述 |
|---|---|
| -f/--file | JSON 配置文件, 與命令行其他參數不能同時使用 |
| -c/--config-dir | 配置文件所在的目錄,默認路徑是 /etc/taos/ |
| -h/--host | 用于連接 taosd 服務器的 FQDN,默認值為 localhost。 |
| -P/--port | 用于連接 taosd 服務器的端口號,默認值為 6030。 |
| -I/--interface | taosBenchmark 如何插入數據,默認值為 taosc。 |
| -u/--user | 用于連接 taosd 服務器的用戶名,默認值為 root。 |
| -p/--password | 用于連接 taosd 服務器的密碼,默認值為 taosdata。 |
| -o/--output | 指定結果輸出文件的路徑,默認值為 ./output.txt。 |
| -T/--thread | 指定插入數據的線程數,默認值為 8 |
| -i/--insert-interval | 隔行插入模式的插入間隔,單位為 ms,默認值為 0。 |
| -S/--timestampstep | 每個子表中每條記錄的插入時間戳步長,單位是 ms,默認值是 1 |
| -B/--interlace-rows | 向子表插入交錯行的數量 |
| -r/--rec-per-req | 每次插入請求的記錄數,默認值為 30000 |
| -t/--tables | 子表的數量,默認值為 10000。 |
| -n/--records | 每個子表插入的記錄數,默認值為 10000。 |
| -d/--database | 數據庫的名稱,默認值為 test。 |
| -l/--columns | 子表的列數,將使用int數據類型的列。 |
| -A/--tag-type | 子表的標簽的數據類型。 |
| -b/--data-type | 子表的列的數據類型 |
| -w/--binwidth | 調整nchar和binary數據類型的默認長度,默認值為 64。 |
| -m/--table-prefix | 子表名稱的前綴,默認值為 d |
| -E/--escape-character | 在超級表和子表名稱中使用轉義字符,可選。 |
| -C/--chinese | nchar和binary是否基本的Unicode中文字符,可選。 |
| -N/--normal-table | 只創建普通表,不創建超級表,可選。 |
| -M/--random | 數據源否使用隨機的,可選。 |
| -x/--aggr-func | 插入后查詢聚合函數,可選。 |
| -y/--answer-yes | 通過確認提示繼續,可選。 |
| -R/--disorder-range | 失序時間戳的范圍,基于數據庫的精度,默認值為 1000 |
| -O/--disorder | 插入無序時間戳的數據的概率,默認為 0。 |
| -F/--prepare_rand | 生產隨機數據的隨機個數,默認為10000 |
| -a/--replica | 創建數據庫時的副本數量,默認值為 1。 |
| -V/--version | 顯示版本信息并退出 |
| -?/--help | 顯示幫助信息并退出。 |
JSON
1、插入 json 配置文件
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"connection_pool_size": 8,
"thread_count": 4,
"result_file": "./insert_res.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"interlace_rows": 100,
"num_of_records_per_req": 100,
"prepared_rand": 10000,
"chinese":"no",
"databases": [{
"dbinfo": {
"name": "db",
"drop": "yes",
"replica": 1,
"days": 10,
"cache": 16,
"blocks": 8,
"precision": "ms",
"keep": 3650,
"minRows": 100,
"maxRows": 4096,
"comp":2,
"walLevel":1,
"cachelast":0,
"quorum":1,
"fsync":3000,
"update": 0
},
"super_tables": [{
"name": "stb",
"child_table_exists":"no",
"childtable_count": 100,
"childtable_prefix": "stb_",
"escape_character": "yes",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"data_source": "rand",
"insert_mode": "taosc",
"line_protocol": "line",
"insert_rows": 100000,
"childtable_limit": 10,
"childtable_offset":100,
"interlace_rows": 0,
"insert_interval":0,
"partial_col_num": 0,
"disorder_ratio": 0,
"disorder_range": 1000,
"timestamp_step": 10,
"start_timestamp": "2020-10-01 00:00:00.000",
"sample_format": "csv",
"sample_file": "./sample.csv",
"use_sample_ts": "no",
"tags_file": "",
"columns": [{"type": "INT", "name": "id"}, {"type": "DOUBLE", "count":10}, {"type": "BINARY", "len": 16, "count":3}, {"type": "BINARY", "len": 32, "count":6}],
"tags": [{"type": "TINYINT", "count":2, "max": 10, "min": 98}, {"type": "BINARY", "len": 16, "count":5, "values":["beijing","shanghai"]}]
}]
}]
}
參數
| 組 | 選項名稱 | 描述 |
|---|---|---|
| filetype | 文件類型,指定哪種測試,對于插入測試,需要為insert。 | |
| cfgdir | taosd 配置文件所在的目錄,默認值是 /etc/taos。 | |
| host | taosd 服務器的 FQDN,默認為 localhost。 | |
| port | taosd 服務器的端口號,默認為 6030。 | |
| user | 連接 taosd 服務器的用戶名,默認為 root。 | |
| password | 連接 taosd 服務器的密碼,默認為 taosdata。 | |
| connection_pool_size | taos連接池的大小,默認為線程數。 | |
| thread_count | 插入和創建表的線程數,默認為 8。 | |
| result_file | 保存輸出結果的文件路徑,默認為 ./output.txt。 | |
| confirm_parameter_prompt | 在執行過程中傳遞確認提示,默認為無。 | |
| insert_interval | 插入隔行掃描模式的間隔時間,默認值為 0 | |
| interlace_rows | 每個子表的交錯行數,默認值為 0。 | |
| num_of_records_per_req | 每個請求中的記錄數,默認值為 30000。 | |
| prepare_rand | 隨機產生的數據數量,默認值為 10000 | |
| chinese | nchar 和 binary 都是 rand 中文,默認值為否。 | |
| dbinfo | name | 數據庫名稱,必填 |
| dbinfo | drop | 插入測試前是否刪除數據庫,默認值為是。 |
| dbinfo | replica | 復制的數量,默認值是 1。 |
| dbinfo | days | 在文件中存儲數據的時間跨度,默認值為 10。 |
| dbinfo | cache | 內存塊的大小,單位是 MB,默認值是 16。 |
| dbinfo | blocks | 每個 vnode(tsdb) 中的緩存大小的內存塊的數量,默認值為 6。 |
| dbinfo | precision | 數據庫時間精度,默認值為 "ms"。 |
| dbinfo | keep | 保留數據的天數,默認值為 3650。 |
| dbinfo | minRows | 文件塊中的最小記錄數,默認值為 100 |
| dbinfo | minRows | 文件塊中的最大記錄數,默認值為 4096 |
| dbinfo | comp | 文件壓縮標志,默認值為 2。 |
| dbinfo | walLevel | wal 級別,默認值是 1。 |
| dbinfo | cachelast | 是否允許將每個表的最后一條記錄保留在內存中,默認值為 0 |
| dbinfo | quorum | 異步寫需要的確認次數,默認為 1 |
| dbinfo | fsync | 當 wal 設置為 2 時,fsync 的間隔時間,單位為 ms,默認值為 3000。 |
| dbinfo | update | 是否支持數據更新,默認值為 0。 |
| super_tables | name | 超級表的名稱,必須填寫。 |
| super_tables | child_table_exists | 子表是否已經存在,默認為否。 |
| super_tables | child_table_count | 子表的數量,必填 |
| super_tables | childtable_prefix | 子表名稱的前綴,必須填寫。 |
| super_tables | escape_character | 超級表和子表的名稱包括轉義字符,默認為否。 |
| super_tables | auto_create_table | SQL 語句是否自動創建子表。 |
| Super_tables | batch_create_tbl_num | 為每個請求創建的子表數量,默認為 10。 |
| super_tables | data_source | 數據資源類型,選項:rand, sample。 |
| super_tables | insert_mode | 插入模式,選項:taosc, rest, stmt, sml,默認為 taosc。 |
| super_tables | non_stop_mode | 插入模式是否為持續不停的寫入,默認為 no |
| super_tables | line_protocol | 行協議,可選項:line, telnet, json, 默認為 line。 |
| super_tables | tcp_transfer | 使用 tcp 還是 http 協議,默認為 http。 |
| super_tables | insert_rows | 每個子表的記錄數,默認為 0。 |
| super_tables | childtable_offset | 子表的偏移量。 |
| super_tables | childtable_limit | 插入數據的子表數量。 |
| super_tables | interlace_rows | 每個子表的間隔行,默認為 0。 |
| super_tables | insert_interval | 兩個請求之間的插入時間間隔,當 interlace_rows 大于 0 時有效。 |
| super_tables | partial_col_num | 指定僅向前多少列寫入,默認為 0。 |
| super_tables | disorder_ratio | 紊亂時間戳的數據比例,默認為 0 |
| super_tables | disorder_range | 無序時間戳的范圍,只有當 disorder_ratio 大于 0 時才有效,默認為 1000。 |
| super_tables | timestamp_step | 每條記錄的時間戳步驟,默認為 1。 |
| super_tables | start_timestamp | 每個子表的時間戳起始值,默認值是 now。 |
| super_tables | sample_format | 樣本數據文件的類型,現在只支持 csv。 |
| super_tables | sample_file | 樣本文件,僅當 data_source 為 "sample "時有效。 |
| super_tables | use_sample_ts | 樣本文件是否包含時間戳,默認為否。 |
| super_tables | tags_file | 原理與sample_file相同,標簽數據樣本文件,僅支持 taosc、rest insert模式。 |
| columns/tags | type | 數據類型,必填 |
| columns/tags | len | 數據長度,默認為 8。 |
| columns/tags | count | 該列的連續數,默認為 1。 |
| columns/tags | name | 這一列的名稱,連續的列名將是 name_#{number}。 |
| columns/tags | min | 數字數據類型列/標簽的最小值 |
| columns/tags | max | 數字數據類型列/標簽的最大值 |
| columns/tags | values | nchar/binary 列/標簽的值,將從值中隨機選擇。 |
2、查詢測試 json 配置文件
{
"filetype": "query",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"confirm_parameter_prompt": "no",
"databases": "db",
"query_times": 2,
"query_mode": "taosc",
"specified_table_query": {
"query_interval": 1,
"concurrent": 3,
"sqls": [
{
"sql": "select last_row(*) from stb0 ",
"result": "./query_res0.txt"
},
{
"sql": "select count(*) from stb00_1",
"result": "./query_res1.txt"
}
]
},
"super_table_query": {
"stblname": "stb1",
"query_interval": 1,
"threads": 3,
"sqls": [
{
"sql": "select last_row(ts) from xxxx",
"result": "./query_res2.txt"
}
]
}
}
查詢測試 JSON 文件的參數
| 組 | 選項 | 描述 | |
|---|---|---|---|
| filetype | 文件類型,指定哪種測試,對于查詢測試,需要 | ||
| cfgdir | taosd 配置文件所在的目錄。 | ||
| host | taosd 服務器的 FQDN,默認為 localhost。 | ||
| port | taosd 服務器的端口號,默認為 6030。 | ||
| user | 連接 taosd 服務器的用戶名,默認為 root。 | ||
| password | 連接 taosd 服務器的密碼,默認為 taosdata。 | ||
| confirm_parameter_prompt | 在執行過程中傳遞確認提示,默認為否。 | ||
| database | 數據庫的名稱,需要 | ||
| query_times | 查詢次數 | ||
| query mode | 查詢模式,選項:taosc 和 rest,默認為 taosc。 | ||
| specified_table_query/super_table_query | query_interval | 查詢時間間隔,單位是秒,默認是 0 | |
| specified_table_query/super_table_query | concurrent/threads | 執行 SQL 的線程數,默認為 1。 | |
| super_table_query | stblname | supertable name, required | 超級表名稱。 |
| sqls | sql | SQL 命令,必填 | |
| sqls | result | 查詢結果的結果文件,沒有則為空。 |
3、訂閱 json 配置文件
{
"filetype":"subscribe",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"databases": "db",
"confirm_parameter_prompt": "no",
"specified_table_query":
{
"concurrent":1,
"interval":0,
"restart":"yes",
"keepProgress":"yes",
"sqls": [
{
"sql": "select * from stb00_0 ;",
"result": "./subscribe_res0.txt"
}
]
},
"super_table_query":
{
"stblname": "stb0",
"threads":1,
"interval":10000,
"restart":"yes",
"keepProgress":"yes",
"sqls": [
{
"sql": "select * from xxxx where ts > '2021-02-25 11:35:00.000' ;",
"result": "./subscribe_res1.txt"
}]
}
}
訂閱測試 JSON 文件的參數
| 組 | 選項 | 描述 |
|---|---|---|
| filetype | 文件類型,指定哪種測試,對于訂閱測試,需要 | |
| cfgdir | taosd 配置文件的目錄。 | |
| host | taosd 服務器的 FQDN,默認為 localhost。 | |
| port | taosd 服務器的端口號,默認為 6030。 | |
| user | 連接 taosd 服務器的用戶名,默認為 root。 | |
| password | 連接 taosd 服務器的密碼,默認為 taosdata。 | |
| databases | 數據庫名稱,需要 | |
| confirm_parameter_prompt | 在執行過程中是否通過確認提示。 | |
| specified_table_query/super_table_query | concurrent/threads | 執行 SQL 的線程數,默認為 1。 |
| specified_table_query/super_table_query | interval | 執行訂閱的時間間隔,默認為 0。 |
| specified_table_query/super_table_query | restart | no: 繼續之前的訂閱,yes: 開始新的訂閱。 |
| specified_table_query/super_table_query | keepProgress | 是否保留訂閱的進度。 |
| specified_table_query/super_table_query | resubAfterConsume | 是否取消訂閱,然后再次訂閱? |
| super_table_query | stblname | supertable 的名稱,必須的。 |
| sqls | sql | SQL 命令,必填 |
| sqls | result | 查詢結果的結果文件,沒有則為空。 |
參數具體說明
返回
insert mode
可選項有taosc, rest, stmt, sml, sml-rest, 分別對應c接口,restful,參數綁定,schemaless的c接口,taosAdapter schemaless寫入
insert interval
只有當interlace rows大于0時才起作用。 意味著線程在為每個子表插入隔行掃描記錄后,會等待該值的時間再進行下一輪寫入。
partial col num
若該值為 5, 則僅向前 5 列寫入,僅當 insert_mode 為 taosc 和 rest 時生效,為 0 則是向全部列寫入。
batch create tbl num
創建子表時的批數,默認為 10。
注:實際的批數不一定與該值相同,當執行的 SQL 語句大于支持的最大長度時,會自動截斷再執行,繼續創建。
auto create table
僅當 insert_mode 為 taosc, rest, stmt 時 并且 childtable_exists 為 ”no“ 時生效,此參數表示執行寫入的 SQL 語句,若為 “yes” 則為 insert into tb using stb tags (xxx,xxx,...) values (xxx,xxx,...) 這樣的格式,若為 “no“ 則為 insert into tb values (xxx,xxx,...) 這樣的格式,前者不需要提前建立子表,后者需要。
interlace rows
如果它的值為 0,意味著逐個子表逐個子表插入,如果它的值大于零,比如5,將首先插入 到第一個子表的5條記錄,然后是第二個子表5條記錄、然后第三個,以此類推。當所有的子表都寫入5條記錄后,線程將從第一個子表繼續寫入,以此類推。
record per request
每次插入數據請求/調用api時包含的數據行數,也是批次數,當批次數過大時,taos客戶端會返回相應的錯誤信息,此時需要調整這個數來滿足寫入要求。
columns
如果同時設置了該參數和-b/--data-type,會比較該參數與-b/--data-type設置的列類型的列的個數,如果前者大于后者,比如: -l 5 -b float,double, 那么最后的列為 FLOAT,DOUBLE,INT,INT,INT。如果前者小于等于后者,比如: -l 3 -b float,double,float,bigint,那么最后的列為 FLOAT,DOUBLE,FLOAT,BIGINT。
tag type
設置超級表的標簽類型,nchar 和 binary 也可以設置長度,例如:
taosBenchmark -A INT,DOUBLE,NCHAR,BINARY(16)
默認是INT,BINARY(16)。
注意:在有的 shell 比如 bash 命令里面 “()” 需要轉義,則上述指令應為:
taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\)
data type
與-A/--tag-type相同,但用于列,默認為FLOAT,INT,FLOAT
random
默認的情況下,數據是模擬電表的采集點的數據,數據值有特定的大小范圍,若配置次參數,數據將隨機從支持最大的正負32位整數中產生。若有修改表結構的其他參數,如 -l, -b, -A等...,將自動使用從支持最大的正負32位整數內隨機產生的數據。
disorder ratio
隨機亂序時間戳的概率,最大為50,即為50%。隨機的亂序時間戳為當前應插入數據的時間戳倒退隨機disorder-range內的時間戳。
disorder range
只有當-O/--disorder大于0時才有效,單位與數據庫的時間精確度相同。
prepared rand
作為數據源預先生成的隨機數據的數量,小的prepare_rand 會節省內存,但會減少數據種類。若為1,則生成的所有同類型的數據相同。
connection pool size
所有與taos c客戶端相關的交互都需要 taos 實例,實例會預先創建,以防止運行過程中由于中斷導致的失敗,該值決定taos實例預先創建的數量。若不配置,則與線程數相同。
data source
數據的來源,默認為 taosBenchmark 隨機產生,可以配置為 sample,即為使用 sample_file 參數指定的文件內的數據。
line protocol
行協議,僅當 insert_mode 為 sml 與 sml-rest 時生效,可選項為 line, telnet, json。
non stop mode
寫入模式是否為不停的持續寫入,若為 “yes” 則 insert_rows 失效,直到 Ctrl + C 停止程序,寫入才會停止。
注:即使 insert_rows 失效,但是也必須是一個非零正整數。
tcp transfer
僅當 insert_mode 為 sml-rest 并且 line_protocol 為 telnet 時生效,支持兩種通訊協議: tcp 與 http, 默認為 http。
normal table
僅當 insert_mode 為 taosc, stmt, rest 模式下可以使用,不創建超級表,只創建普通表。
childtable limit
僅當 childtable_exists 為 yes 時生效,為使用語句
select tbname from stable limit x offset y;
中的limit的值 x,即為獲取插入的現有的子表數量。
childtable offset
僅當 childtable_exists 為 yes 時生效,為使用語句
select tbname from stable limit x offset y;
中的 offset的值y,即為獲取插入子表的偏移量。
sample file
是否使用以 csv 格式的數據作為數據源,僅當data_source 為 sample 時生效。
注:這里與最終生成的數據不同,最終數據源的數據與prepared_rand的值有關,若 csv 文件內的數據行數小于prepared_rand,那么會循環讀取 csv 文件數據直到與prepared_rand相同,若大于,則會只讀取 prepared_rand 個數的行的數據。
use sample ts
僅當 data_source 為 sample 時生效,sample_file 指定的 csv 文件內是否包含第一列時間戳,默認為 no, 若為yes, 則使用 csv 文件第一列的時間戳,由于同一子表時間戳不能重復,生成的數據個數必須與 csv 文件內的數據行數相同,此時 insert_rows 失效。
tags file
僅當 insert_mode 為 taosc, rest 的模式下生效。
注:這里原理與 sample-file 類似,最終的 tag 的數值與 childtable_count 有關,如果 csv 文件內的 tag 數據行小于給定的子表數量,那么會循環讀取 csv 文件數據直到與子表數量相同,若大于,則只會讀取 childtable_count 行 tag 數據。
type
可選值請參考官方支持的數據類型(//www.yakult-sh.com.cn/docs/cn/v2.0/taos-sql#data-type)。
注:JSON 數據類型比較特殊,只有在 tags 里面可以選擇,并且有且僅有一列 JSON tag 才可以,此時 count 和 len 代表的意義分別是 JSON tag 內的 key-value pair 的個數和每個KV pair 的 value的值的長度,value默認為string。
count
該列連續的個數,比如我們想測試4096個列的性能時,不用羅列出 4096 個列來表示,直接使用 "count": 4096 即可。
len
該數據類型的長度,對 NCHAR,BINARY 和 JSON 數據類型有效,若對其他數據類型配置,若為 0 , 則代表這列始終都是以 null 值寫入,若為其他數,則沒有意義,不建議配置。
name
列的名字,若與count同時使用,比如 "name":"current", "count":3, 則 3 個列的名字分別為 current, current_2. current_3
sql
對于超級表的查詢 SQL,在 SQL 命令中保留 "xxxx",程序會自動將其替換為超級表的所有子表名。 替換為超級表中所有的子表名。

