Elasticsearch 性能調(diào)優(yōu)指南——推薦實(shí)戰(zhàn) DSL
本文是在以下 6 篇基礎(chǔ)上的繼續(xù)擴(kuò)展版本,不求大而全,只求對(duì)實(shí)戰(zhàn)有幫助。
1、干貨 | Elasticsearch 運(yùn)維實(shí)戰(zhàn)常用命令清單
2、干貨 | Elasticsearch Top10 監(jiān)控指標(biāo)
3、你不得不關(guān)注的 Elasticsearch Top X 關(guān)鍵指標(biāo)
4、干貨 | Elasticsearch 開(kāi)發(fā)實(shí)戰(zhàn)常用命令清單
5、干貨 | Elasticsearch開(kāi)發(fā)人員最佳實(shí)戰(zhàn)指南
6、Elasitcsearch 開(kāi)發(fā)運(yùn)維常用命令集錦
1、未分配分片查看
GET _cat/shards?v&h=index,shard,prirep,state,unassigned.reason&s=state:asc
2、動(dòng)態(tài)調(diào)整副本數(shù)
PUT my-index-2021.05.30-000002/_settings
{"number_of_replicas": 0}
ps:主分片不可以修改(除非shrink),但:副本可以動(dòng)態(tài)調(diào)整大小。
3、重新打開(kāi)分片分配策略
PUT /_cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "all"
}
}
4、手動(dòng)移動(dòng)未分配的分片
POST /_cluster/reroute
{
"commands": [
{
"move": {
"index": "test",
"shard": 0,
"from_node": "node1",
"to_node": "node2"
}
},
{
"allocate_replica": {
"index": "test",
"shard": 1,
"node": "node3"
}
}
]
}
5、查看磁盤(pán)使用率
GET /_cat/allocation?v
使用率大于等于85%,知道已經(jīng)達(dá)到警戒水位線了,要預(yù)警。
6、查看各個(gè)節(jié)點(diǎn)的版本號(hào)
GET /_cat/nodes?v&h=host,name,version
集群多節(jié)點(diǎn)版本不一致,可能會(huì)引發(fā)各種未知異常。
7、檢索性能調(diào)優(yōu)實(shí)戰(zhàn)
7.1 慢日志設(shè)置
PUT /my-index-000001/_settings
{
"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",
"index.search.slowlog.threshold.fetch.warn": "1s",
"index.search.slowlog.threshold.fetch.info": "800ms",
"index.search.slowlog.threshold.fetch.debug": "500ms",
"index.search.slowlog.threshold.fetch.trace": "200ms",
"index.search.slowlog.level": "info"
}
7.2 構(gòu)建Mapping 設(shè)置路由
PUT my-index-000002
{
"mappings": {
"_routing": {
"required": true
}
}
}
7.3 段合并
POST /my-index-000001/_forcemerge
8、寫(xiě)入優(yōu)化篇
8.1 批量寫(xiě)入
POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
8.2 增加刷新頻率
PUT /my-index-000001/_settings
{
"index" : {
"refresh_interval" : "30s"
}
}
8.3 副本設(shè)置為0,提升寫(xiě)入
PUT my-index-000001/_settings
{
"number_of_replicas": 0
}
8.4 translog 異步刷盤(pán)
PUT my-index-2021.06.03/_settings
{
"index": {
"translog": {
"durability": "async"
}
}
}
9、堆內(nèi)存調(diào)優(yōu)實(shí)戰(zhàn)
在 jvm.option 配置文件中(不支持動(dòng)態(tài)調(diào)整,需要重啟后生效)
ES_HEAP_SIZE=DESIRED_SIZE (e.g. "3g")
10、磁盤(pán)不足解決方案
磁盤(pán)的三個(gè)警戒水位線需要再一次強(qiáng)調(diào)。如果 Elasticsearch 集群節(jié)點(diǎn)的磁盤(pán)空間不足,則會(huì)影響集群性能。
一旦可用存儲(chǔ)空間低于特定閾值限制,它將開(kāi)始阻止寫(xiě)入操作,進(jìn)而影響數(shù)據(jù)進(jìn)入集群。那么,如何擴(kuò)展呢?
三個(gè)警戒水位線推薦閱讀:你不得不關(guān)注的 Elasticsearch Top X 關(guān)鍵指標(biāo)。
小結(jié)

Elasticsearch性能優(yōu)化實(shí)戰(zhàn)指南 讓Elasticsearch飛起來(lái)!——性能優(yōu)化實(shí)踐干貨 Elasticsearch大文件檢索性能提升20倍實(shí)踐(干貨) Elasticsearch 聚合性能優(yōu)化六大猛招 Elasticsearch 高基數(shù)聚合性能提升3倍,改動(dòng)了什么?
參考
elasticsearch_monitoring_cheatsheet.pdf
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/modules-cluster.html#disk-based-shard-allocation
https://www.elastic.co/guide/en/elasticsearch/reference/7.14/how-to.html
推薦

