1. 程式人生 > >timescaledb和influxdb單行寫入效能

timescaledb和influxdb單行寫入效能

目錄

測試結果摘要

測試環境

Influxdb單行寫入測試

測試結果

資源佔用

timescaledb單行寫入測試

測試結果

資源佔用

結果對比


測試結果摘要

單行寫入效能,timescaledb超過influxdb的2倍。不論單執行緒還是多執行緒。更詳細的結果請看後文。

執行緒平均速率(行/s) 單執行緒 2執行緒 4執行緒 8執行緒 16執行緒 32執行緒
infuxdb 422 378 398 370
341 305
timescaledb 912 863 1018 968 1097 833
             
總速率(行/s) 單執行緒 2執行緒 4執行緒 8執行緒 16執行緒 32執行緒
infuxdb 422
752 1588 2947 5444 9732
timescaledb 912 1719 3874 7364 16476 25563

在測試中網路IO、磁碟IO,timescaledb更高,因為寫入更快。

CPU佔用timescaledb也要高出很多,32執行緒時,influxdb CPU佔用 30%,timescaledbCPU佔用70%。

記憶體佔用 32執行緒時 influxdb佔用 高峰為3.8%。  timescaledb佔用 高峰為0.2*32 = 6.4%。大約2倍。

測試環境

influxdb和timescale(pg)資料檔案都寫在固態硬碟上。

influxdb.conf修改:

[meta]
  # Where the metadata/raft database is stored
  dir = "/data2/influxdata/influxdb/meta"

[data]
  # The directory where the TSM storage engine stores TSM files.
  dir = "/data2/influxdata/influxdb/data"

  # The directory where the TSM storage engine stores WAL files.
  wal-dir = "/data2/influxdata/influxdb/wal"

cache-max-memory-size = "2g"
cache-snapshot-memory-size = "100m"

postgresql.conf修改

max_connections = 256

shared_buffers = 3GB                    # min 128kB

work_mem = 16MB                         # min 64kB
maintenance_work_mem = 256MB            # min 1MB

wal_buffers = 4MB 
checkpoint_timeout = 10min              # range 30s-1d
max_wal_size = 2GB

checkpoint_completion_target = 0.9  

測試工具

因為沒有找到可以同時測試TSDB和influxDB的工具,所以自己用JAVA寫了一個客戶端,對兩種資料庫以相同的邏輯寫入相同的資料。客戶端執行在PC上。

 

Influxdb單行寫入測試

資料構造

timestamp + 20 fields 無tags

20fields, 11個整數, 9 個隨機字串

> select * from test where id = 1
name: test
time            col10 col11 col12                        col13             col14                col15              col16                      col17     col18           col19 col2 col20    col3 col4 col5 col6 col7 col8 col9 id
----            ----- ----- -----                        -----             -----                -----              -----                      -----     -----           ----- ---- -----    ---- ---- ---- ---- ---- ---- ---- --
947656001000000 9723  7713  5WP0RK6TB9GT4R740G4YJKXWQFGQ Z0ZBVQLZ2GUCZ4JT5 1SMXEU46DL7BUWSBKNCW 7YA2HA3IO922GUPNNB VS67LNXMWS8C4M68SCU52KBXD0 MLFYKCC54 1XN7R6EEAR7XLSY D7YDJ 3915 R6GVKNW3 6250 7874 5988 4291 4666 9036 7288 1

timestamp 從946656001000L,即"2000-01-01 00:00:01.000"開始,每個執行緒之間相隔 100萬秒(大約11.5天)

執行緒中每一行資料間隔1秒,10W行資料,也就是10W秒,時間跨度大約1.5天。

測試結果

influxdb 單執行緒 2執行緒 4執行緒 8執行緒 16執行緒 32執行緒
執行緒平均速率 位元組 77 KB/s 69 KB/s 72.6 KB/s 67.5 KB/s 62.4 KB/s 56 KB/s
行數 422 行/s 378 行/s 398 行/s 370 行/s 341 行/s 305 行/s
總寫入速率 位元組 77 KB/s 137 KB/s 290 KB/s 538 KB/s 994 KB/s 1777 KB/s
行數 422 行/s 752 行/s 1588 行/s 2947 行/s 5444 行/s 9732行/s

資源佔用

4執行緒時,CPU、磁碟佔用都不高,

32執行緒時,CPU佔用有明顯上升

記憶體佔用最高峰為3.8%

[[email protected] pgdata]# ps -aux|grep influxd
root     10844  6.1  3.8 2850632 1246000 ?     Sl   Oct09  81:05 influxd

 

timescaledb單行寫入測試

表結構如下,與上面測試保持一致。

建立超表都是預設引數,自動分割槽的時間間隔為1天。

create table "ckts1"(
	time TIMESTAMPTZ NOT NULL,
	"id" int,
	"col2" int,
	"col3" int,
	"col4" int,
	"col5" int,
	"col6" int,
	"col7" int,
	"col8" int,
	"col9" int,
	"col10" int,
	"col11" int,,
	"col12" varchar(30),
	"col13" varchar(30),
	"col14" varchar(30),
	"col15" varchar(30),
	"col16" varchar(30),
	"col17" varchar(30),
	"col18" varchar(30),
	"col19" varchar(30),
	"col20" varchar(30)
);

SELECT create_hypertable('ckts1', 'time');

ts1=# \d+ ckts1 
                                            Table "public.ckts1"
 Column |           Type           | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+--------------------------+-----------+----------+---------+----------+--------------+-------------
 time   | timestamp with time zone |           | not null |         | plain    |              | 
 id     | integer                  |           |          |         | plain    |              | 
 col2   | integer                  |           |          |         | plain    |              | 
 col3   | integer                  |           |          |         | plain    |              | 
 col4   | integer                  |           |          |         | plain    |              | 
 col5   | integer                  |           |          |         | plain    |              | 
 col6   | integer                  |           |          |         | plain    |              | 
 col7   | integer                  |           |          |         | plain    |              | 
 col8   | integer                  |           |          |         | plain    |              | 
 col9   | integer                  |           |          |         | plain    |              | 
 col10  | integer                  |           |          |         | plain    |              | 
 col11  | integer                  |           |          |         | plain    |              | 
 col12  | character varying(30)    |           |          |         | extended |              | 
 col13  | character varying(30)    |           |          |         | extended |              | 
 col14  | character varying(30)    |           |          |         | extended |              | 
 col15  | character varying(30)    |           |          |         | extended |              | 
 col16  | character varying(30)    |           |          |         | extended |              | 
 col17  | character varying(30)    |           |          |         | extended |              | 
 col18  | character varying(30)    |           |          |         | extended |              | 
 col19  | character varying(30)    |           |          |         | extended |              | 
 col20  | character varying(30)    |           |          |         | extended |              | 
Indexes:
    "ckts1_time_idx" btree ("time" DESC)
Triggers:
    ts_insert_blocker BEFORE INSERT ON ckts1 FOR EACH ROW EXECUTE PROCEDURE _timescaledb_internal.insert_blocker()

ts1=# 

timestamp 每行間隔和 執行緒間間隔與上面一致。

總資料和influxdb一致

ts1=# select * from ckts1 where id = 1;
          time          | id | col2 | col3 | col4 | col5 | col6 | col7 | col8 | col9 | col10 | col11 |            col12             |       col13       |        col14         |       col15        |           col16            |   col17   |      col18      | col19 |  col20   
------------------------+----+------+------+------+------+------+------+------+------+-------+-------+------------------------------+-------------------+----------------------+--------------------+----------------------------+-----------+-----------------+-------+----------
 2000-01-12 13:46:41+08 |  1 | 3915 | 6250 | 7874 | 5988 | 4291 | 4666 | 9036 | 7288 |  9723 |  7713 | 5WP0RK6TB9GT4R740G4YJKXWQFGQ | Z0ZBVQLZ2GUCZ4JT5 | 1SMXEU46DL7BUWSBKNCW | 7YA2HA3IO922GUPNNB | VS67LNXMWS8C4M68SCU52KBXD0 | MLFYKCC54 | 1XN7R6EEAR7XLSY | D7YDJ | R6GVKNW3
(1 row)

測試結果

timescaledb 單執行緒 2執行緒 4執行緒 8執行緒 16執行緒 32執行緒
執行緒平均速率 位元組 166.5 KB/s 157.5 KB/s 186 KB/s 176 KB/s 200 KB/s 152 KB/s
行數 912 行/s 863 行/s 1018 行/s 968 行/s 1097 行/s 833 行/s
總寫入速率 位元組 166.5 KB/s 313.7 KB/s 707.3 KB/s 1344 KB/s 3008 KB/s 4668 KB/s
行數 912 行/s 1719 行/s 3874 行/s 7364  行/s 16476 行/s 25563 行/s

資源佔用

到8執行緒測試時,CPU佔用還不高

16執行緒測試時,CPU佔用已經有超過50%的了,超過了32執行緒寫入influxdb的CPU佔用。

32執行緒時,CPU佔用很高了

記憶體佔用最高峰為 0.2*32 = 6.4%

postgres 17963 16.8  0.2 3373804 72904 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55285) idle
postgres 17964 17.1  0.2 3370192 71208 ?       Ss   16:45   0:20 postgres: postgres ts1 192.168.55.55(55281) idle in transaction
postgres 17965 17.0  0.2 3370192 70948 ?       Rs   16:45   0:19 postgres: postgres ts1 192.168.55.55(55284) PARSE
postgres 17966 16.9  0.2 3370736 70628 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55283) idle in transaction
postgres 17967 16.7  0.2 3370740 70792 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55292) idle in transaction
postgres 17968 17.2  0.2 3370740 70768 ?       Ss   16:45   0:20 postgres: postgres ts1 192.168.55.55(55282) idle in transaction
postgres 17970 17.1  0.2 3370192 70424 ?       Ss   16:45   0:20 postgres: postgres ts1 192.168.55.55(55287) idle
postgres 17976 17.1  0.2 3370204 70748 ?       Ss   16:45   0:20 postgres: postgres ts1 192.168.55.55(55288) idle in transaction
postgres 17981 16.8  0.2 3370740 69756 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55297) idle
postgres 17982 16.8  0.2 3373804 72904 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55296) idle
postgres 17983 16.9  0.2 3373804 73500 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55286) idle
postgres 17984 16.9  0.2 3370740 69992 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55299) idle
postgres 17985 17.1  0.2 3370740 70532 ?       Rs   16:45   0:20 postgres: postgres ts1 192.168.55.55(55298) idle
postgres 17986 17.0  0.2 3370740 71068 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55300) idle
postgres 17987 17.0  0.2 3370192 69632 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55301) idle in transaction
postgres 17988 16.8  0.2 3370740 70000 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55302) idle
postgres 17989 16.9  0.2 3373804 73296 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55303) idle in transaction
postgres 17992 16.4  0.2 3370740 69732 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55311) idle in transaction
postgres 17993 16.5  0.2 3370192 69096 ?       Ss   16:45   0:19 postgres: postgres ts1 192.168.55.55(55308) idle

結果對比

執行緒平均速率(行/s) 單執行緒 2執行緒 4執行緒 8執行緒 16執行緒 32執行緒
infuxdb 422 378 398 370 341 305
timescaledb 912 863 1018 968 1097 833
             
總速率(行/s) 單執行緒 2執行緒 4執行緒 8執行緒 16執行緒 32執行緒
infuxdb 422 752 1588 2947 5444 9732
timescaledb 912 1719 3874 7364 16476 25563

小結

結論顯而易見,在單行測試中influxdb效能不足timescaledb的一半。