Elasticsearch运维系列_ES之max_result_window 寄义-对性能影响及参数调解 ...

打印 上一主题 下一主题

主题 1414|帖子 1414|积分 4242

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
假如你觉得这篇文章能给你带来劳绩,请关注我公众号:



这篇文章重要给大家介绍max_result_window参数及其对性能影响。
Part1 配景形貌

   当前某个业务xxxdb单个索引值较大,逐日单个索引大小在二三百G,当前索引保留15天,假如拉取一个15天的范围周期,会查询到几个T的数据量,并且该索引未做副本,这种大查询会导致ES负载较高,严厉影响性能。
  单日索引大小



   检查发现xxx_access_xxx_xxx 索引使用的索引模版xxx_xxx_access_xxx_template 有个参数max_result_window 比较异常,设置值较大。
    -- 查询xxx_xxxx_access_xxx_template索引模版信息
  1. GET /_template/xxx_xxx_access_xxx_template
  2. -- 上述命令执行结果如下:
  3. {
  4.   "xxx_xxx_access_xxx_template" : {
  5.     "order" : 8,
  6.     "index_patterns" : [
  7.       "xxx_xxx_access_xxx_*"
  8.     ],
  9.     "settings" : {
  10.       "index" : {
  11.         "lifecycle" : {
  12.           "name" : "5d_cold_15d_delete_policy"
  13.         },
  14.         "refresh_interval" : "30s",
  15.         "number_of_shards" : "10",
  16.         "translog" : {
  17.           "sync_interval" : "60s"
  18.         },
  19.         "merge" : {
  20.           "scheduler" : {
  21.             "max_thread_count" : "1"
  22.           },
  23.           "policy" : {
  24.             "max_merged_segment" : "500m"
  25.           }
  26.         },
  27.         "max_result_window" : "1000000",
  28.         "analysis" : {
  29.           "analyzer" : {
  30.             "comma_analyzer" : {
  31.               "filter" : [
  32.                 "lowercase"
  33.               ],
  34.               "char_filter" : [
  35.                 "replace_comma"
  36.               ],
  37.               "type" : "custom",
  38.               "tokenizer" : "standard"
  39.             },
  40.             "file_analyzer" : {
  41.               "filter" : [
  42.                 "lowercase"
  43.               ],
  44.               "char_filter" : [
  45.                 "file_sep"
  46.               ],
  47.               "type" : "custom",
  48.               "tokenizer" : "standard"
  49.             }
  50.           },
  51.           "char_filter" : {
  52.             "file_sep" : {
  53.               "type" : "mapping",
  54.               "mappings" : [
  55.                 "/ => ' '",
  56.                 ". => ' '"
  57.               ]
  58.             },
  59.             "replace_comma" : {
  60.               "type" : "mapping",
  61.               "mappings" : [
  62.                 ". => ' '",
  63.                 ", => ' '",
  64.                 "# => ' '",
  65.                 "$ => ' '",
  66.                 "% => ' '",
  67.                 "' => ' '",
  68.                 "( => ' '",
  69.                 ") => ' '",
  70.                 "* => ' '",
  71.                 "+ => ' '",
  72.                 "- => ' '",
  73.                 "/ => ' '",
  74.                 ": => ' '",
  75.                 "; => ' '",
  76.                 "< => ' '",
  77.                 "= => ' '",
  78.                 "> => ' '",
  79.                 "? => ' '",
  80.                 "@ => ' '",
  81.                 "[ => ' '",
  82.                 "] => ' '",
  83.                 "^ => ' '",
  84.                 "{ => ' '",
  85.                 "} => ' '",
  86.                 "~ => ' '",
  87.                 "` => ' '",
  88.                 "| => ' '",
  89.                 "& => ' '",
  90.                 "! => ' '",
  91.                 "" => ' '",
  92.                 "_ => ' '"
  93.               ]
  94.             }
  95.           }
  96.         },
  97.         "number_of_replicas" : "0"
  98.       }
  99.     },
  100.     "mappings" : {
  101.       "properties" : {
  102.         "schema" : {
  103.           "type" : "text"
  104.         },
  105.         "netSendTime" : {
  106.           "ignore_malformed" : true,
  107.           "type" : "long"
  108.         },
  109.         "checkLengthTime" : {
  110.           "ignore_malformed" : true,
  111.           "type" : "long"
  112.         },
  113.         "routeTime" : {
  114.           "ignore_malformed" : true,
  115.           "type" : "long"
  116.         },
  117.         "type" : {
  118.           "type" : "text"
  119.         },
  120.         "databaseTime" : {
  121.           "ignore_malformed" : true,
  122.           "type" : "long"
  123.         },
  124.         "resultSetSize" : {
  125.           "ignore_malformed" : true,
  126.           "type" : "long"
  127.         },
  128.         "sql" : {
  129.           "analyzer" : "comma_analyzer",
  130.           "type" : "text"
  131.         },
  132.         "minNodeTime" : {
  133.           "ignore_malformed" : true,
  134.           "type" : "long"
  135.         },
  136.         "dbExeTime" : {
  137.           "ignore_malformed" : true,
  138.           "type" : "long"
  139.         },
  140.         "host" : {
  141.           "type" : "text",
  142.           "fields" : {
  143.             "keyword" : {
  144.               "ignore_above" : 256,
  145.               "type" : "keyword"
  146.             }
  147.           }
  148.         },
  149.         "startTime" : {
  150.           "ignore_malformed" : true,
  151.           "type" : "long"
  152.         },
  153.         "sqlRows" : {
  154.           "ignore_malformed" : true,
  155.           "type" : "long"
  156.         },
  157.         "mergeTime" : {
  158.           "ignore_malformed" : true,
  159.           "type" : "long"
  160.         },
  161.         "sqlStartTime" : {
  162.           "ignore_malformed" : true,
  163.           "type" : "long"
  164.         },
  165.         "dataNodeNum" : {
  166.           "ignore_malformed" : true,
  167.           "type" : "long"
  168.         },
  169.         "funcDbTime" : {
  170.           "ignore_malformed" : true,
  171.           "type" : "integer"
  172.         },
  173.         "dataNode" : {
  174.           "type" : "text",
  175.           "fields" : {
  176.             "keyword" : {
  177.               "ignore_above" : 256,
  178.               "type" : "keyword"
  179.             }
  180.           }
  181.         },
  182.         "maxReceiveNodeResultsTime" : {
  183.           "ignore_malformed" : true,
  184.           "type" : "long"
  185.         },
  186.         "MaxNodeTime" : {
  187.           "ignore_malformed" : true,
  188.           "type" : "integer"
  189.         },
  190.         "allTime" : {
  191.           "ignore_malformed" : true,
  192.           "type" : "long"
  193.         },
  194.         "funcRedisTime" : {
  195.           "ignore_malformed" : true,
  196.           "type" : "long"
  197.         },
  198.         "selectRowTime" : {
  199.           "ignore_malformed" : true,
  200.           "type" : "long"
  201.         },
  202.         "fddbTime" : {
  203.           "ignore_malformed" : true,
  204.           "type" : "long"
  205.         },
  206.         "sqlType" : {
  207.           "ignore_malformed" : true,
  208.           "type" : "long"
  209.         },
  210.         "calcTime" : {
  211.           "ignore_malformed" : true,
  212.           "type" : "long"
  213.         },
  214.         "endTime" : {
  215.           "ignore_malformed" : true,
  216.           "type" : "long"
  217.         },
  218.         "minReceiveNodeResultsTime" : {
  219.           "ignore_malformed" : true,
  220.           "type" : "long"
  221.         },
  222.         "extern1" : {
  223.           "ignore_malformed" : true,
  224.           "type" : "long"
  225.         },
  226.         "user" : {
  227.           "type" : "text"
  228.         },
  229.         "executeTime" : {
  230.           "ignore_malformed" : true,
  231.           "type" : "long"
  232.         }
  233.       }
  234.     },
  235.     "aliases" : { }
  236.   }
  237. }
复制代码
1 max_result_window 解释

   通过上面命令可以看到 max_result_window 值设置过大,当前设置为 1000000 (一百万)。
    max_result_window 这个参数是什么意思,是用来做什么的呢?
    max_result_window 是 Elasticsearch 中的一个参数,它决定了可以从单个查询中请求的最大效果窗口的大小。换句话说,它控制了可以通过 from 和 size 参数获取的最大文档数量。这对于防止过度内存使用和性能问题非常紧张,因为请求大量数据会斲丧大量内存并影响集群性能。
  1. 示例:
  2. 如果有一个索引并希望从该索引中检索文档,可以使用 from 和 size 参数来控制分页:
  3. GET /index_name/_search
  4. {
  5.    "from": 0,
  6.    "size": 100
  7. }
  8. 这将返回前 100 个文档。from 参数指定要跳过的文档数,size 参数指定要返回的文档数。
  9. 但如果尝试执行如下操作:
  10. GET /index_name/_search
  11. {
  12.     "from": 10000,
  13.     "size": 100
  14. }
  15. 在默认配置下,这将返回一个错误,因为 from + size 超过了 max_result_window 的限制。
  16. 如果希望更改更大的结果窗口,可以在索引中调整 max_result_window 参数,比如:
  17. PUT /index_name/_settings
  18. {
  19.     "index": {
  20.     "max_result_window": 50000
  21.     }
  22. }
  23. 这将 max_result_window 设置为 50,000。
复制代码
  在 Elasticsearch 7.12.1 版本中,max_result_window 的默认值是 10,000。这意味着默认情况下,您可以请求的效果窗口最大为 10,000 个文档。假如实行请求超过这个限制的效果窗口,Elasticsearch 会返回一个错误。
    max_result_window 支持的最大返回数是 2^31-1,也就是2147483647,生产不建议对 max_result_window 设置过大的值,过大的max_result_window值会对ES带来性能问题,可能会因为值设置过大导致ES内存问题和性能下降。
    可以通过设置 from 和 size 参数可以举行分页查询。例如:from=num_a, size=num_b,则获取的效果是从第 num_a + 1 条到第 num_a + num_b 条数据。
  2 参数调解

根据对上面max_result_window 参数的分析,筹划对 max_result_window值举行调解,将其调解为默认大小。
最简单的方法是通过修改索引模版json信息,将该参数从索引模版删除,调解为默认值,实行如下修改命令:
  1. PUT /_template/xxx_xxx_access_xxx_template
  2. {
  3.     "order" : 8,
  4.     "index_patterns" : [
  5.       "xxx_xxx_access_xxx_*"
  6.     ],
  7.     "settings" : {
  8.       "index" : {
  9.         "lifecycle" : {
  10.           "name" : "5d_cold_15d_delete_policy"
  11.         },
  12.         "refresh_interval" : "30s",
  13.         "number_of_shards" : "10",
  14.         "translog" : {
  15.           "sync_interval" : "60s"
  16.         },
  17.         "merge" : {
  18.           "scheduler" : {
  19.             "max_thread_count" : "1"
  20.           },
  21.           "policy" : {
  22.             "max_merged_segment" : "500m"
  23.           }
  24.         },
  25.         "analysis" : {
  26.           "analyzer" : {
  27.             "comma_analyzer" : {
  28.               "filter" : [
  29.                 "lowercase"
  30.               ],
  31.               "char_filter" : [
  32.                 "replace_comma"
  33.               ],
  34.               "type" : "custom",
  35.               "tokenizer" : "standard"
  36.             },
  37.             "file_analyzer" : {
  38.               "filter" : [
  39.                 "lowercase"
  40.               ],
  41.               "char_filter" : [
  42.                 "file_sep"
  43.               ],
  44.               "type" : "custom",
  45.               "tokenizer" : "standard"
  46.             }
  47.           },
  48.           "char_filter" : {
  49.             "file_sep" : {
  50.               "type" : "mapping",
  51.               "mappings" : [
  52.                 "/ => ' '",
  53.                 ". => ' '"
  54.               ]
  55.             },
  56.             "replace_comma" : {
  57.               "type" : "mapping",
  58.               "mappings" : [
  59.                 ". => ' '",
  60.                 ", => ' '",
  61.                 "# => ' '",
  62.                 "$ => ' '",
  63.                 "% => ' '",
  64.                 "' => ' '",
  65.                 "( => ' '",
  66.                 ") => ' '",
  67.                 "* => ' '",
  68.                 "+ => ' '",
  69.                 "- => ' '",
  70.                 "/ => ' '",
  71.                 ": => ' '",
  72.                 "; => ' '",
  73.                 "< => ' '",
  74.                 "= => ' '",
  75.                 "> => ' '",
  76.                 "? => ' '",
  77.                 "@ => ' '",
  78.                 "[ => ' '",
  79.                 "] => ' '",
  80.                 "^ => ' '",
  81.                 "{ => ' '",
  82.                 "} => ' '",
  83.                 "~ => ' '",
  84.                 "` => ' '",
  85.                 "| => ' '",
  86.                 "& => ' '",
  87.                 "! => ' '",
  88.                 "" => ' '",
  89.                 "_ => ' '"
  90.               ]
  91.             }
  92.           }
  93.         },
  94.         "number_of_replicas" : "0"
  95.       }
  96.     },
  97.     "mappings" : {
  98.       "properties" : {
  99.         "schema" : {
  100.           "type" : "text"
  101.         },
  102.         "netSendTime" : {
  103.           "ignore_malformed" : true,
  104.           "type" : "long"
  105.         },
  106.         "checkLengthTime" : {
  107.           "ignore_malformed" : true,
  108.           "type" : "long"
  109.         },
  110.         "routeTime" : {
  111.           "ignore_malformed" : true,
  112.           "type" : "long"
  113.         },
  114.         "type" : {
  115.           "type" : "text"
  116.         },
  117.         "databaseTime" : {
  118.           "ignore_malformed" : true,
  119.           "type" : "long"
  120.         },
  121.         "resultSetSize" : {
  122.           "ignore_malformed" : true,
  123.           "type" : "long"
  124.         },
  125.         "sql" : {
  126.           "analyzer" : "comma_analyzer",
  127.           "type" : "text"
  128.         },
  129.         "minNodeTime" : {
  130.           "ignore_malformed" : true,
  131.           "type" : "long"
  132.         },
  133.         "dbExeTime" : {
  134.           "ignore_malformed" : true,
  135.           "type" : "long"
  136.         },
  137.         "host" : {
  138.           "type" : "text",
  139.           "fields" : {
  140.             "keyword" : {
  141.               "ignore_above" : 256,
  142.               "type" : "keyword"
  143.             }
  144.           }
  145.         },
  146.         "startTime" : {
  147.           "ignore_malformed" : true,
  148.           "type" : "long"
  149.         },
  150.         "sqlRows" : {
  151.           "ignore_malformed" : true,
  152.           "type" : "long"
  153.         },
  154.         "mergeTime" : {
  155.           "ignore_malformed" : true,
  156.           "type" : "long"
  157.         },
  158.         "sqlStartTime" : {
  159.           "ignore_malformed" : true,
  160.           "type" : "long"
  161.         },
  162.         "dataNodeNum" : {
  163.           "ignore_malformed" : true,
  164.           "type" : "long"
  165.         },
  166.         "funcDbTime" : {
  167.           "ignore_malformed" : true,
  168.           "type" : "integer"
  169.         },
  170.         "dataNode" : {
  171.           "type" : "text",
  172.           "fields" : {
  173.             "keyword" : {
  174.               "ignore_above" : 256,
  175.               "type" : "keyword"
  176.             }
  177.           }
  178.         },
  179.         "maxReceiveNodeResultsTime" : {
  180.           "ignore_malformed" : true,
  181.           "type" : "long"
  182.         },
  183.         "MaxNodeTime" : {
  184.           "ignore_malformed" : true,
  185.           "type" : "integer"
  186.         },
  187.         "allTime" : {
  188.           "ignore_malformed" : true,
  189.           "type" : "long"
  190.         },
  191.         "funcRedisTime" : {
  192.           "ignore_malformed" : true,
  193.           "type" : "long"
  194.         },
  195.         "selectRowTime" : {
  196.           "ignore_malformed" : true,
  197.           "type" : "long"
  198.         },
  199.         "fddbTime" : {
  200.           "ignore_malformed" : true,
  201.           "type" : "long"
  202.         },
  203.         "sqlType" : {
  204.           "ignore_malformed" : true,
  205.           "type" : "long"
  206.         },
  207.         "calcTime" : {
  208.           "ignore_malformed" : true,
  209.           "type" : "long"
  210.         },
  211.         "endTime" : {
  212.           "ignore_malformed" : true,
  213.           "type" : "long"
  214.         },
  215.         "minReceiveNodeResultsTime" : {
  216.           "ignore_malformed" : true,
  217.           "type" : "long"
  218.         },
  219.         "extern1" : {
  220.           "ignore_malformed" : true,
  221.           "type" : "long"
  222.         },
  223.         "user" : {
  224.           "type" : "text"
  225.         },
  226.         "executeTime" : {
  227.           "ignore_malformed" : true,
  228.           "type" : "long"
  229.         }
  230.       }
  231.     },
  232.     "aliases" : { }
  233.   }
复制代码
  除了以上方法,还可以通过使用 PUT Template API在操作系统上实行。 今天带大家分享了max_result_window参数寄义,后续将会给大家带来更多分享。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

张裕

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表