Java查询es很慢怎么办_elasticsearch索引和搜索慢问题分析解决

简述

Elasticsearch是一个分布式的免费开源搜索和分析引擎,能够实现近实时的数据搜索。在使用的过程中,由于各种原因可能导致集群写入或者查询缓慢,本文主要讲述集中常见的原因和解决方法。

写入拒绝或者慢

现象

当像索引(存储和使文档可被搜索)或者搜索数据的时候会出现类似如下429状态码的报错:

"status": 429, "error": {"type": "es_rejected_execution_exception", "reason": "rejected execution of org.elasticsearch.transport.TransportService$7@77c11b3c on EsThreadPoolExecutor[name = VM-1-1-1-1/write, queue capacity = 800, org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor@4349a9ab[Running, pool size = 32, active threads = 32, queued tasks = 800, completed tasks = 13026004]]"}}

排查

查看Indexing Rate监控指标确认是不是写入速率过高

1)通过kibana或者其它monitor监控查看

2)通过API自己取目前的值,然后存储自己计算:

http://192.168.1.12:9200/_stats

查看集群目前的ThreadpoolWriteQueue和ThreadpoolWriteRejected,确认是不是集群写入太慢或者并发写入过多,导致单node write队列满了。7.x版本每个node的ThreadpoolWriteQueue默认为10000,线程池大小默认为此node的cpu核心数。

1)通过kibana或者其它monitor监控查看

2)通过API自己取目前的值,然后存储自己计算:

http://192.168.1.12:9200/_cat/thread_pool/write?v&h=id,name,active,queue,rejected,completed

根据实际情况,打开慢写入日志,查看哪些写入比较消耗时间,从而进行优化

curl -X PUT "192.168.1.12:9200/_settings?pretty" -H 'Content-Type: application/json' -d'

{

"index.indexing.slowlog.threshold.index.warn": "10s",

"index.indexing.slowlog.threshold.index.info": "5s",

"index.indexing.slowlog.threshold.index.debug": "2s",

"index.indexing.slowlog.threshold.index.trace": "500ms",

"index.indexing.slowlog.level": "info",

"index.indexing.slowlog.source": "1000"

}

'

解决

client写入端增加重试,重试时间设置为随机生成的时间

使用bulk批量写入

增大索引的refresh时间,降低开销

降低shard的replica数量

关闭swap

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值