Elasticsearch高CPU使用率和查询响应时间

时间:2019-07-16 13:58:51

标签: elasticsearch search cpu-usage heap-memory

我一直在构建基于Elasticsearch Service的搜索功能。 我正在使用的索引映射是:

curl -X PUT "localhost:9200/cast_tag_added" -H 'Content-Type: application/json' -d'
{
  "settings": {
   "analysis": {
    "analyzer": {
     "analyzer_title": {
      "tokenizer": "tokenizer_title",
      "filter": [
       "lowercase",
       "asciifolding",
       "trim"
      ]
     },
     "tokenizer": {
      "tokenizer_title": {
       "type": "edge_ngram",
       "min_gram": 2,
       "max_gram": 20,
       "token_chars": [
        "letter",
        "digit"
       ]
      }
     }
    }
  },

  "mappings": {
   "_doc": {
    "properties": {
     "name": {
      "type": "text",
      "index": "true",
      "analyzer": "analyzer_title",
      "search_analyzer": "analyzer_search"
     },
     "id": {
      "type": "long",
      "index":"false"
     },
     "ratings": {
      "type" : "double",
      "index" : "false"
      }, 
     }   
   }
  }
 }
}

存储的样本数据为:

{
    "name": "Die Hard" 
    "id": 12345
}

样本查询:

{
    "query": {
            "function_score": {
                "query": {
                    "bool": {
                        "should": [{
                            "match": {
                                "name": {
                                    "query": "die",
                                    "fuzziness": "AUTO",
                                    "operator": "and",
                                    "boost": 2
                                }
                            }
                        }, {
                            "match_phrase": {
                                "name": {
                                    "query": "die",
                                    "boost": 4
                                }
                            }
                        }
                },
                "field_value_factor": {
                    "field": "ratings",
                    "modifier": "log1p",
                    "missing": 1
                }
            }
        },
        "explain" : true
    }
}

但是在测试时,我发现查询吞吐量太低(大约24),并且查询响应延迟也太长(平均大约8秒)。我添加了以下设置以获取慢速日志查询:

{
"index.search.slowlog.threshold.query.warn": "0ms",
"index.search.slowlog.threshold.query.info": "0ms",
"index.search.slowlog.threshold.query.debug": "0ms",
"index.search.slowlog.threshold.query.trace": "0ms",
"index.search.slowlog.threshold.fetch.warn": "0ms",
"index.search.slowlog.threshold.fetch.info": "0ms",
"index.search.slowlog.threshold.fetch.debug": "0ms",
"index.search.slowlog.threshold.fetch.trace": "0ms"
}

这给了我所有正在运行的查询的响应时间。 对于每个查询,我在 my-application_index_search_slowlog.log 文件中看到的响应时间都非常短。对于所有查询,它的范围在几微秒到1或2毫秒之间。示例:

[2019-07-16T05:24:06,264][WARN ][index.search.slowlog.query] [node-1] [cast_tag_added][1] took[892micros], took_millis[0], total_hits[676], types[], stats[], search_type[QUERY_THEN_FETCH], total_shards[5], source[<the search query goes here>], id[],

即使日志中显示的响应时间较短,也无法弄清为什么查询响应延迟如此之高。还注意到,在Elasticsearch服务器上开始测试后几秒钟,CPU利用率会飙升至100%。

0 个答案:

没有答案
相关问题