美文网首页
ES默认延迟写入引发的惨案

ES默认延迟写入引发的惨案

作者: 天冷请穿衣 | 来源:发表于2021-02-01 16:44 被阅读0次

造成的困扰:
es在index后有一个refresh_interval默认1秒,在这个时间间隔内search是不可见的。起初并不知道这个特性,导致应用了es保存数据的业务在存储数据后立即读取却取出不到的问题。

存入数据:
19:09:27上传了一条,19:09:29上传了两条数据:


1s内立即取回,取到的是19:09:27上传的数据:


解决:
将index的refresh_interval值调小:

{
  "settings": {
    "index": {  
      ...
      "refresh_interval": "100ms",
      ...
    }
  }
}

不过,生产环境最好不要把这个值设置得太小,因为会影响系统的性能:

...don’t do a manual refresh every time you index a document in production; it will hurt your performance. Instead, your application needs to be aware of the near real-time nature of Elasticsearch and make allowances for it.

参考

追记:
refresh_interval是索引的属性值,不要和代码里中bulk的FlushInterval值混淆了。

相关文章

网友评论

      本文标题:ES默认延迟写入引发的惨案

      本文链接:https://www.haomeiwen.com/subject/xsgmoktx.html