influxDB内存优化


查询series cardinality命令

  • InfluxDB官网说明:Why does series cardinality matter?
    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 CARDINALITY命令](https://docs.influxdata.com/influxdb/v1.7/query_language/spec/#show-cardinality)
```sql
-- 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
  5. 启动influxDB服务

文章作者: wuzhiyong
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 wuzhiyong !
评论
 上一篇
k8s【coredns解析问题】 k8s【coredns解析问题】
问题[root@master busybox]# kubectl get pod -nkube-system -owide NAME READY STATUS RESTART
2020-07-02
下一篇 
spring cloud gateway部署到k8s上UrlEncode问题 spring cloud gateway部署到k8s上UrlEncode问题
问题 k8s中ingress使用的是ingress-nginx. 项目中用到了spring cloud gateway做API网关,部署环境有docker、k8s等. 测试出现一个问题:请求的URL路径中如果出现了中文参数,如http:/
2020-06-30
  目录