如何使用 taosBenchmark 進行性能測試
自從 TDengine 2019年 7 月開源以來,憑借創新的數據建模設計、快捷的安裝方式、易用的編程接口和強大的數據寫入查詢性能博得了大量時序數據開發者的青睞。其中寫入和查詢性能往往令剛接觸 TDengine 的用戶稱嘆不已。為了便于用戶在最短時間內就可以體驗到 TDengine 的高性能特點,我們專門開發了一個應用程序 taosBenchmark (曾命名為 taosdemo)用于對 TDengine 進行寫入和查詢的性能測試,用戶可以通過 taosBenchmark 輕松模擬大量設備產生海量數據的場景,并且可以通過 taosBenchmark 參數靈活按照實際場景定制表的個數(對應設備數)、表的列數(對應每個設備采樣點)、數據類型、亂序數據比例、順序或輪詢插入方式、以及并發線程數量。
運行 taosBenchmark 很簡單,通過下載 TDengine 安裝包或者自行下載 編譯都可以在安裝目錄或者編譯結果目錄中找到并運行。
接下來本文為大家講解 taosBenchmark 的使用介紹及注意事項。
使用 taosBenchmark 進行寫入測試
不使用任何參數的情況下執行 taosBenchmark 命令,輸出如下:
$ taosBenchmark
taosBenchmark is simulating data generated by power equipment monitoring...
host: 127.0.0.1:6030
user: root
password: taosdata
configDir:
resultFile: ./output.txt
thread num of insert data: 8
thread num of create table: 8
top insert interval: 0
number of records per req: 30000
max sql length: 1048576
database count: 1
database[0]:
database[0] name: test
drop: yes
replica: 1
precision: ms
super table count: 1
super table[0]:
stbName: meters
autoCreateTable: no
childTblExists: no
childTblCount: 10000
childTblPrefix: d
dataSource: rand
iface: taosc
insertRows: 10000
interlaceRows: 0
disorderRange: 1000
disorderRatio: 0
maxSqlLen: 1048576
timeStampStep: 1
startTimestamp: 2017-07-14 10:40:00.000
sampleFormat:
sampleFile:
tagsFile:
columnCount: 3
column[0]:FLOAT column[1]:INT column[2]:FLOAT
tagCount: 2
tag[0]:INT tag[1]:BINARY(16)
Press enter key to continue or Ctrl-C to stop
這里顯示的是接下來 taosBenchmark 進行數據寫入的各項參數。默認不輸入任何命令行參數的情況下 taosBenchmark 將模擬生成一個電力行業典型應用的電表數據采集場景數據。即建立一個名為 test 的數據庫,并創建一個名為 meters 的超級表,其中表結構為:
taos> describe test.meters;
Field | Type | Length | Note |
=================================================================================
ts | TIMESTAMP | 8 | |
current | FLOAT | 4 | |
voltage | INT | 4 | |
phase | FLOAT | 4 | |
groupid | INT | 4 | TAG |
location | BINARY | 64 | TAG |
Query OK, 6 row(s) in set (0.002972s)
按任意鍵后 taosBenchmark 將建立數據庫 test 和超級表 meters,并按照 TDengine 數據建模的最佳實踐,以 meters 超級表為模板生成一萬個子表,代表一萬個獨立上報數據的電表設備。
taos> use test;
Database changed.
taos> show stables;
name | created_time | columns | tags | tables |
============================================================================================
meters | 2021-08-27 11:21:01.209 | 4 | 2 | 10000 |
Query OK, 1 row(s) in set (0.001740s)
然后 taosBenchmark 為每個電表設備模擬生成一萬條記錄:
...
====thread[3] completed total inserted rows: 6250000, total affected rows: 6250000. 347626.22 records/second====
[1]:100%
====thread[1] completed total inserted rows: 6250000, total affected rows: 6250000. 347481.98 records/second====
[4]:100%
====thread[4] completed total inserted rows: 6250000, total affected rows: 6250000. 347149.44 records/second====
[8]:100%
====thread[8] completed total inserted rows: 6250000, total affected rows: 6250000. 347082.43 records/second====
[6]:99%
[6]:100%
====thread[6] completed total inserted rows: 6250000, total affected rows: 6250000. 345586.35 records/second====
Spent 18.0863 seconds to insert rows: 100000000, affected rows: 100000000 with 16 thread(s) into test.meters. 5529049.90 records/second
insert delay, avg: 28.64ms, max: 112.92ms, min: 9.35ms
以上信息是在一臺具備 8個CPU 64G 內存的普通 PC 服務器上進行實測的結果。顯示 taosBenchmark 用了 18 秒的時間插入了 100000000 (一億)條記錄,平均每秒鐘插入 552 萬 9千零49 條記錄。
TDengine 還提供性能更好的參數綁定接口,而在同樣的硬件上使用參數綁定接口 (taosBenchmark -I stmt )進行相同數據量的寫入,結果如下:
...
====thread[14] completed total inserted rows: 6250000, total affected rows: 6250000. 1097331.55 records/second====
[9]:97%
[4]:97%
[3]:97%
[3]:98%
[4]:98%
[9]:98%
[3]:99%
[4]:99%
[3]:100%
====thread[3] completed total inserted rows: 6250000, total affected rows: 6250000. 1089038.19 records/second====
[9]:99%
[4]:100%
====thread[4] completed total inserted rows: 6250000, total affected rows: 6250000. 1087123.09 records/second====
[9]:100%
====thread[9] completed total inserted rows: 6250000, total affected rows: 6250000. 1085689.38 records/second====
[11]:91%
[11]:92%
[11]:93%
[11]:94%
[11]:95%
[11]:96%
[11]:97%
[11]:98%
[11]:99%
[11]:100%
====thread[11] completed total inserted rows: 6250000, total affected rows: 6250000. 1039087.65 records/second====
Spent 6.0257 seconds to insert rows: 100000000, affected rows: 100000000 with 16 thread(s) into test.meters. 16595590.52 records/second
insert delay, avg: 8.31ms, max: 860.12ms, min: 2.00ms
顯示 taosBenchmark 用了 6 秒的時間插入了一億條記錄,每秒鐘插入性能高達 1659 萬 5 千 590 條記錄。
由于 taosBenchmark 使用起來非常方便,我們又對 taosBenchmark 做了更多的功能擴充,使其支持更復雜的參數設置,便于進行快速原型開發的樣例數據準備和驗證工作。
完整的 taosBenchmark 命令行參數列表可以通過 taosBenchmark --help 顯示如下:
$ taosBenchmark --help
Usage: taosBenchmark [OPTION...]
-f, --file=FILE (**IMPORTANT**) Set JSON configuration file(all
options are going to read from this JSON file),
which is mutually exclusive with other commandline
options
-a, --replia=NUMBER The number of replica when create database,
default is 1.
-A, --tag-type=TAG_TYPE Data type of tables' tags, default is
INT,BINARY(16).
-b, --data-type=COL_TYPE Data type of tables' cols, default is
FLOAT,INT,FLOAT.
-B, --interlace-rows=NUMBER The number of interlace rows insert into
tables, default is 0
-c, --config-dir=CONFIG_DIR Configuration directory.
-C, --chinese Nchar and binary are basic unicode chinese
characters, optional.
-d, --database=DATABASE Name of database, default is test.
-E, --escape-character Use escape character in stable and child table
name, optional.
-F, --prepared_rand=NUMBER Random data source size, default is 10000.
-g, --debug Debug mode, optional.
-G, --performance Performance mode, optional.
-h, --host=HOST TDengine server FQDN to connect, default is
localhost.
-i, --insert-interval=NUMBER Insert interval for interlace mode in
milliseconds, default is 0.
-I, --interface=IFACE insert mode, default is taosc, options:
taosc|rest|stmt|sml
-l, --columns=NUMBER Number of INT data type columns in table, default
is 0.
-m, --table-prefix=TABLE_PREFIX
Prefix of child table name, default is d.
-M, --random Data source is randomly generated, optional.
-n, --records=NUMBER Number of records for each table, default is
10000.
-N, --normal-table Only create normal table without super table,
optional.
-o, --output=FILE The path of result output file, default is
./output.txt.
-O, --disorder=NUMBER Ratio of inserting data with disorder timestamp,
default is 0.
-p, --password=PASSWORD The password to use when connecting to the server,
default is taosdata.
-P, --port=PORT The TCP/IP port number to use for the connection,
default is 6030.
-r, --rec-per-req=NUMBER Number of records in each insert request, default
is 30000.
-R, --disorder-range=NUMBER Range of disordered timestamp, default is 1000.
-S, --time-step=NUMBER Timestamp step in milliseconds, default is 1.
-t, --tables=NUMBER Number of child tables, default is 10000.
-T, --threads=NUMBER The number of thread when insert data, default is
8.
-u, --user=USER The user name to use when connecting to the
server, default is root.
-w, --binwidth=NUMBER The default length of nchar and binary if not
specified, default is 64.
-x, --aggr-func Query aggregation function after insertion,
optional.
-y, --answer-yes Pass confirmation prompt to continue, optional.
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
Report bugs to <support@yakult-sh.com.cn>.
taosBenchmark 的參數是為了滿足數據模擬的需求來設計的。下面介紹幾個常用的參數:
-I, --interface=IFACE The interface (taosc, rest, and stmt) taosBenchmark uses. Default is 'taosc'.
前面介紹 taosBenchmark 不同接口的性能差異已經提到, -I 參數為選擇不同的接口,目前支持 taosc、stmt 和 rest 幾種。其中 taosc 為使用 SQL 語句方式進行數據寫入;stmt 為使用參數綁定接口進行數據寫入;rest 為使用 RESTful 協議進行數據寫入。
-T, --threads=NUMBER The number of threads. Default is 8.
-T 參數設置 taosBenchmark 使用多少個線程進行數據同步寫入,通過多線程可以盡最大可能壓榨硬件的處理能力。
-b, --data-type=DATATYPE The data_type of columns, default: FLOAT, INT, FLOAT.
-w, --binwidth=WIDTH The width of data_type 'BINARY' or 'NCHAR'. Default is 64
-l, --columns=COLUMNS The number of columns per record. Demo mode by default is 3 (float, int, float). Max values is 4095
前文提到,taosBenchmark 默認創建一個典型電表數據采集應用場景,每個設備包含電流電壓相位3個采集量。對于需要定義不同的采集量,可以使用 -b 參數。TDengine 支持 BOOL、TINYINT、SMALLINT、INT、BIGINT、FLOAT、DOUBLE、BINARY、NCHAR、TIMESTAMP 等多種數據類型。通過 -b 加上以“ , ”(英文逗號)分割定制類型的列表可以使 taosBenchmark 建立對應的超級表和子表并插入相應模擬數據。通過 -w 參數可以指定 BINARY 和 NCHAR 數據類型的列的寬度(默認為 64 )。-l 參數可以在 -b 參數指定數據類型的幾列之后補充以 INT 型的總的列數,特別多列的情況下可以減少手工輸入的過程,最多支持到 4095 列。
-r, --rec-per-req=NUMBER The number of records per request. Default is 30000.
為了達到 TDengine 性能極限,可以使用多客戶端、多線程以及一次插入多條數據來進行數據寫入。 -r 參數為設置一次寫入請求可以拼接的記錄條數,默認為30000條。有效的拼接記錄條數還和客戶端緩沖區大小有關,目前的緩沖區為 1M Bytes,如果記錄的列寬度比較大,最大拼接記錄條數可以通過 1M 除以列寬(以字節為單位)計算得出。
-t, --tables=NUMBER The number of tables. Default is 10000.
-n, --records=NUMBER The number of records per table. Default is 10000.
-M, --random The value of records generated are totally random. The default is to simulate power equipment scenario.
前面提到 taosBenchmark 默認創建 10000 個表,每個表寫入 10000 條記錄。可以通過 -t 和 -n 設置表的數量和每個表的記錄的數量。默認無參數生成的數據為模擬真實場景,模擬生成的數據為電流電壓相位值增加一定的抖動,可以更真實表現 TDengine 高效的數據壓縮能力。如果需要模擬生成完全隨機數據,可以通過 -M 參數。
-y, --answer-yes Default input yes for prompt.
前面我們可以看到 taosBenchmark 默認在進行創建數據庫或插入數據之前輸出將要進行操作的參數列表,方便使用者在插入之前了解即將進行的數據寫入的內容。為了方便進行自動測試,-y 參數可以使 taosBenchmark 輸出參數后立刻進行數據寫入操作。
-O, --disorder=NUMBER Insert order mode--0: In order, 1 ~ 50: disorder ratio. Default is in order.
-R, --disorder-range=NUMBER Out of order data's range, ms, default is 1000.
在某些場景,接收到的數據并不是完全按時間順序到來,而是包含一定比例的亂序數據,TDengine 也能進行很好的處理。為了模擬亂序數據的寫入,taosBenchmark 提供 -O 和 -R 參數進行設置。-O 參數為 0 和不使用 -O 參數相同為完全有序數據寫入。1 到 50 為數據中包含亂序數據的比例。-R 參數為亂序數據時間戳偏移的范圍,默認為 1000 毫秒。另外注意,時序數據以時間戳為唯一標識,所以亂序數據可能會生成和之前已經寫入數據完全相同的時間戳,這樣的數據會根據數據庫創建的 update 值或者被丟棄(update 0)或者覆蓋已有數據(update 1 或 2),而總的數據條數可能和期待的條數不一致的情況。
-g, --debug Print debug info.
如果對 taosBenchmark 寫入數據過程感興趣或者數據寫入結果不符合預期,可以使用 -g 參數使 taosBenchmark 打印執行過程中間調試信息到屏幕上,或通過 Linux 重定向命令導入到另外一個文件,方便找到發生問題的原因。另外 taosBenchmark 在執行失敗后也會把相應執行的語句和調試原因輸出到屏幕。可以搜索 reason 來找到 TDengine 服務端返回的錯誤原因信息。
-x, --aggr-func Test aggregation functions after insertion.
TDengine 不僅僅是插入性能非常強大,由于其先進的數據庫引擎設計使查詢性能也異常強大。taosBenchmark 提供一個 -x 函數,可以在插入數據結束后進行常用查詢操作并輸出查詢消耗時間。以下為在前述服務器上進行插入一億條記錄后進行常用查詢的結果。
可以看到 select * 取出一億條記錄(不輸出到屏幕)操作僅消耗1.26秒。而對一億條記錄進行常用的聚合函數操作通常僅需要二十幾毫秒,時間最長的 count 函數也不到四十毫秒。
taosBenchmark -I stmt -T 48 -y -x
...
...
select * took 1.266835 second(s)
...
select count(*) took 0.039684 second(s)
...
Where condition: groupid = 1
select avg(current) took 0.025897 second(s)
...
select sum(current) took 0.025622 second(s)
...
select max(current) took 0.026124 second(s)
...
...
select min(current) took 0.025812 second(s)
...
select first(current) took 0.024105 second(s)
...
除了命令行方式, taosBenchmark 還支持接受指定一個 JSON 文件做為傳入參數的方式來提供更豐富的設置。一個典型的 JSON 文件內容如下:
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"thread_count": 4,
"thread_count_create_tbl": 4,
"result_file": "./insert_res.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"interlace_rows": 100,
"num_of_records_per_req": 100,
"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_",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"data_source": "rand",
"insert_mode": "taosc",
"insert_rows": 100000,
"childtable_limit": 10,
"childtable_offset":100,
"interlace_rows": 0,
"insert_interval":0,
"max_sql_len": 1024000,
"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"}, {"type": "DOUBLE", "count":10}, {"type": "BINARY", "len": 16, "count":3}, {"type": "BINARY", "len": 32, "count":6}],
"tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}]
}]
}]
}
例如:我們可以通過 "thread_count" 和 "thread_count_create_tbl" 來為建表和插入數據指定不同數量的線程。可以通過 "child_table_exists"、"childtable_limit" 和 "childtable_offset" 的組合來使用多個 taosBenchmark 進程(甚至可以在不同的電腦上)對同一個超級表的不同范圍子表進行同時寫入。也可以通過 "data_source" 和 "sample_file" 來指定數據來源為 CSV 文件,來實現導入已有數據的功能。CSV 為半角逗號分隔的數據文件,每行數據列數需要和表的數據列數(如果是標簽數據,是和標簽數)相同。
使用 taosBenchmark 進行查詢和訂閱測試
taosBenchmark 不僅僅可以進行數據寫入,也可以執行查詢和訂閱功能。但一個 taosBenchmark 實例只能支持其中的一種功能,不能同時支持三種功能,通過配置文件來指定進行哪種功能的測試。
以下為一個典型查詢 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 文件中和查詢相關的特有參數含義:
"query_times": 每種查詢類型的查詢次數
"query_mode": 查詢數據接口,"taosc":調用TDengine的c接口;“restful”:使用 RESTful 接口。可選項。缺省是“taosc”。
"specified_table_query": { 指定表的查詢
"query_interval": 執行 sqls 的間隔,單位是秒。可選項,缺省是0。
"concurrent": 并發執行 sqls 的線程數,可選項,缺省是1。每個線程都執行所有的 sqls。
"sqls": 可以添加多個 SQL 語句,最多支持 100 條。
"sql": 查詢語句。必選項。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。
"super_table_query": { 對超級表中所有子表的查詢
"stblname": 超級表名稱。必選項。
"query_interval": 執行 sqls 的間隔,單位是秒。可選項,缺省是0。
"threads": 并發執行 sqls 的線程數,可選項,缺省是1。每個線程負責一部分子表,執行所有的 sqls。
"sql": "SELECT COUNT(*) FROM xxxx"。查詢超級表內所有子表的查詢語句,其中表名必須寫成 “xxxx”,實例會自動替換成子表名。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。
以下為一個典型訂閱 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,
"mode":"sync",
"interval":0,
"restart":"yes",
"keepProgress":"yes",
"sqls": [
{
"sql": "select * from stb00_0 ;",
"result": "./subscribe_res0.txt"
}]
},
"super_table_query":
{
"stblname": "stb0",
"threads":1,
"mode":"sync",
"interval":10000,
"restart":"yes",
"keepProgress":"yes",
"sqls": [
{
"sql": "select * from xxxx where ts > '2021-02-25 11:35:00.000' ;",
"result": "./subscribe_res1.txt"
}]
}
}
以下為訂閱功能相關的特有參數含義:
"interval": 執行訂閱的間隔,單位是秒。可選項,缺省是0。
"restart": 訂閱重啟。"yes":如果訂閱已經存在,重新開始,"no": 繼續之前的訂閱。(請注意執行用戶需要對 dataDir 目錄有讀寫權限)
"keepProgress": 保留訂閱信息進度。yes表示保留訂閱信息,no表示不保留。該值為yes,restart為no時,才能繼續之前的訂閱。
"resubAfterConsume": 配合 keepProgress 使用,在訂閱消費了相應次數后調用 unsubscribe 取消訂閱并再次訂閱。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。 注意:每條 SQL 語句后的保存結果的文件不能重名,且生成結果文件時,文件名會附加線程號。
結語
TDengine是濤思數據專為物聯網、車聯網、工業互聯網、IT運維等設計和優化的大數據平臺。TDengine 由于數據庫內核中創新的數據存儲和查詢引擎設計,展現出遠超同類產品的高效性能。并且由于支持 SQL 語法和多種編程語言的連接器(目前支持 Java, Python, Go, C#, Node.js, Rust 等),易用性極強,學習成本為零。為了便于運維需求,我們還提供數據遷移和監控功能等相關生態工具軟件。
為了剛接觸 TDengine 的使用者方便進行技術評估和壓力測試,我們為 taosBenchmark 開發了豐富的特性。本文即為對 taosBenchmark 的一個簡單介紹,隨著 TDengine 新功能的不斷增加,taosBenchmark 也會繼續演化和改進。taosBenchmark 的代碼做為 TDengine 的一部分在 GitHub 上完全開源。歡迎就 taosBenchmark 或 TDengine 的使用或實現在 GitHub 或者濤思數據的用戶群提出建議或批評。
附錄 - 完整 taosBenchmark 參數介紹
taosBenchmark支持兩種配置參數的模式,一種是命令行參數,一種是使用 JSON 格式的配置文件。
一、命令行參數
-f:指定 taosBenchmark 所需參數的 JSON 配置文件。當使用該參數時,其他所有命令行參數都失效。可選項,缺省是 NULL。目前僅支持不含 BOM(byte-order mark)的標準 UTF-8 編碼文件。
-u: 用戶名。可選項,缺省是“root“。
-p: 密碼。可選項,缺省是“taosdata"。指定密碼需要使用 MySQL 風格,即密碼和 -p 貼緊方式,中間無空格。
-c: 配置文件taos.cfg所在的路徑。因為taosBenchmark通過包含taos的動態庫,去鏈接taosd服務,所以需要做好配置文件。可選項,缺省是 "/etc/taos"路徑。
-h:taosd服務的FQDN。可選項,缺省是“localhost“。
-P: taosd服務的端口號。可選項,缺省是6030。
-d:數據庫名稱。可選項,缺省是“test”。
-a:副本個數,可選項。1 - 3,缺省是1。
-m:表名的前綴。可選項,缺省是“t”。
-s::執行該文件包含的多條 SQL 查詢命令。
-N:使用普通建表模式。有該選項時,全部創建普通表,否則缺省創建超級表,再根據超級表創建子表;
-o:指定執行結果輸出文件的路徑。可選項,缺省是./output.txt。
-q:查詢模式,0:同步模式;1:異步模式。可選項,缺省是0。
-b:列的類型。可選項,缺省是:FLOAT,INT,FLOAT。NCHAR和BINARY也可以自定義長度,例如: NCHAR(16), BINARY(8)
-w:BINARY或NCHAR數據類型的長度。可選項,缺省是16。
-l:列的個數。可選項,缺省是3。
-T:并發線程數。可選項,缺省是10。
-i:兩次 SQL 插入的休眠時間間隔,缺省是0。
-S:兩次插入間隔時間戳步長,缺省是1。
-B:交錯(interlace)寫入模式,缺省是0(順序寫入模式)。
-r:每條插入請求包含的記錄數,缺省是30000。
-t:表的個數。可選項,缺省是10000。
-n:每個表插入的記錄數。可選項,缺省是10000。
-M: 插入數據為完全隨機。可選項,缺省為模擬能源設備真實場景(數據在固定范圍小幅波動)。
-x:不僅僅插入數據。有該選項時,taosBenchmark還會進行聚合函數查詢操作。
-y:提示詢問輸入時缺省輸入yes。
-O:插入亂序數據的比例,0:順序插入;> 0:亂序數據的百分比。可選項,缺省是0。、
-R:亂序百分比不為0時,亂序時間戳范圍,單位:毫秒。可選項,缺省是1000。
-g:打印debug信息
-V: 打印taosBenchmark的debug信息。
--help: 打印命令參數列表。
二、JSON 格式的配置文件中所有參數說明
taosBenchmark支持3種功能的測試,包括插入、查詢、訂閱。但一個taosBenchmark實例不能同時支持三種功能,一個 taosBenchmark 實例只能支持其中的一種功能,通過配置文件來指定進行哪種功能的測試。
1、插入功能測試的 JSON 配置文件
{
"filetype": "insert",
"cfgdir": "/etc/taos",
"host": "127.0.0.1",
"port": 6030,
"user": "root",
"password": "taosdata",
"thread_count": 4,
"thread_count_create_tbl": 4,
"result_file": "./insert_res.txt",
"confirm_parameter_prompt": "no",
"insert_interval": 0,
"interlace_rows": 100,
"num_of_records_per_req": 100,
"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_",
"auto_create_table": "no",
"batch_create_tbl_num": 5,
"data_source": "rand",
"insert_mode": "taosc",
"insert_rows": 100000,
"childtable_limit": 10,
"childtable_offset":100,
"interlace_rows": 0,
"insert_interval":0,
"max_sql_len": 1024000,
"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"}, {"type": "DOUBLE", "count":10}, {"type": "BINARY", "len": 16, "count":3}, {"type": "BINARY", "len": 32, "count":6}],
"tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}]
}]
}]
}
"filetype": 本taosBenchmark實例進行哪種功能測試。"insert"表示數據插入功能。必選項。
"cfgdir": 配置文件taos.cfg所在的路徑。因為taosBenchmark通過包含taos的動態庫,去鏈接taosd服務,所以需要做好配置文件。可選項,缺省是 "/etc/taos"路徑。
"host": taosd服務的FQDN。可選項,缺省是“localhost“。
"port": taosd服務的端口號。可選項,缺省是6030。
"user": 用戶名。可選項,缺省是“root“。
"password": 密碼。可選項,缺省是“taosdata"。
"thread_count": 插入數據時的并發線程數。可選項,缺省是1。
"thread_count_create_tbl": 建子表時的并發線程數。可選項,缺省是1。
"result_file": 測試完成后結果保存文件。可選項,缺省是本實例啟動目錄下的"./insert_res.txt"。
"confirm_parameter_prompt": 執行過程中提示是否確認,為no時,執行過程無需手工輸入enter。可選項,缺省是no。
"insert_interval": 兩次發送請求的間隔時間。可選項,缺省是0,代表無人工設置的時間間隔,單位為ms。。
"interlace_rows": 設置輪詢插入每個單表數據的條目數,如果 interlace_rows childtable_count supertable_num 小于 num_of_records_per_req 時,則請求插入的數目以 interlace_rows childtable_count supertable_num 為準。可選項,缺省是 0。
"num_of_records_per_req": 每條請求數據內容包含的插入數據記錄數目,該數據組成的 SQL 不能大于 maxSqlLen,如果過大,則取 taosd 限制的1M長度(1048576)。0 代表不插入數據,建議配置大于 0。
"databases": [{
"dbinfo": {"name": 數據庫名稱。必選項。
"drop": 如果數據庫已經存在,”yes“:刪除后重建;”no“:不刪除,直接使用。可選項,缺省是”no“。drop = yes 會使其他子表創建相關條目無效。
"replica": 副本個數,可選項。1 - 3,缺省是1。
"days": 數據文件存儲數據的時間跨度,可選項。缺省是10天。
"cache": 內存塊的大小,單位是MB,可選項。缺省是16MB。
"blocks": 每個VNODE(TSDB)中有多少cache大小的內存塊,可選項。缺省是6塊。
"precision": 數據庫時間精度,可選項。"ms":毫秒, “us”:微秒。缺省是“ms”。in
"keep": 數據保留的天數,可選項。缺省是3650天。
"minRows": 文件塊中記錄的最小條數,可選項。缺省是100。
"maxRows": 文件塊中記錄的最大條數,可選項。缺省是4096.
"comp":文件壓縮標志位,可選項。0:關閉,1:一階段壓縮,2:兩階段壓縮。缺省是2。
"walLevel":WAL級別,可選項。1:寫wal, 但不執行fsync; 2:寫wal, 而且執行fsync。缺省是1。
"cachelast":允許在內存中保留每張表的最后一條記錄。1表示允許。
"quorum":異步寫入成功所需應答之法定數,1-3,可選項。缺省是1。
"fsync":當wal設置為2時,執行fsync的周期,單位是毫秒,最小為0,表示每次寫入,立即執行fsync. 最大為180000,可選項。缺省是3000。
"update": 支持數據更新,0:否;1:是。可選項。缺省是0。 ? },
"super_tables": [{ ? "name": 超級表名稱,必選項。
"child_table_exists": 子表是否已經存在,“yes”:是;"no":否。指定“是”后,不再建子表,后面相關子表的參數就無效了。可選項,缺省是“no”。database 設置 drop = yes 時,無論配置文件內容,此參數將自動置為 no。
"childtable_count": 建立子表個數 。該值需要大于0。當child_table_exists為“no”時,必選項,否則就是無效項。
"childtable_prefix": 子表名稱前綴。當child_table_exists為“no”時,必選項,否則就是無效項。確保數據庫中表名沒有重復。
"auto_create_table": 子表的創建方式,“yes”:自動建表;"no":提前建表。可選項,缺省是“no”。當 child_table_exists 為 “yes” 時此參數將自動置為 no 。
"batch_create_tbl_num": 一個 SQL 批量創建子表的數目。
"data_source": 插入數據來源,"rand":實例隨機生成;“sample”:從樣例文件中讀取。可選項。缺省是“rand”。
"insert_mode": 插入數據接口,"taosc":調用TDengine的c接口;“rest”:使用 RESTful 接口;“stmt”:使用 stmt (參數綁定)接口 (目前僅在 develop 分支代碼中)。可選項。缺省是“taosc”。
"insert_rows": 插入記錄數,0:一直插入,永不退出;>0:每個子表插入記錄數,完成后實例退出。可選項,缺省是0。
"childtable_offset": 插入數據時,子表起始值。只在drop=no && child_table_exists= yes,該字段生效。
"childtable_limit": 插入數據時,子表從offset開始,偏移的表數目。使用者可以運行多個 taosBenchmark 實例(甚至可以在不同的機器上)通過使用不同的 childtable_offset 和 childtable_limit 配置值來實現同時寫入相同數據庫相同超級表下多個子表。只在drop=no && child_table_exists= yes,該字段生效。
"interlace_rows": 跟上面的配置一致,不過該處的配置優先,每個stable可以有自己單獨的配置。最大不超過 num_of_records_per_req。
"insert_interval": 同上。
"max_sql_len": 同上
"disorder_ratio": 插入數據時的亂序百分比,可選項,缺省是0。
"disorder_range": 亂序百分比不為0時,亂序時間戳范圍,單位:ms。可選項,缺省是1000,即1秒或1000毫秒。
"timestamp_step": 每個子表中記錄時間戳的步長,單位:ms。可選項,缺省是1,即1毫秒。
"start_timestamp": 子表中記錄時間戳的起始值,支持"2020-10-01 00:00:00.000"和“now”兩種格式,可選項,缺省是“now”。
"sample_format": 當插入數據源選擇“sample”時,sample文件的格式,"csv":CSV 格式,每列的值與子表的 columns 保持一致,但不包含第1列的時間戳。可選項,缺省是”csv”。目前僅僅支持 CSV 格式的 sample 文件。
"sample_file":sample文件,包含路徑和文件名。當插入數據源選擇“sample”時,該項為必選項。
"use_sample_ts":sample 文件是否包含第一列時間戳,可選項: "yes" 和 "no", 默認 "no"。(注意:若為 yes,則 disorder_ratio 和 disorder_range 失效)
"tags_file": 子表 tags 值文件,只能是 CSV 文件格式,且必須與超級表的tags保持一致。當該項為非空時,表示子表的tags值從文件中獲取;為空時,實例隨機生成。可選項,缺省是空。
"columns": [{ 超級表的 column 列表,最大支持 4096 列(指所有普通列+超級列總和)。默認的第一列為時間類型,程序自動添加,不需要手工添加。
"type": 該列的數據類型 ,必選項。
"len": 該列的長度,只有 type 是 BINARY 或 NCHAR 時有效,可選項,缺省值是 8。
"count":該類型的連續列個數,可選項,缺省是 1。
}],
"tags": [{ 超級表的 tags 列表,type不能是 TIMESTAMP 類型, 最大支持 128 個。
"type": 該列的數據類型 ,必選項。
"len": 該列的長度,只有 type 是 BINARY 或 NCHAR 時有效,可選項,缺省值是 8。
"count":該類型的連續列個數,可選項,缺省是 1。
}]
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"
}
]
}
}
"filetype": 本taosBenchmark實例進行哪種功能測試。"query"表示數據查詢功能。必選項。
"cfgdir": 配置文件taos.cfg所在的路徑。因為taosBenchmark通過包含taos的動態庫,去鏈接taosd服務,所以需要做好配置文件。可選項,缺省是 "/etc/taos"路徑。
"host": taosd服務的FQDN。可選項,缺省是“localhost“。
"port": taosd服務的端口號。可選項,缺省是6030。
"user": 用戶名。可選項,缺省是“root“。
"password": 密碼。可選項,缺省是“taosdata"。
"confirm_parameter_prompt": 執行過程中提示是否確認,為no時,執行過程無需手工輸入enter。可選項,缺省是no。
"databases": 數據庫名稱。必選項。
"query_times": 每種查詢類型的查詢次數
"query_mode": 查詢數據接口,"taosc":調用TDengine的c接口;“restful”:使用 RESTful 接口。可選項。缺省是“taosc”。
"specified_table_query": { 指定表的查詢
"query_interval": 執行 sqls 的間隔,單位是秒。可選項,缺省是0。
"concurrent": 并發執行 sqls 的線程數,可選項,缺省是1。每個線程都執行所有的 sqls。
"sqls": 可以添加多個 SQL 語句,最多支持100條。
"sql": 查詢語句。必選項。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。
"super_table_query": { 對超級表中所有子表的查詢
"stblname": 超級表名稱。必選項。
"query_interval": 執行 sqls 的間隔,單位是秒。可選項,缺省是0。
"threads": 并發執行 sqls 的線程數,可選項,缺省是1。每個線程負責一部分子表,執行所有的 sqls。
"sql": "select count(*) from xxxx"。查詢超級表內所有子表的查詢語句,其中表名必須寫成 “xxxx”,實例會自動替換成子表名。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。
注意:每條 SQL 語句后的保存結果的文件不能重名,且生成結果文件時,文件名會附加線程號。
查詢結果顯示:如果查詢線程結束一次查詢距開始執行時間超過30秒打印一次查詢次數、用時和QPS。所有查詢結束時,匯總打印總的查詢次數和QPS。
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,
"mode":"sync",
"interval":0,
"restart":"yes",
"keepProgress":"yes",
"sqls": [
{
"sql": "select * from stb00_0 ;",
"result": "./subscribe_res0.txt"
}]
},
"super_table_query":
{
"stblname": "stb0",
"threads":1,
"mode":"sync",
"interval":10000,
"restart":"yes",
"keepProgress":"yes",
"sqls": [
{
"sql": "select * from xxxx where ts > '2021-02-25 11:35:00.000' ;",
"result": "./subscribe_res1.txt"
}]
}
}
"filetype": 本taosBenchmark實例進行哪種功能測試。"subscribe"表示數據查詢功能。必選項。**
"cfgdir": 配置文件taos.cfg所在的路徑。因為taosBenchmark通過包含taos的動態庫,去鏈接taosd服務,所以需要做好配置文件。可選項,缺省是 "/etc/taos"路徑。
"host": taosd服務的FQDN。可選項,缺省是“localhost“。
"port": taosd服務的端口號。可選項,缺省是6030。
"user": 用戶名。可選項,缺省是“root“。
"password": 密碼。可選項,缺省是“taosdata"。
"databases": 數據庫名稱。必選項。**
"confirm_parameter_prompt": 執行過程中提示是否確認,為no時,執行過程無需手工輸入enter。可選項,缺省是no。
注意:這里的訂閱查詢 SQL 目前只支持 SELECT * ,其余不支持。
"specified_table_query": 指定表的訂閱。
"concurrent": 并發執行 sqls 的線程數,可選項,缺省是1。每個線程都執行所有的 sqls。
"mode": 訂閱模式。目前支持同步和異步訂閱,缺省是sync。
"interval": 執行訂閱的間隔,單位是秒。可選項,缺省是0。
"restart": 訂閱重啟。"yes":如果訂閱已經存在,重新開始,"no": 繼續之前的訂閱。(請注意執行用戶需要對 dataDir 目錄有讀寫權限)
"keepProgress": 保留訂閱信息進度。yes表示保留訂閱信息,no表示不保留。該值為yes,restart為no時,才能繼續之前的訂閱。
"resubAfterConsume": 配合 keepProgress 使用,在訂閱消費了相應次數后調用 unsubscribe 取消訂閱并再次訂閱。
"sql": 查詢語句。必選項。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。
"super_table_query": 對超級表中所有子表的訂閱。
"stblname": 超級表名稱。必選項。
"threads": 并發執行 sqls 的線程數,可選項,缺省是1。每個線程都執行所有的 sqls。
"mode": 訂閱模式。
"interval": 執行 sqls 的間隔,單位是秒。可選項,缺省是 0。
"restart": 訂閱重啟。"yes":如果訂閱已經存在,重新開始,"no": 繼續之前的訂閱。
"keepProgress": 保留訂閱信息進度。yes表示保留訂閱信息,no表示不保留。該值為yes,restart為no時,才能繼續之前的訂閱。
"resubAfterConsume": 配合 keepProgress 使用,在訂閱消費了相應次數后調用 unsubscribe 取消訂閱并再次訂閱。
"sql": " SELECT COUNT(*) FROM xxxx "。查詢語句,其中表名必須寫成 “xxxx”,實例會自動替換成子表名。
"result": 查詢結果寫入的文件名。可選項,缺省是空,表示查詢結果不寫入文件。 注意:每條 SQL 語句后的保存結果的文件不能重名,且生成結果文件時,文件名會附加線程號。

