ElasticSearch索引优化

Linux调整文件数
在文件/etc/security/limits.conf中增加
* soft nofile 65536
* hard nofile 65536
* - memlock unlimited
或者直接编辑/etc/profile文件,在后面加上
ulimit -l unlimited

关闭文件的更新时间
在文件/etc/fstab中添加一行
/dev/sda7     /data/elasticsearch    ext4    noatime,nodiratime 0 0
此处的/dev/sda7指的是通过命令df –h查看/data/elasticsearch所在分区

内存设置
elasticsearch内存设置在文件elasticsearch.yml中

1,设置bootstrap.mlockall等于true
bootstrap.mlockall: true

2,设置线程池数目
# #---------------------------------- Indexing Settings -------------------------
  index.refresh_interval: 30s
  index.translog.flush_threshold_ops: 50000
#
#---------------------------------- Search pool ---------------------
  threadpool.search.type: fixed
  threadpool.search.size: 200
  threadpool.search.queue_size: 1000
#
#---------------------------------- Bulk pool ----------------------
  threadpool.bulk.type: fixed
  threadpool.bulk.size: 600
  threadpool.bulk.queue_size: 3000
#
#---------------------------------- Index pool ---------------------
  threadpool.index.type: fixed
  threadpool.index.size: 200
  threadpool.index.queue_size: 1000
#
#---------------------------------- Indices settings ---------------
  indices.memory.index_buffer_size: 30%
  indices.memory.min_shard_index_buffer_size: 12mb
  indices.memory.min_index_buffer_size: 96mb
#
#---------------------------------- Cache Sizes -------------------
  indices.fielddata.cache.size: 15%
  indices.fielddata.cache.expire: 6h
  indices.cache.filter.size: 15%
  indices.cache.filter.expire: 6h
这样可以确保elasticsearch使用物理内存,不使用linux swap。


提高ES占用内存 (elasticsearch.in.sh)
内存适当调大,初始是256M, 最大1G
ES_MIN_MEM=256m
ES_MAX_MEM=1g
调大后,最小和最大一样,避免GC, 并根据机器情况,设置内存大小。
由于109.116和109.126内存为16G,故将ES的内存调整为12G
ES_MIN_MEM=12g
ES_MAX_MEM=12g

设置GC策略
elasticsearch默认使用的GC是CMS GC
如果你的内存大小超过6G,CMS是不给力的,容易出现stop-the-world
建议使用G1 GC
注释掉:
ES_GC_OPTS="$ES_GC_OPTS -XX:+UseParNewGC"
ES_GC_OPTS="$ES_GC_OPTS -XX:+UseConcMarkSweepGC"
ES_GC_OPTS="$ES_GC_OPTS -XX:CMSInitiatingOccupancyFraction=75"
ES_GC_OPTS="$ES_GC_OPTS -XX:+UseCMSInitiatingOccupancyOnly"

修改为:
ES_GC_OPTS="$ES_GC_OPTS -XX:+UseG1GC"
ES_GC_OPTS="$ES_GC_OPTS -XX:MaxGCPauseMillis=200"
G1 GC优点是减少stop-the-world的几率,但是CPU占有率高。


修改防火墙设置
/etc/init.d/iptables stop

在命令行中运行

curl -XPOST 'http://ip:9200/_all/_optimize?max_num_segments=1'
curl -XPOST 'http://ip:9200/_all/_optimize?only_expunge_deletes=true'
其中:

1.max_num_segments : 

        索引段即lucene中的segments概念,我们知道ES索引过程中会refresh和tranlog也就是说我们在索引过程中segments number不至一个。

        而segments number与检索是有直接联系的,segments number越多检索越慢,而将segments numbers 有可能的情况下保证为1这将可以提到将近一半的检索速度。 

2. only_expunge_deletes : 

        在ES中删除文档,数据不会马上进行硬盘上除去,而进在ES索引中产生一个.del的文件,而在检索过程中这部分数据也会参与检索,ES在检索过程会判断是否删除了,这样也会降低检索效率。所以可以执行清除删除文档。 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值