elasticsearch - 优化 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#节点角色)
解决方案
设置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
推荐阅读
- unity3d - Unity 截止着色器具有纹理的所有通道始终为 0
- unit-testing - 需要 CDI 容器的单元测试导致 java.lang.IllegalStateException: Unable to access CDI
- c - AF_XDP-Socket 与 Linux 套接字:为什么我的 AF-XDP 套接字会丢失数据包,而通用 linux 套接字却不会?
- html - 标题位置:粘性背景颜色问题
- r - 如何快速确定我应该使用哪种类型的绘图?
- java - 从 int 中删除所有奇数位的递归方法
- julia - 在 Julia 中显示函数的所有方法
- mysql - 无法通过密钥环文件启用加密
- python - 无法在 Windows 10 中打开 Chrome Webdriver
- angularjs - 图像不加载 AngularJS WebStorm