首页 > 解决方案 > 优化 Elasticsearch 写入减慢读取

问题描述

我有一个 Flink 工作,每秒将数千个文档批量写入/插入到 Elasticsearch 上。每次我查询时,大约需要 10-20 秒才能得到响应。

我有第二个索引,它在同一个集群上完全相同并且同样完整,但是现在该索引上的写入被拒绝为 0。当我查询时,需要几毫秒才能得到响应。

即注销查询需要几毫秒。写入查询需要 10-20 秒。

CPU 利用率 ~10%,JVM 内存压力 ~70%。ES 7.8。

这样看来,对分片的写入会以某种方式减慢读取速度。这很奇怪,"profile": true因为它给了我毫秒级的查询时间,但took(总请求时间)就像我看到的那样以秒为单位。

我的问题是为什么会发生这种情况,我该如何优化它?

(我确实想过也许我可以拥有只读副本节点,但 ES 不支持只读副本节点类型https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#节点角色

标签: elasticsearch

解决方案


设置refresh_interval为 1s 似乎已经解决了这个问题。如果有人解释为什么我会很感激。

curl -X PUT "host/index/_settings?pretty&human=true" -H 'Content-Type: application/json' -d'
{
  "index" : {
    "refresh_interval" : "1s"
  }
}

编辑:

除非明确设置,否则刷新率会根据读取负载动态变化。

默认情况下,Elasticsearch 每秒定期刷新索引,但仅在最近 30 秒内收到一个或多个搜索请求的索引上。您可以使用 index.refresh_interval 设置更改此默认间隔。

https://www.elastic.co/guide/en/elasticsearch/reference/7.10/indices-refresh.html#refresh-api-desc


推荐阅读