elasticsearch,Performance,elasticsearch" /> elasticsearch,Performance,elasticsearch" />

Performance 弹性搜索速度问题

Performance 弹性搜索速度问题,performance,elasticsearch,Performance,elasticsearch,我们正在使用ElasticSearch搜索15万条记录。这些记录被分成不同的索引大小,其中一些索引有150万条记录 我们有足够的RAM 80 GB,60 GB的整个索引都适合RAM。根据ElasticSearch的响应时间统计,查询执行耗时7毫秒,但我们从ElasticSearch获得的结果耗时300毫秒。这里怎么了?我们可以在哪里寻找,我们的时间将走向何方 ES设置: 2 Nodes on 2 different hosts Each index has 1 primary shard we

我们正在使用ElasticSearch搜索15万条记录。这些记录被分成不同的索引大小,其中一些索引有150万条记录

我们有足够的RAM 80 GB,60 GB的整个索引都适合RAM。根据ElasticSearch的响应时间统计,查询执行耗时7毫秒,但我们从ElasticSearch获得的结果耗时300毫秒。这里怎么了?我们可以在哪里寻找,我们的时间将走向何方

ES设置:

2 Nodes on 2 different hosts

Each index has 1 primary shard we have 2 shards each index 

3,762 Total Shards

3,762 Successful Shards

85 Indices

20,347,989 Documents

40.5GB Size

elasticsearch.yml

index.cache.field.type: soft

indices.cache.filter.size: 50%

index.fielddata.cache: soft

index.cache.field.expire: 60m

indices.fielddata.cache.size: 50%

indices.fielddata.cache.expire : 60m

index.store.type: mmapfs

transport.tcp.compress: true;

bootstrap.mlockall: true

index.search.slowlog.threshold.query.warn: 10s

index.search.slowlog.threshold.query.info: 5s

index.search.slowlog.threshold.query.debug: 2s

index.search.slowlog.threshold.query.trace: 500ms
例如:我们有一个国家DE的索引,有150万个文档。此索引有2个碎片

启动ES:

/usr/lib/jvm/java-7-openjdk-amd64//bin/java -Xms32g -Xmx32g -Xss256k -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -Delasticsearch -Des.pidfile=/var/run/elasticsearch.pid -Des.path.home=/usr/share/elasticsearch -cp :/usr/share/elasticsearch/lib/elasticsearch-1.1.2.jar:/usr/share/elasticsearch/lib/*:/usr/share/elasticsearch/lib/sigar/* -Des.default.config=/etc/elasticsearch/elasticsearch.yml -Des.default.path.home=/usr/share/elasticsearch -Des.default.path.logs=/var/log/elasticsearch -Des.default.path.data=/var/lib/elasticsearch -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=/etc/elasticsearch org.elasticsearch.bootstrap.Elasticsearch
操作系统:

示例查询:搜索某个城市,我们在其中向ES提供位置\u id:

{
    "query": {
        "match_all": {}
    },
    "sort": {},
    "facets": {
        "location_id": {
            "facet_filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "sponsored": [
                                1,
                                0
                            ]
                        }
                    }, {
                        "geo_distance": {
                            "distance": "50km",
                            "geo_point": {
                                "lat": -33.42628,
                                "lon": -70.56656
                            }
                        }
                    }]
                }
            },
            "terms": {
                "field": "location_facet",
                "all_terms": true,
                "size": 100,
                "script": "doc['geo_point'].empty ? null : ceil(doc['geo_point'].arcDistanceInKm(-33.42628,    -70.56656)) + '|' + doc['location_facet'].value\n + '|' + doc['location_id'].value"
            }
        },
        "company_id": {
            "facet_filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "sponsored": [
                                1,
                                0
                            ]
                        }
                    }, {
                        "geo_distance": {
                            "distance": "50km",
                            "geo_point": {
                                "lat": -33.42628,
                                "lon": -70.56656
                            }
                        }
                    }, {
                        "terms": {
                            "location_id": [
                                25717
                            ]
                        }
                    }]
                }
            },
            "terms": {
                "field": "company_facet",
                "order": "count",
                "script": "doc['company_facet'].value + '|' + doc['company_id'].value"
            }
        },
        "job_type_id": {
            "facet_filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "sponsored": [
                                1,
                                0
                            ]
                        }
                    }, {
                        "geo_distance": {
                            "distance": "50km",
                            "geo_point": {
                                "lat": -33.42628,
                                "lon": -70.56656
                            }
                        }
                    }]
                }
            },
            "terms": {
                "field": "jobtype_facet",
                "order": "term",
                "all_terms": true
            }
        }
    },
    "filter": {},
    "size": 10,
    "from": 0,
    "explain": false,
    "highlight": {
        "order": "score",
        "require_field_match": false,
        "pre_tags": [
            "<b>"
        ],
        "post_tags": [
            "</b>"
        ],
        "fields": {
            "description": {
                "type": "fvh",
                "force_source": true,
                "no_match_size": 200,
                "index_options": "offsets",
                "fragment_size": 200,
                "number_of_fragments": 2,
                "matched_fields": [
                    "description",
                    "title"
                ]
            }
        }
    }
}
{
“查询”:{
“全部匹配”:{}
},
“排序”:{},
“方面”:{
“位置标识”:{
“面_过滤器”:{
“布尔”:{
“必须”:[{
“条款”:{
“赞助”:[
1.
0
]
}
}, {
“地理距离”:{
“距离”:“50公里”,
“地理点”:{
“lat”:-33.42628,
“lon”:-70.56656
}
}
}]
}
},
“条款”:{
“字段”:“位置”,
“所有术语”:正确,
“尺寸”:100,
“脚本”:“doc['geo_-point'].empty?null:ceil(doc['geo_-point'].arcdanceinkm(-33.42628,-70.56656))+'|'+doc['location_-facet'].value\n+'|'+doc['location_-id'].value”
}
},
“公司id”:{
“面_过滤器”:{
“布尔”:{
“必须”:[{
“条款”:{
“赞助”:[
1.
0
]
}
}, {
“地理距离”:{
“距离”:“50公里”,
“地理点”:{
“lat”:-33.42628,
“lon”:-70.56656
}
}
}, {
“条款”:{
“位置标识”:[
25717
]
}
}]
}
},
“条款”:{
“字段”:“公司”,
“订单”:“计数”,
“脚本”:“doc['company_facet'].value+'|'+doc['company_id'].value”
}
},
“作业类型\u id”:{
“面_过滤器”:{
“布尔”:{
“必须”:[{
“条款”:{
“赞助”:[
1.
0
]
}
}, {
“地理距离”:{
“距离”:“50公里”,
“地理点”:{
“lat”:-33.42628,
“lon”:-70.56656
}
}
}]
}
},
“条款”:{
“字段”:“作业类型”,
“订单”:“期限”,
“所有术语”:正确
}
}
},
“筛选器”:{},
“尺寸”:10,
“from”:0,
“解释”:错误,
“亮点”:{
“顺序”:“得分”,
“要求字段匹配”:false,
“pre_标签”:[
""
],
“post_标签”:[
""
],
“字段”:{
“说明”:{
“类型”:“fvh”,
“力量来源”:没错,
“无匹配尺寸”:200,
“索引选项”:“偏移量”,
“碎片大小”:200,
“碎片的数量”:2,
“匹配的_字段”:[
“说明”,
“标题”
]
}
}
}
}

此查询的响应时间:>400ms,非常慢。我们也禁用了面,但没有任何更改。

对于单点,“geo_bounding_box”过滤器可能比“geo_distance”过滤器更快。

很难这样说。您应该检查以下内容:*网络延迟如何?*有效负载大,网络传输需要时间吗?*你在使用HTTP吗?尝试Thrift模块,因为您将能够利用TCP的较低开销和Thrift的压缩。了解更多有关集群的信息将很有帮助。有多少节点?有多少个碎片(主碎片和副本碎片)?你的JVM设置是什么?CPU和核心数?磁盘空间?磁盘类型?您是否在查询期间测量CPU和磁盘性能?您是同时插入的吗?你从哪里得到7毫秒和300毫秒的计时?@vaidik:谢谢你的快速响应!我们没有任何延迟问题。我们的服务器位于专用网络中。我还测试了来自外部服务器的请求,下载时间仅为9ms。返回文档的大小为47300字节。真正的问题来自ES,因为在响应中返回的是花费的时间。@John Petrone:谢谢您的快速响应。我会把你需要的资料寄给你。我认为这是ES中的一些设置问题,因为我们在文档中有不同大小的不同索引,但实际上我们使用相同数量的碎片=2。例如,一个索引有150万行。你认为2个碎片要少吗?一个多大的碎片
{
    "query": {
        "match_all": {}
    },
    "sort": {},
    "facets": {
        "location_id": {
            "facet_filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "sponsored": [
                                1,
                                0
                            ]
                        }
                    }, {
                        "geo_distance": {
                            "distance": "50km",
                            "geo_point": {
                                "lat": -33.42628,
                                "lon": -70.56656
                            }
                        }
                    }]
                }
            },
            "terms": {
                "field": "location_facet",
                "all_terms": true,
                "size": 100,
                "script": "doc['geo_point'].empty ? null : ceil(doc['geo_point'].arcDistanceInKm(-33.42628,    -70.56656)) + '|' + doc['location_facet'].value\n + '|' + doc['location_id'].value"
            }
        },
        "company_id": {
            "facet_filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "sponsored": [
                                1,
                                0
                            ]
                        }
                    }, {
                        "geo_distance": {
                            "distance": "50km",
                            "geo_point": {
                                "lat": -33.42628,
                                "lon": -70.56656
                            }
                        }
                    }, {
                        "terms": {
                            "location_id": [
                                25717
                            ]
                        }
                    }]
                }
            },
            "terms": {
                "field": "company_facet",
                "order": "count",
                "script": "doc['company_facet'].value + '|' + doc['company_id'].value"
            }
        },
        "job_type_id": {
            "facet_filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "sponsored": [
                                1,
                                0
                            ]
                        }
                    }, {
                        "geo_distance": {
                            "distance": "50km",
                            "geo_point": {
                                "lat": -33.42628,
                                "lon": -70.56656
                            }
                        }
                    }]
                }
            },
            "terms": {
                "field": "jobtype_facet",
                "order": "term",
                "all_terms": true
            }
        }
    },
    "filter": {},
    "size": 10,
    "from": 0,
    "explain": false,
    "highlight": {
        "order": "score",
        "require_field_match": false,
        "pre_tags": [
            "<b>"
        ],
        "post_tags": [
            "</b>"
        ],
        "fields": {
            "description": {
                "type": "fvh",
                "force_source": true,
                "no_match_size": 200,
                "index_options": "offsets",
                "fragment_size": 200,
                "number_of_fragments": 2,
                "matched_fields": [
                    "description",
                    "title"
                ]
            }
        }
    }
}