0%

influxDB内存优化

查询series cardinality命令

InfluxDB maintains an in-memory index of every series in the system. As the number of unique series grows, so does the RAM usage. High series cardinality can lead to the operating system killing the InfluxDB process with an out of memory (OOM) exception. See SHOW CARDINALITY to learn about the InfluxSQL commands for series cardinality.

// 翻译
InfluxDB会在系统上为每个series维护一个内存索引,而随着这些series的增加,RAM内存使用率也会增加。如果series cardinality如果太高,就会导致操作系统触发OOMKiller机制,将Influxdb进程KILL掉. 使用 SHOW CARDINALITY 命令可以查看到 series cardinality。
-- show estimated cardinality of the series on current database
SHOW SERIES CARDINALITY
-- show estimated cardinality of the series on specified database
SHOW SERIES CARDINALITY ON mydb
-- show exact series cardinality
SHOW SERIES EXACT CARDINALITY
-- show series cardinality of the series on specified database
SHOW SERIES EXACT CARDINALITY ON mydb
To reduce series cardinality, series must be dropped from the index. DROP DATABASE, DROP MEASUREMENT, and DROP SERIES will all remove series from the index and reduce the overall series cardinality.

//大意
要减少或者删除series cardinality, 需要删除库//series

将series由保存到内存改为保存到TSI文件

修改配置

这里我们需要修改的配置是index-version项,可以在influxdb.conf[data]下修改,也可以通过环境变量INFLUXDB_DATA_INDEX_VERSION修改.

[data]
  # The type of shard index to use for new shards.  The default is an in-memory index that is
  # recreated at startup.  A value of "tsi1" will use a disk based index that supports higher
  # cardinality datasets.
  # 这个配置项默认值inmem,可以取消注释修改为tsi1,那么后续的index将会保存在TSI文件中了.重启生效.
  # index-version = "inmem"

重构TSI索引

  1. 停止InfluxDB服务
  2. 删除所有_series文件夹
    默认情况下,_series保存在/data/<dbName>/_series,检查并删除/data目录下所有_series
  3. 删除所有index文件夹
    默认情况下,index文件夹在/data/<dbName/<rpName>/<shardID>/index
  4. 使用influx_inspect重构TSI index
# 格式
influx_inspect buildtsi -datadir <data_dir> -waldir <wal_dir>
# 示例
influx_inspect buildtsi -datadir /data -waldir /wal
  1. 启动influxDB服务