timescaledb和influxdb单行写入性能

目录

测试结果摘要

测试环境

Influxdb单行写入测试

测试结果

资源占用

timescaledb单行写入测试

测试结果

资源占用

结果对比


测试结果摘要

单行写入性能,timescaledb超过influxdb的2倍。不论单线程还是多线程。更详细的结果请看后文。

线程平均速率(行/s)单线程2线程4线程8线程16线程32线程
infuxdb422378398370341305
timescaledb91286310189681097833
       
总速率(行/s)单线程2线程4线程8线程16线程32线程
infuxdb4227521588294754449732
timescaledb9121719387473641647625563

在测试中网络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/s69 KB/s72.6 KB/s67.5 KB/s62.4 KB/s56 KB/s
行数422 行/s378 行/s398 行/s370 行/s341 行/s305 行/s
总写入速率字节77 KB/s137 KB/s290 KB/s538 KB/s994 KB/s1777 KB/s
行数422 行/s752 行/s1588 行/s2947 行/s5444 行/s9732行/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/s157.5 KB/s186 KB/s176 KB/s200 KB/s152 KB/s
行数912 行/s863 行/s1018 行/s968 行/s1097 行/s833 行/s
总写入速率字节166.5 KB/s313.7 KB/s707.3 KB/s1344 KB/s3008 KB/s4668 KB/s
行数912 行/s1719 行/s3874 行/s7364  行/s16476 行/s25563 行/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线程
infuxdb422378398370341305
timescaledb91286310189681097833
       
总速率(行/s)单线程2线程4线程8线程16线程32线程
infuxdb4227521588294754449732
timescaledb9121719387473641647625563

小结

结论显而易见,在单行测试中influxdb性能不足timescaledb的一半。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值