更新时间:2024-04-19 GMT+08:00

查询冷数据性能提升

背景信息

在Kibana的Discover页面的首次查询时,由于此时无任何缓存,导致所有数据均需要从OBS上获取。当命中的文档数量较多时,需要耗费大量的时间从OBS上获取对应的时间字段以及文件元数据。如果将这一部分数据直接缓存在本地,即可大量提升查询性能,解决Discover页面首次查询慢的问题。

前提条件

此特性仅支持在2023年02月后创建的7.6.2和7.10.2版本集群以及OpenSearch集群。

查询冷数据本地缓存API

您可以使用该API查询冷数据本地缓存的相关指标。

请求示例

GET /_frozen_stats/local_cache
GET /_frozen_stats/local_cache/{nodeId}

响应示例

{
   "_nodes" : {
     "total" : 1,
     "successful" : 1,
     "failed" : 0
   },
   "cluster_name" : "elasticsearch",
   "nodes" : {
     "6by3lPy1R3m55Dcq3liK8Q" : {
       "name" : "node-1",
       "transport_address" : "127.0.0.1:9300",
       "host" : "127.0.0.1",
       "ip" : "127.0.0.1",
       "local_cache" : {
         "get_stats" : {
           "get_total_count" : 562,                            //从冷数据本地缓存查询数据的总次数
           "get_hit_count" : 562,                              //从冷数据本地缓存查询数据命中的次数
           "get_miss_count" : 0,                               //从冷数据本地缓存查询数据未命中的次数
           "get_total_ns" : 43849200,                          //从冷数据本地缓存查询数据的总时长
           "get_avg_ns" : 78023                                //从冷数据本地缓存查询数据的平均时长
         },
         "load_stats" : {
           "load_count" : 2,                                    //加载冷数据本地缓存的次数
           "load_total_ms" : 29,                                //加载冷数据本地缓存的总时长
           "load_avg_ms" : 14,                                  //加载冷数据本地缓存的平均时长
           "load_fail_count" : 0,                               //加载冷数据本地缓存的失败次数
           "load_overflow_count" : 0                            //加载冷数据本地缓存时超过缓存池的次数
         },
         "reload_stats" : {
           "reload_count" : 0,                                  //重新生成冷数据本地缓存的次数
           "reload_total_ms" : 0,                               //重新生成冷数据本地缓存的总时长
           "reload_avg_ms" : 0,                                 //重新生成冷数据本地缓存的平均时长
           "reload_fail_count" : 0                              //重新生成冷数据本地缓存的失败次数
         },
         "init_stats" : {
           "init_count" : 0,                                     //初始化冷数据本地缓存的次数
           "init_total_ms" : 0,                                  //初始化冷数据本地缓存的总时长
           "init_avg_ms" : 0,                                    //初始化冷数据本地缓存的平均时长
           "init_fail_count" : 0                                 //初始化冷数据本地缓存的失败次数
         }
       }
     }
   }
 }

配置参数

配置项

类型

单位

取值范围

scope

是否可动态修改

作用

low_cost.local_cache.max.capacity

Integer

10-5000,默认值500。

node

节点上,能够打开的冷数据缓存的最大数量。(每个shard对应一个缓存对象)

说明:
  • 堆内存使用率一直很高,可以尝试降低该值。
  • 如果查询冷数据本地缓存的相关统计指标中load_overflow_count数值一直持续快速增加,建议调大该值。

index.low_cost.local_cache.threshold

Integer

%

0-100,默认值50。

index

启用冷数据本地缓存的阈值。

说明:
  • 如果date类型字段的占比小于此值。启用冷数据本地缓存date类型字段。否则不使用。
  • 如果当前索引的date类型字段占据当前索引的绝大部分数据量,不建议使用此功能。

index.low_cost.local_cache.evict_time

字符串

1d-365d,默认值30d。

index

冷数据本地缓的淘汰时间。根据index.frozen_date(冻结成功的时间)判定。

说明:
  • 如果为旧集群冻结的索引,无index.frozen_date,则根据索引创建时间判定。
  • 建议根据磁盘用量调整淘汰时长,节省磁盘空间。

修改参数

  • 修改low_cost.local_cache.max.capacity
    PUT _cluster/settings
     {
       "persistent": {
         "low_cost.local_cache.max.capacity":1000
       }
     }
  • 修改index.low_cost.local_cache.threshold
    PUT es_write_pref2-00000000021/_settings
     {
     "index.low_cost.local_cache.threshold":20
     }
  • 修改index.low_cost.local_cache.evict_time
    PUT es_write_pref2-00000000021/_settings
     {
     "index.low_cost.local_cache.evict_time":"7d"
     }