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%

[root@server4 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的一半。

猜你喜欢

转载自blog.csdn.net/jacicson1987/article/details/82988556