无码人妻精品一区二区三18禁,影音先锋男人AV橹橹色,污污污污污污www网站免费,日韩成人av无码一区二区三区,欧美性受xxxx狂喷水

如何使用 taosdemo 對 TDengine 進行性能測試?這里有一份詳細教程

Shuduo Sang

2021-10-09 / ,

自 2019 年 7 月開源以來,TDengine 憑借(jie)創新的數(shu)據建模(mo)設計(ji)、快捷的安裝方式、易用的編程(cheng)(cheng)接(jie)(jie)口和(he)(he)強(qiang)大的數(shu)據寫入查(cha)詢性能(neng)博得(de)了大量用戶(hu)的青(qing)睞,其中寫入和(he)(he)查(cha)詢性能(neng)往往令剛接(jie)(jie)觸 TDengine 的用戶(hu)稱嘆(tan)不已。為了便于用戶(hu)在最短時間內就體驗到 TDengine 高性能(neng)這個(ge)特(te)點,我們專門開發(fa)了一(yi)個(ge)名為 taosdemo 的應(ying)用程(cheng)(cheng)序,用于對 TDengine 進(jin)行寫入和(he)(he)查(cha)詢的性能(neng)測試。

用戶(hu)(hu)可以(yi)通(tong)過 taosdemo 輕(qing)松模擬大量(liang)設備產生海量(liang)數據的(de)場景(jing),還可以(yi)通(tong)過 taosdemo 參數靈活控制表(biao)的(de)個數、表(biao)的(de)列數、數據類(lei)型(xing)、一次插入(ru)的(de)記(ji)錄(lu)條數、記(ji)錄(lu)的(de)時(shi)間間隔、亂序比例、客戶(hu)(hu)端接口類(lei)型(xing)以(yi)及并發線程數量(liang)等等。同時(shi),taosdemo也(ye)支持查(cha)詢和訂閱的(de)測試。

運行 taosdemo 很簡單,通過下載 TDengine 安裝包或者自行(xing)下載 進(jin)行(xing)編譯,都可(ke)以在安裝(zhuang)目(mu)錄或者編譯結(jie)果(guo)目(mu)錄中找到并運(yun)行(xing)。

接(jie)下來本文(wen)為(wei)大家(jia)講解 taosdemo 的使用(yong)介紹及注意事項。

如何使用 taosdemo 進行寫入測試

在不(bu)使用任何參(can)數的情況下執行 taosdemo 命(ming)令,輸出如下:

$ taosdemo

taosdemo 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

這(zhe)里顯示的(de)(de)是接下(xia)來 taosdemo 進行數(shu)據(ju)(ju)寫(xie)入(ru)的(de)(de)各(ge)項參數(shu)。默認(ren)不輸入(ru)任何命令行參數(shu)的(de)(de)情況(kuang)下(xia), taosdemo 將(jiang)模擬生成一(yi)個(ge)(ge)電(dian)力行業典型應用(yong)的(de)(de)電(dian)表數(shu)據(ju)(ju)采集場景數(shu)據(ju)(ju),即建(jian)立一(yi)個(ge)(ge)名(ming)(ming)為 test 的(de)(de)數(shu)據(ju)(ju)庫,并創建(jian)一(yi)個(ge)(ge)名(ming)(ming)為 meters 的(de)(de)超級(ji)表,超級(ji)表的(de)(de)結構為:

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)

按回車鍵后(hou) taosdemo 將建(jian)立數(shu)據庫(ku) test 和超(chao)級(ji)(ji)表(biao)(biao) meters,并(bing)按照 TDengine 數(shu)據建(jian)模(mo)的最佳實踐,以 meters 超(chao)級(ji)(ji)表(biao)(biao)為模(mo)板生(sheng)成一萬個(ge)子(zi)表(biao)(biao),代表(biao)(biao)一萬個(ge)獨立上報數(shu)據的電表(biao)(biao)設備。

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)

然后 taosdemo 為每個電表設備模擬生成一萬條記錄:

...
====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

以上(shang)信息是在一臺具備 8 個 CPU 64G 內(nei)存的普通 PC 服務器上(shang)進行(xing)實測(ce)的結果。數據(ju)顯示(shi) taosdemo 用了 18 秒(miao)(miao)的時間插入了 100000000 (不用數了,一億條)記錄,平均每秒(miao)(miao)鐘插入 552 萬 9 千零(ling) 49 條記錄。

此外,TDengine 還能提供性能更好的(de)參數綁(bang)定接(jie)口,在同樣的(de)硬件上使用其參數綁(bang)定接(jie)口 (taosdemo -I stmt )進行相(xiang)同數據(ju)量的(de)寫(xie)入(ru)時(shi),結(jie)果如下:

...


====thread[0] completed total inserted rows: 12500000, total affected rows: 12500000. 2162660.81 records/second====
[1]:100%
====thread[1] completed total inserted rows: 12500000, total affected rows: 12500000. 2156510.94 records/second====
[7]:96%
[5]:96%
[7]:97%
[5]:97%
[7]:98%
[5]:98%
[7]:99%
[5]:99%
[7]:100%
====thread[7] completed total inserted rows: 12500000, total affected rows: 12500000. 2106514.83 records/second====
[5]:100%
====thread[5] completed total inserted rows: 12500000, total affected rows: 12500000. 2104144.73 records/second====
[4]:96%
[2]:96%
[4]:97%
[2]:97%
[4]:98%
[2]:98%
[4]:99%
[2]:99%
[4]:100%
====thread[4] completed total inserted rows: 12500000, total affected rows: 12500000. 2044114.28 records/second====
[2]:100%
====thread[2] completed total inserted rows: 12500000, total affected rows: 12500000. 2039911.44 records/second====
Spent 6.1404 seconds to insert rows: 100000000, affected rows: 100000000 with 8 thread(s) into test.meters. 16285462.00 records/second


insert delay, avg: 4.68ms, max: 662.29ms, min: 2.00ms

結果顯(xian)示 taosdemo 用了 6 秒的時間插入了一億(yi)條記錄,每(mei)秒鐘(zhong)插入性(xing)能高達(da) 1628 萬 5462 條記錄。

由于 taosdemo 使用起(qi)來非(fei)常方便,我們(men)又對(dui)其做(zuo)了更(geng)多的(de)(de)功能擴充,使其能夠支(zhi)持更(geng)復雜的(de)(de)參數設置,便于進行快速原(yuan)型開(kai)發(fa)的(de)(de)樣例數據(ju)準(zhun)備和(he)驗證(zheng)工作(zuo)。

完整(zheng)的 taosdemo 命(ming)令行參數列表通過 taosdemo –help 顯示如(ru)下:

$ taosdemo --help
-f, --file=FILE The meta file to the execution procedure.
-u, --user=USER The user name to use when connecting to the server.
-p, --password The password to use when connecting to the server.
-c, --config-dir=CONFIG_DIR Configuration directory.
-h, --host=HOST TDengine server FQDN to connect. The default host is localhost.
-P, --port=PORT The TCP/IP port number to use for the connection.
-I, --interface=INTERFACE The interface (taosc, rest, and stmt) taosdemo uses. By default use 'taosc'.
-d, --database=DATABASE Destination database. By default is 'test'.
-a, --replica=REPLICA Set the replica parameters of the database, By default use 1, min: 1, max: 3.
-m, --table-prefix=TABLEPREFIX Table prefix name. By default use 'd'.
-s, --sql-file=FILE The select sql file.
-N, --normal-table Use normal table flag.
-o, --output=FILE Direct output to the named file. By default use './output.txt'.
-q, --query-mode=MODE Query mode -- 0: SYNC, 1: ASYNC. By default use SYNC.
-b, --data-type=DATATYPE The data_type of columns, By default use: FLOAT, INT, FLOAT.
-w, --binwidth=WIDTH The width of data_type 'BINARY' or 'NCHAR'. By default use 64
-l, --columns=COLUMNS The number of columns per record. Demo mode by default is 1 (float, int, float). Max values is 4095
All of the new column(s) type is INT. If use -b to specify column type, -l will be ignored.
-T, --threads=NUMBER The number of threads. By default use 8.
-i, --insert-interval=NUMBER The sleep time (ms) between insertion. By default is 0.
-S, --time-step=TIME_STEP The timestamp step between insertion. By default is 1.
-B, --interlace-rows=NUMBER The interlace rows of insertion. By default is 0.
-r, --rec-per-req=NUMBER The number of records per request. By default is 30000.
-t, --tables=NUMBER The number of tables. By default is 10000.
-n, --records=NUMBER The number of records per table. By default is 10000.
-M, --random The value of records generated are totally random.
By default to simulate power equipment scenario.
-x, --aggr-func Test aggregation functions after insertion.
-y, --answer-yes Input yes for prompt.
-O, --disorder=NUMBER Insert order mode--0: In order, 1 ~ 50: disorder ratio. By default is in order.
-R, --disorder-range=NUMBER Out of order data's range. Unit is ms. By default is 1000.
-g, --debug Print debug info.
-?, --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>.

下面介紹 taosdemo 的(de)參(can)數,其設計初衷是(shi)為了滿足數據模擬的(de)需求。接下來先介紹幾(ji)個(ge)常用的(de)參(can)數:

-I, --interface=INTERFACE     The interface (taosc, rest, and stmt) taosdemo uses. Default is 'taosc'.

前(qian)(qian)面在介紹 taosdemo 不同(tong)接口的性能差異時已經提到, -I 參數為選(xuan)擇不同(tong)的接口,目(mu)前(qian)(qian)支持 taosc、stmt 和(he) rest 三種。其(qi)中 taosc 為使(shi)(shi)用 SQL 語句方式進行(xing)數據(ju)(ju)寫入;stmt 為使(shi)(shi)用參數綁定(ding)接口進行(xing)數據(ju)(ju)寫入;rest 為使(shi)(shi)用 RESTful 協(xie)議進行(xing)數據(ju)(ju)寫入。

-T, --threads=NUMBER          The number of threads. Default is 8.

通過-T 參(can)數設置 taosdemo 使用幾個線(xian)程(cheng)進行數據同步寫入,多線(xian)程(cheng)寫入可以(yi)盡最大可能壓榨硬件的處理能力。

-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

前文(wen)提到,taosdemo 默(mo)認(ren)創建(jian)一個典型電(dian)表(biao)(biao)數(shu)據(ju)(ju)采集(ji)應(ying)用場景,每個設備包含(han)電(dian)流電(dian)壓(ya)相位3個采集(ji)量。對于需要定義不(bu)同采集(ji)量的(de)(de)(de)(de)場景,可(ke)以(yi)(yi)使用 -b 參數(shu),TDengine 支持 BOOL、TINYINT、SMALLINT、INT、BIGINT、FLOAT、DOUBLE、BINARY、NCHAR、TIMESTAMP 等(deng)多(duo)種數(shu)據(ju)(ju)類型。通(tong)(tong)過(guo) -b 加(jia)上以(yi)(yi)“ , ”(英(ying)文(wen)逗號)分(fen)割定制類型的(de)(de)(de)(de)列(lie)(lie)(lie)表(biao)(biao),可(ke)以(yi)(yi)使 taosdemo 建(jian)立對應(ying)的(de)(de)(de)(de)超級表(biao)(biao)和子表(biao)(biao),并插入(ru)相應(ying)模擬數(shu)據(ju)(ju);通(tong)(tong)過(guo) -w 參數(shu)可(ke)以(yi)(yi)指定 BINARY 和 NCHAR 數(shu)據(ju)(ju)類型的(de)(de)(de)(de)列(lie)(lie)(lie)的(de)(de)(de)(de)寬度(默(mo)認(ren)為 64 );-l 參數(shu)可(ke)以(yi)(yi)在 -b 參數(shu)指定數(shu)據(ju)(ju)類型的(de)(de)(de)(de)幾列(lie)(lie)(lie)之(zhi)后補充以(yi)(yi) INT 型的(de)(de)(de)(de)總的(de)(de)(de)(de)列(lie)(lie)(lie)數(shu),特別多(duo)列(lie)(lie)(lie)的(de)(de)(de)(de)情況下可(ke)以(yi)(yi)減少(shao)手工輸入(ru)的(de)(de)(de)(de)過(guo)程,最多(duo)支持到 4095 列(lie)(lie)(lie)。

-r, --rec-per-req=NUMBER      The number of records per request. Default is 30000.

為(wei)(wei)(wei)了(le)盡最大(da)可(ke)能利用(yong) TDengine 性能,可(ke)以(yi)(yi)使用(yong)多客(ke)戶端、多線程以(yi)(yi)及一次插入(ru)多條數(shu)據來(lai)進行數(shu)據寫入(ru)。 -r 參(can)數(shu)為(wei)(wei)(wei)設置一次寫入(ru)請求可(ke)以(yi)(yi)拼(pin)(pin)接(jie)的(de)記錄條數(shu),默認為(wei)(wei)(wei)30000條。有效的(de)拼(pin)(pin)接(jie)記錄條數(shu)還和客(ke)戶端緩沖區大(da)小有關,目前的(de)緩沖區為(wei)(wei)(wei) 1M Bytes,如果記錄的(de)列寬(kuan)度比(bi)較大(da),最大(da)有效拼(pin)(pin)接(jie)記錄條數(shu)可(ke)以(yi)(yi)通過 1M 除(chu)以(yi)(yi)列寬(kuan)(以(yi)(yi)字節為(wei)(wei)(wei)單位)計算得出。

-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 senario.

前文還提到 taosdemo 默(mo)認創(chuang)建(jian) 10000 個(ge)表(biao),每個(ge)表(biao)寫入 10000 條記錄,可(ke)以通過(guo) -t 和(he) -n 設(she)置表(biao)的(de)(de)數(shu)(shu)量和(he)每個(ge)表(biao)記錄的(de)(de)數(shu)(shu)量。這里默(mo)認無參(can)數(shu)(shu)生(sheng)成的(de)(de)數(shu)(shu)據為模(mo)擬(ni)真(zhen)(zhen)實(shi)(shi)場(chang)景(jing),模(mo)擬(ni)生(sheng)成的(de)(de)數(shu)(shu)據為電流、電壓和(he)相位(wei)值增加一定的(de)(de)抖動,可(ke)以更真(zhen)(zhen)實(shi)(shi)表(biao)現 TDengine 高效的(de)(de)數(shu)(shu)據壓縮(suo)能力。如果(guo)需要模(mo)擬(ni)生(sheng)成完全隨(sui)機數(shu)(shu)據,可(ke)以通過(guo) -M 參(can)數(shu)(shu)實(shi)(shi)現。

-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.

在某些場景,接收到的(de)(de)(de)(de)數(shu)(shu)(shu)據(ju)(ju)(ju)并不是完(wan)全(quan)按時(shi)間(jian)順序(xu)(xu)排列,而是包含一(yi)定比(bi)例的(de)(de)(de)(de)亂(luan)(luan)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju),對此TDengine 也能(neng)(neng)進行很(hen)好的(de)(de)(de)(de)處(chu)理(li)。為了模擬亂(luan)(luan)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju)的(de)(de)(de)(de)寫(xie)入(ru),taosdemo 提供 -O 和(he)(he) -R 參(can)數(shu)(shu)(shu)進行設置。-O 參(can)數(shu)(shu)(shu)為 0 和(he)(he)不使(shi)用 -O 參(can)數(shu)(shu)(shu)兩者相(xiang)同(tong),為完(wan)全(quan)有(you)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju)寫(xie)入(ru),參(can)數(shu)(shu)(shu) 1 到 50 為數(shu)(shu)(shu)據(ju)(ju)(ju)中包含亂(luan)(luan)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju)的(de)(de)(de)(de)比(bi)例。-R 參(can)數(shu)(shu)(shu)為亂(luan)(luan)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju)時(shi)間(jian)戳(chuo)偏(pian)移的(de)(de)(de)(de)范圍,默認(ren)為 1000 毫秒。另外注意(yi),時(shi)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju)以時(shi)間(jian)戳(chuo)為唯一(yi)標識,所以亂(luan)(luan)序(xu)(xu)數(shu)(shu)(shu)據(ju)(ju)(ju)可能(neng)(neng)會(hui)生(sheng)成和(he)(he)之(zhi)前已經寫(xie)入(ru)的(de)(de)(de)(de)數(shu)(shu)(shu)據(ju)(ju)(ju)完(wan)全(quan)相(xiang)同(tong)的(de)(de)(de)(de)時(shi)間(jian)戳(chuo),這樣的(de)(de)(de)(de)數(shu)(shu)(shu)據(ju)(ju)(ju)會(hui)根據(ju)(ju)(ju)數(shu)(shu)(shu)據(ju)(ju)(ju)庫創建(jian)的(de)(de)(de)(de) update 設置值或(huo)(huo)者被丟(diu)棄(update 0)或(huo)(huo)者覆蓋已有(you)數(shu)(shu)(shu)據(ju)(ju)(ju)(update 1 或(huo)(huo) 2),所以可能(neng)(neng)會(hui)發生(sheng)總的(de)(de)(de)(de)寫(xie)入(ru)數(shu)(shu)(shu)據(ju)(ju)(ju)條數(shu)(shu)(shu)和(he)(he)期待的(de)(de)(de)(de)條數(shu)(shu)(shu)不一(yi)致的(de)(de)(de)(de)情況。

 -g, --debug                   Print debug info.

如(ru)果對 taosdemo 寫(xie)(xie)入(ru)數(shu)(shu)據過程(cheng)感興趣或者覺得數(shu)(shu)據寫(xie)(xie)入(ru)結(jie)果不符合(he)預(yu)期,可(ke)以(yi)使(shi)用 -g 參數(shu)(shu)使(shi) taosdemo 把執行(xing)(xing)過程(cheng)的(de)中間調試信息(xi)輸出到(dao)屏幕(mu)上(shang),也可(ke)以(yi)通過 Linux 重定向命令導入(ru)到(dao)另外一個文(wen)件,方便(bian)找到(dao)發生問(wen)題的(de)原(yuan)(yuan)(yuan)因。另外 taosdemo 在執行(xing)(xing)失敗后也會把相應(ying)執行(xing)(xing)的(de)語句和調試原(yuan)(yuan)(yuan)因輸出到(dao)屏幕(mu),可(ke)以(yi)搜索輸出文(wen)字中的(de) “reason” 來找到(dao) TDengine 服務端返(fan)回的(de)錯誤原(yuan)(yuan)(yuan)因信息(xi),這(zhe)里要(yao)注意(yi)使(shi)用 -g 參數(shu)(shu)進行(xing)(xing)調試信息(xi)輸出會影響性能。

-y, --answer-yes              Default input yes for prompt.

前(qian)面我們可(ke)(ke)以(yi)看到 taosdemo 默認(ren)在進(jin)(jin)行創建數(shu)據(ju)庫(ku)或插入(ru)數(shu)據(ju)之(zhi)前(qian),輸出將要進(jin)(jin)行操作(zuo)(zuo)的(de)參數(shu)列(lie)表并等待(dai)用戶按回車(che)鍵再繼續執行寫(xie)入(ru)操作(zuo)(zuo),方便使(shi)用者在插入(ru)之(zhi)前(qian)了解即將進(jin)(jin)行的(de)數(shu)據(ju)寫(xie)入(ru)的(de)內(nei)容。為了方便進(jin)(jin)行自動(dong)測試,-y 參數(shu)可(ke)(ke)以(yi)使(shi) taosdemo 輸出參數(shu)后立刻進(jin)(jin)行數(shu)據(ju)寫(xie)入(ru)操作(zuo)(zuo)。


-x, --aggr-func Test aggregation funtions after insertion.

TDengine 不僅插(cha)入性(xing)能非常強(qiang)大,其先進的數據庫(ku)引擎設(she)計使得查詢(xun)性(xing)能也(ye)異常強(qiang)大。taosdemo 提供了(le)一(yi)個(ge) -x 參數,可以(yi)在(zai)插(cha)入數據結束后進行常用查詢(xun)操作并輸出(chu)查詢(xun)消耗(hao)時(shi)間。以(yi)下為在(zai)前述相同服務(wu)器上插(cha)入一(yi)億條記錄后進行常用查詢(xun)的結果。

可以看(kan)到(dao) select * 取(qu)出一億條(tiao)記錄(不輸出到(dao)屏幕(mu))操作僅消耗1.26秒。而對一億條(tiao)記錄進行常(chang)用(yong)的聚合函數操作通常(chang)僅需要(yao)二十幾毫秒,時間最長(chang)的 count 函數也不到(dao)四十毫秒。

taosdemo -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)
...

除了命令行方式, taosdemo 還支持接受指定一個(ge) JSON 文(wen)件做為傳(chuan)入(ru)參數的方式。一個(ge)典型的 JSON 文(wen)件內容如下:

{
    "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",   
            "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}]
        }]
    }]
}

JSON 文(wen)件還可(ke)以提供更(geng)豐富(fu)的(de)設(she)置項。例如:我們可(ke)以通過(guo) “thread_count” 和 “thread_count_create_tbl” 來(lai)為建(jian)表(biao)和插(cha)入數據(ju)指(zhi)定(ding)不同數量的(de)線程(cheng);可(ke)以通過(guo) “child_table_exists”、”childtable_limit” 和 “childtable_offset” 的(de)組合來(lai)使用(yong)多個 taosdemo 進程(cheng);甚至可(ke)以在不同的(de)電腦上對同一個超(chao)級表(biao)的(de)不同范圍子(zi)表(biao)進行同時寫(xie)入;還可(ke)以通過(guo) “data_source” 和 “sample_file” 來(lai)指(zhi)定(ding)數據(ju)來(lai)源為 csv 文(wen)件,來(lai)實(shi)現導入已有數據(ju)的(de)功能。

如何使用 taosdemo 進行查詢和訂閱測試

taosdemo 不(bu)僅(jin)可以(yi)(yi)進(jin)行(xing)數據寫入,還擁有查(cha)詢和訂閱功(gong)能。但一(yi)個(ge) taosdemo 實例只(zhi)能支持其中的一(yi)種功(gong)能,不(bu)能同時支持三種功(gong)能,我們可以(yi)(yi)通過配置(zhi)文件(jian)來指定進(jin)行(xing)哪種功(gong)能的測試。

以下為一個典(dian)型查詢 JSON 示例文件內(nei)容:

{
  "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 文件中和查詢相關(guan)的(de)特(te)有參數含義:

“query_times”: 每種查詢類型的查詢次數
“query_mode”: 查詢數據接口。”taosc”:調用TDengine的c接口;“resetful”:使用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”: 查(cha)詢結果(guo)寫入(ru)的(de)文件名。可(ke)選項,缺省是空,表示(shi)查(cha)詢結果(guo)不寫入(ru)文件。

以下(xia)為(wei)一(yi)個(ge)典型訂(ding)閱 JSON 示(shi)例文(wen)件內(nei)容:

{
    "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"
        }]
      }
  }

以下為訂閱功(gong)能(neng)相關的特有參數含義:

“interval”: 執行訂閱的間隔,單位是秒。可選項,缺省是0。
“restart”: 訂閱重啟。”yes”:如果訂閱已經存在,重新開始;”no”: 繼續之前的訂閱。(請注意執行用戶需要對 dataDir 目錄有讀寫權限)
“keepProgress”: 保留訂閱信息進度。yes表示保留訂閱信息,no表示不保留。該值為yes,restart為no時,才能繼續之前的訂閱。
“resubAfterConsume”: 配合 keepProgress 使用,在訂閱消費了相應次數后調用 unsubscribe 取消訂閱并再次訂閱。
“result”: 查(cha)詢結果寫入的文件(jian)名。可選項(xiang),缺省是(shi)空,表示(shi)查(cha)詢結果不寫入文件(jian)。 注意:每條sql語(yu)句后保存結果的文件(jian)不能重名,且生(sheng)成結果文件(jian)時,文件(jian)名會附加線程(cheng)號(hao)。

結語

TDengine是濤思數據(ju)(ju)專為(wei)(wei)物(wu)聯(lian)(lian)網、車(che)聯(lian)(lian)網、工業互聯(lian)(lian)網、IT運維等(deng)場景設計(ji)和優化的大數據(ju)(ju)平臺,由于(yu)數據(ju)(ju)庫內(nei)核中(zhong)創(chuang)新的數據(ju)(ju)存儲和查詢(xun)引擎設計(ji),其展現出(chu)了遠超(chao)同類產品的高效性能。同時(shi),TDengine還支持 SQL 語法和多種(zhong)編程語言的連接器(目(mu)前支持 Java、Python、Go、C#、NodeJS 以及 Rust 等(deng)),易用(yong)性極強,學習(xi)成(cheng)本幾乎為(wei)(wei)零。為(wei)(wei)了便于(yu)運維需求,其還提供數據(ju)(ju)遷(qian)移和監控(kong)功能等(deng)相(xiang)關生態工具軟件。

為了方便剛接觸 TDengine 的(de)使用(yong)者進(jin)行技(ji)術評(ping)估(gu)和壓力測試,我(wo)們為 taosdemo 開發了豐富的(de)特性,本文即為對 taosdemo 的(de)一個簡(jian)單介紹。相信隨著(zhu) TDengine 新(xin)功能的(de)不(bu)斷增加,taosdemo 也會繼續(xu)演化和改進(jin)。

當下,作為 TDengine 的一部分,taosdemo 的源代碼在 GitHub 上已經完全開源,歡迎大家就 taosdemo 或 TDengine 的使用或實現在 GitHub 或者濤思數據的用戶群提出建議或反饋。