ES常见性能问题与解决方案

常见性能问题与解决方案

当前性能问题很多是硬件资源限制,或者是配置使用不合理,再或者是集群部署不合理,常见问题如下:

  1. 全文检索场景下查询速度慢问题。 分析:对全索引,全字段进行全文检索,发现查询速度很慢。通过集群状态分析发现,index数和shard数偏多,规划不合理,同时索引分片数设置不合理。通过查询慢日志发现,提取阶段需要合并大量的结果,导致整个查询时间慢。 解决方案:关闭swap交换内存,重新规划索引的shard个数,定时的进行索引段合并减少集群segment个数。
  2. 写入数据达到一定量时,指定ID导致读IO很高问题。 分析:在EsNode节点上执行iotop命令,发现大量Elasticsearch线程的磁盘读速率高。通过线程堆栈信息发现,在索引bulk命令的写入流程中,由于写入请求指定文档ID,需要先做一次全量查询,确认该index是否存在指定的文档ID,这个查询过程占用大量的磁盘读IO。 解决方案:业务测进行调整,写入数据时不指定文档ID,而是将其作为一个index字段。

针对性能问题首先排查系统部署是否合理,然后查看硬件资源是否达到瓶颈,结合客户的查询特点,有针对性的利用第3节的调优参数进行调整。

查看日志信息,排查系统后台是否有报错,根据错误信息针对具体问题分析性能不达标的根本原因。

日志分类介绍:

当前Elasticsearch各个实例的日志保存在“${BigdataLogHome}/elasticsearch/${Rolename}”和“${BigdataLogHome}/audit/elasticsearch/${Rolename}”目录下。

  • 安装日志如下:
日志文件名 分析描述
es-postinstall.log Elasticsearch安装日志
es-start.log Elasticsearch启动日志
es-stop.log Elasticsearch停止日志
  • 运行日志如下:
日志文件名 分析描述
elasticsearch_cluster.log Elasticsearch集群日志,实例运行日志
es-process-check.log Elasticsearch健康检查日志
es-sevice-check.log Elasticsearch服务检查日志
elasticsearch_cluster_index_indexing_slowlog.log Elasticsearch索引慢日志
elasticsearch_cluster_index_search_slowlog.log Elasticsearch查询慢日志
es-gc.log Elasticsearch实例的GC日志
elasticsearch_cluster-audit.log 记录对索引级别的操作,比如迁移shard,删除索引等
  • 开启慢日志: 默认的情况下,Elasticsearch的查询慢日志和索引慢日志是没有启用的。需要通过设置日志的级别(warn, info, debug, trace)和阀值来开启慢日志。 首先设置日志级别,如下所示将日志级别设置为debug:curl -XPUT –tlsv1.2 –negotiate -k -v -u : ‘https://ip:httpport/_cluster/settings?pretty’ -H ‘Content-Type: application/json’ -d’ { “transient”: { “logger.index.indexing.slowlog”:”DEBUG”, “logger.index.search.slowlog”:”DEBUG” } }’ 设置完日志级别后需要分别设置查询慢日志和索引慢日志的对应日志级别下的阀值,可以在elasticsearch.yml文件里定义这些阀值。没有阀值设置的索引会自动继承在静态配置文件里配置的参数。同时也提供动态API的方式来设置。
    1. 查询慢日志 shard级别的查询慢日志会将慢查询(查询和获取阶段)记录到elasticsearch_cluster_index_search_slowlog.log日志中。 设置查询慢日志各种级别下的阀值,同时也支持多索引(索引名按逗号分隔)和全索引(用*通配符)操作。curl -XPUT –tlsv1.2 –negotiate -k -v -u : ‘https://ip:httport/myindex-001/_settings?pretty’ -H ‘Content-Type: application/json’ -d’ { “index.search.slowlog.threshold.query.warn”: “10s”, “index.search.slowlog.threshold.query.info”: “5s”, “index.search.slowlog.threshold.query.debug”: “2s”, “index.search.slowlog.threshold.query.trace”: “500ms”, “index.search.slowlog.threshold.fetch.warn”: “1s”, “index.search.slowlog.threshold.fetch.info”: “800ms”, “index.search.slowlog.threshold.fetch.debug”: “500ms”, “index.search.slowlog.threshold.fetch.trace”: “200ms”, }’ 说明: index.search.slowlog.threshold.query.*:对应日志级别下的阀值,查询阶段慢于该阀值即打印日志。 index.search.slowlog.threshold.fetch.*:对应日志级别下的阀值,提取阶段慢于该阀值即打印日志。
    2. 索引慢日志 设置索引慢日志各种级别下的阀值,同时也支持多索引(索引名按逗号分隔)和全索引(用*通配符)操作。curl -XPUT –tlsv1.2 –negotiate -k -v -u : ‘https://ip:httpport/myindex-001/_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.source”: “1000” }’ 说明: index.indexing.slowlog.threshold.index.*:对应日志级别下的阀值,索引时间慢于该阀值即打印日志。 index.indexing.slowlog.source:Elasticsearch默认将在慢索引日志中记录_source的前1000个字符,将其设置为false或0将完全跳过记录源,设置为true将记录整个源。

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注