gpt4 book ai didi

elasticsearch - Elasticsearch服务器超时

转载 作者:行者123 更新时间:2023-12-03 01:13:20 25 4
gpt4 key购买 nike

我正在8核/ 16G RAM Qbox服务器上运行ES节点。
我正在做一些索引和搜索操作。索引(最大5 /秒),搜索(最大1e4 /秒)。我的索引大约有2M记录了1.2G的数据。搜索查询大约需要300毫秒的中位数。
我对服务器为何无法处理如此低的流量感到困惑。
贝娄是我的映射,也是我要发送的查询:
对应:

{
"orders_prod-1586935194034930": {
"mappings": {
"_doc": {
"dynamic": "true",
"properties": {
"address_id": {
"type": "long"
},
"card_4_digits": {
"type": "keyword"
},
"card_type": {
"type": "keyword"
},
"channel_id": {
"type": "integer"
},
"created_at": {
"type": "date",
"format": "strict_date_hour_minute_second"
},
"customer_email": {
"type": "keyword"
},
"customer_name": {
"type": "keyword"
},
"customer_name_text": {
"type": "text"
},
"customer_phone": {
"type": "keyword"
},
"delivery_address": {
"type": "keyword"
},
"favorite": {
"type": "boolean"
},
"has_promo_discount": {
"type": "boolean"
},
"id": {
"type": "long"
},
"ivr_code": {
"type": "keyword"
},
"order_at": {
"type": "date",
"format": "strict_date_hour_minute_second"
},
"order_type": {
"type": "keyword"
},
"payment_type": {
"type": "keyword"
},
"placed_at": {
"type": "date",
"format": "strict_date_hour_minute_second"
},
"restaurant_id": {
"type": "integer"
},
"short_uuid": {
"type": "keyword"
},
"state": {
"type": "keyword"
},
"subtotal": {
"type": "integer"
},
"total": {
"type": "integer"
},
"updated_at": {
"type": "date",
"format": "strict_date_hour_minute_second"
},
"user_id": {
"type": "integer"
},
"uuid": {
"type": "keyword"
},
"workflow_color": {
"type": "keyword"
},
"workflow_node_id": {
"type": "keyword"
},
"workflow_node_name": {
"type": "keyword"
},
"workflow_tag": {
"type": "keyword"
}
}
}
}
}
}
查询:
{
"from":0,
"size":20,
"query":{
"bool":{
"must":[
{
"bool":{
"should":[
{
"term":{
"user_id":{
"value":308612,
"boost":1.0
}
}
},
{
"term":{
"restaurant_id":{
"value":8898,
"boost":1.0
}
}
},
{
"term":{
"restaurant_id":{
"value":4164,
"boost":1.0
}
}
},
{
"term":{
"restaurant_id":{
"value":4679,
"boost":1.0
}
}
}
],
"adjust_pure_negative":true,
"minimum_should_match":"1",
"boost":1.0
}
}
],
"must_not":[
{
"term":{
"state":{
"value":"created",
"boost":1.0
}
}
}
],
"should":[
{
"bool":{
"should":[
{
"term":{
"state":{
"value":"executing",
"boost":1.0
}
}
},
{
"term":{
"state":{
"value":"missed",
"boost":1.0
}
}
}
],
"adjust_pure_negative":true,
"minimum_should_match":"1",
"boost":1.0
}
}
],
"adjust_pure_negative":true,
"minimum_should_match":"1",
"boost":1.0
}
},
"_source":{
"includes":[
"short_uuid",
"uuid",
"state",
"restaurant_id",
"channel_id",
"customer_name_text",
"total",
"payment_type",
"card_type",
"order_at"
],
"excludes":[

]
},
"sort":[
{
"order_at":{
"order":"asc"
}
},
{
"created_at":{
"order":"desc"
}
}
]
}
有什么我可以做的吗?也许查询根本不是最优的。我真的需要一些提示。
另一个信息。我在ES日志中看到的崩溃:
[2020-08-19T12:03:16,912][DEBUG][o.e.a.s.TransportSearchAction] [s-f8cb43563fe76e4a-1] [orders_prod-1586935194034930][3], node[xkui_jc_TZ20-IJJ4bo1TQ], [P], s[STARTED], a[id=vmh_Z8BHTsGpLoUoseuKYw]: Failed to execute [SearchRequest{searchType=QUERY_THEN_FETCH, indices=[orders_prod], indicesOptions=IndicesOptions[ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false], types=[_doc], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=10, batchedReduceSize=512, preFilterShardSize=128, allowPartialSearchResults=true, source={"from":0,"size":20,"query":{"bool":{"must":[{"bool":{"should":[{"term":{"user_id":{"value":18048,"boost":1.0}}},{"term":{"restaurant_id":{"value":800,"boost":1.0}}}],"adjust_pure_negative":true,"minimum_should_match":"1","boost":1.0}},{"term":{"state":{"value":"canceled","boost":1.0}}},{"range":{"order_at":{"from":"2020-08-19T12:02:09","to":"2020-09-19T12:02:09","include_lower":true,"include_upper":true,"boost":1.0}}}],"must_not":[{"term":{"state":{"value":"created","boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["short_uuid","uuid","state","restaurant_id","channel_id","customer_name_text","total","payment_type","card_type","order_at"],"excludes":[]},"sort":[{"order_at":{"order":"asc"}},{"created_at":{"order":"desc"}}]}}] lastShard [true]
org.elasticsearch.transport.RemoteTransportException: [s-f8cb43563fe76e4a-0][10.244.23.158:9300][indices:data/read/search[phase/query]]
Caused by: org.elasticsearch.common.util.concurrent.EsRejectedExecutionException: rejected execution of org.elasticsearch.common.util.concurrent.TimedRunnable@7ea74209 on QueueResizingEsThreadPoolExecutor[name = s-f8cb43563fe76e4a-0/search, queue capacity = 1000, min queue capacity = 1000, max queue capacity = 1000, frame size = 2000, targeted response rate = 1s, task execution EWMA = 625.6ms, adjustment amount = 50, org.elasticsearch.common.util.concurrent.QueueResizingEsThreadPoolExecutor@26e28e[Running, pool size = 7, active threads = 7, queued tasks = 1000, completed tasks = 144056]]
at org.elasticsearch.common.util.concurrent.EsAbortPolicy.rejectedExecution(EsAbortPolicy.java:48) ~[elasticsearch-6.4.3.jar:6.4.3]
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830) ~[?:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379) ~[?:1.8.0_201]
at org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor.doExecute(EsThreadPoolExecutor.java:98) ~[elasticsearch-6.4.3.jar:6.4.3]

最佳答案

你说:

Search query takes around 300ms median. I am puzzled on why the servercan not handle even such a low traffic.


我想您觉得300ms太长了。这并不意味着服务器不处理流量,只是查询有点慢。
首先,您的索引有多少个分片。分片大小的目标应为50Gb左右。因此,如果此1.2GB索引具有多个分片和1个副本,那就太多了。
如果可以为此索引计划维护,则应使用适当数量的分片重新索引并强制合并。
关于您的映射,没有很多更改要做。
通常,ID仅用于严格的相等性,因此我们过去将其映射为关键字,而不是整数(user_id,id,channel_id,address_id等),但实际上不会对perfs产生敏感影响
如果您使用的是最近的Elasticsearch,而不使用分数,则在重新编制索引时,可以考虑对order_at和created_at字段进行索引排序。它应该有助于节省时间。
https://www.elastic.co/guide/en/elasticsearch/reference/master/index-modules-index-sorting.html
在查询本身上:
您应该考虑使用过滤器。
过滤器不影响得分,并且可在 flex 和OS端进行缓存。
在您的用例中,整个索引可以保留在RAM中。这可以带来巨大的变化。
您应该具有类似以下的行为(必须经过测试):
{
"size": 20,
"query": {
"bool": {
"filter": {
"bool": {
"should": [
{
"term": {
"restaurant_id": "8898"
}
},
{
"term": {
"restaurant_id": "4164"
}
},
{
"term": {
"restaurant_id": "4679"
}
},
{
"term": {
"user_id": "308612"
}
},
{
"term": {
"state": "executing"
}
},
{
"term": {
"state": "missed"
}
}
],
"minimum_should_match": "1",
"must_not": [
{
"term": {
"state": "created"
}
}
]
}
}
}
},
"_source": [
"short_uuid",
"uuid",
"state",
"restaurant_id",
"channel_id",
"customer_name_text",
"total",
"payment_type",
"card_type",
"order_at"
],
"sort": [
{
"order_at": {
"order": "asc"
}
},
{
"created_at": {
"order": "desc"
}
}
]
}
如果不使用_score,则可以使用固定分数查询来避免 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html的开销

关于elasticsearch - Elasticsearch服务器超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63484734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com