1. 程式人生 > >ElasticSearch 性能調優筆記

ElasticSearch 性能調優筆記

文件 超時 並且 get conf 性能 test ESS fresh

一下內容來源於網絡

對於不同的字段禁用 norms 和 doc_values
如果以上建議適用,還需要檢查字段是否啟用了 norms 和 doc_values。通常只用於過濾而不需要進行打分(匹配度打分)的字段,可以直接禁用 norms 。不用於排序或者聚合的字段可以禁用 doc_values 。註意,如果在已有的 index 做這些變更,是需要對 index 做 reindex的動作。


增加 refresh_interval 刷新的間隔時間
index.refresh_interval的默認值是 1s,這迫使Elasticsearch集群每秒創建一個新的 segment (可以理解為Lucene 的索引文件)。增加這個值,例如30s,可以允許更大的segment寫入,減後以後的segment合並壓力。

禁用 swapping
把操作系統的虛擬內存交換區關閉。sysctl 裏面添加 vm.swappiness = 1

Elasticsearch常用配置及性能參數

讓我們調高節點發現的日誌記錄級別:
PUT /_cluster/settings
{
"transient" : {
"logger.discovery" : "DEBUG"
}
}


這是一個索引級別的設置,也就是說可以獨立應用給單個索引:

PUT /my_index/_settings
{
"index.search.slowlog.threshold.query.warn" : "10s", 查詢慢於 10 秒輸出一個 WARN 日誌。
"index.search.slowlog.threshold.fetch.debug": "500ms", 獲取慢於 500 毫秒輸出一個 DEBUG 日誌。
"index.indexing.slowlog.threshold.index.info": "5s" 索引慢於 5 秒輸出一個 INFO 日誌。

}

一旦閾值設置過了,你可以和其他日誌器一樣切換日誌記錄等級:


PUT /_cluster/settings
{
"transient" : {
"logger.index.search.slowlog" : "DEBUG", 設置搜索慢日誌為 DEBUG 級別。
"logger.index.indexing.slowlog" : "WARN" 設置索引慢日誌為 WARN 級別。
}
}


cluster.name: estest 集群名稱
node.name: “testanya” 節點名稱

node.master: false 是否主節點
node.data: true 是否存儲數據

index.store.type: niofs 讀寫文件方式
index.cache.field.type: soft 緩存類型

bootstrap.mlockall: true 禁用swap

gateway.type: local 本地存儲

gateway.recover_after_nodes: 3 3個數據節點開始恢復

gateway.recover_after_time: 5m 5分鐘後開始恢復數據

gateway.expected_nodes: 4 4個es節點開始恢復

cluster.routing.allocation.node_initial_primaries_recoveries:8 並發恢復分片數
cluster.routing.allocation.node_concurrent_recoveries:2 同時recovery並發數

indices.recovery.max_bytes_per_sec: 250mb 數據在節點間傳輸最大帶寬
indices.recovery.concurrent_streams: 8 同時讀取數據文件流線程

discovery.zen.ping.multicast.enabled: false 禁用多播
discovery.zen.ping.unicast.hosts:[“192.168.169.11:9300”, “192.168.169.12:9300”]

discovery.zen.fd.ping_interval: 10s 節點間存活檢測間隔
discovery.zen.fd.ping_timeout: 120s 存活超時時間
discovery.zen.fd.ping_retries: 6 存活超時重試次數

http.cors.enabled: true 使用監控

index.analysis.analyzer.ik.type:”ik” ik分詞

thread pool setting

threadpool.index.type: fixed 寫索引線程池類型
threadpool.index.size: 64 線程池大小(建議2~3倍cpu數)
threadpool.index.queue_size: 1000 隊列大小

threadpool.search.size: 64 搜索線程池大小
threadpool.search.type: fixed 搜索線程池類型
threadpool.search.queue_size: 1000 隊列大小

threadpool.get.type: fixed 取數據線程池類型
threadpool.get.size: 32 取數據線程池大小
threadpool.get.queue_size: 1000 隊列大小

threadpool.bulk.type: fixed 批量請求線程池類型
threadpool.bulk.size: 32 批量請求線程池大小
threadpool.bulk.queue_size: 1000 隊列大小

threadpool.flush.type: fixed 刷磁盤線程池類型
threadpool.flush.size: 32 刷磁盤線程池大小
threadpool.flush.queue_size: 1000 隊列大小

indices.store.throttle.type: merge
indices.store.throttle.type: none 寫磁盤類型
indices.store.throttle.max_bytes_per_sec:500mb 寫磁盤最大帶寬

index.merge.scheduler.max_thread_count: 8 索引merge最大線程數
index.translog.flush_threshold_size:600MB 刷新translog文件閥值

cluster.routing.allocation.node_initial_primaries_recoveries:8 並發恢復分片數
cluster.routing.allocation.node_concurrent_recoveries:2 同時recovery並發數

使用bulk API 增加入庫速度
初次索引的時候,把 replica 設置為 0
增大 threadpool.index.queue_size 1000
增大 indices.memory.index_buffer_size: 20%
index.translog.durability: async –這個可以異步寫硬盤,增大寫的速度
增大 index.translog.flush_threshold_size: 600MB
增大 index.translog.flush_threshold_ops: 500000


–節點下線時,把所有後綴為 -2的從集群中排除


curl -XPUT http://127.0.0.1:9200/_cluster/settings
{ "transient" :
{"cluster.routing.allocation.enable" : "all", "cluster.routing.allocation.exclude._name":".*-2"}
}

curl -XPUT ip:9200/_cluster/settings -d
‘{
"transient": {
"logger.discover": "DEBUG"
}
"persistent": {
"discovery.zen.minimum_master_nodes": 2
}
}‘


—批量指定節點下線
curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘{
"transient": {
"cluster.routing.allocation.exclude._name": "atest11-2,atest12-2,anatest13-2,antest14-2"
}

}‘

curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘{
"transient": {
"cluster.routing.allocation.exclude._name": "test_aa73_2,test_aa73"
}

}‘


curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘{
"transient": {
"cluster.routing.allocation.exclude._name": ""
}

}‘


curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘{
"transient": {
"cluster.routing.allocation.cluster_concurrent_rebalance": 10
}

}‘

curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘{
"transient": {
"indices.store.throttle.type": "none",
"index.store.type": "niofs",
"index.cache.field.type": "soft",
"indices.store.throttle.max_bytes_per_sec": "500mb",
"index.translog.flush_threshold_size": "600MB",
"threadpool.flush.type": "fixed",
"threadpool.flush.size": 32,
"threadpool.flush.queue_size": 1000
}

}‘


curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘{
"transient": {
"index.indexing.slowlog.level": "warn"
}

}‘

curl -XGET 127.0.0.1:9200/_cluster/health?level=shards

curl -XGET 127.0.0.1:9200/_cluster/settings?pretty

curl -XGET 127.0.0.1:9200/_cluster/pending_tasks?pretty

curl -XGET 127.0.0.1:9200/_cat/aliases

curl -XGET 127.0.0.1:9200/_cat/plugins

curl -XGET 127.0.0.1:9200/_cat/nodes

/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}


shard的移動
curl -XPOST ‘localhost:9200/_cluster/reroute‘ -d ‘{
"commands" : [ {
"move" :
{
"index" : "test_aa_20160529", "shard" : 4,
"from_node" : "node1", "to_node" : "node2"
}
},
{
"allocate" : {
"index" : "test", "shard" : 1, "node" : "node3"
}
}
]
}‘

curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘
{
"transient": {
"logger.indices.recovery": "DEBUG"
}
}‘

curl -XPUT 127.0.0.1:9200/_cluster/settings -d ‘
{
"transient": {
"cluster.routing.allocation.node_initial_primaries_recoveries": "100"
}
}‘


curl -XPOST ‘127.0.0.1:9200/_cluster/settings‘ -d ‘{
"transient" :
{
"indices.memory.index_buffer_size": "20%"
}

}‘

curl -XPOST ‘127.0.0.1:9200/_cluster/settings‘ -d ‘{
"transient" :
{
"index.indexing.slowlog.level" : "info"
}

}‘


put /_cluster/settings
{
"persistent" : {
"indices.store.throttle.max_bytes_per_sec":"20mb",
"indices.breaker.fielddata.limit":"60%",
"indices.breaker.request.limit":"40%",
"indices.breaker.total.limit":"70%"
}
}


PUT /_cluster/settings -d ‘{
"transient" : {
"cluster.routing.allocation.disk.threshold_enabled" : true,
"cluster.routing.allocation.disk.watermark.low" : "85%",
"cluster.routing.allocation.disk.watermark.high" : "90%"
}
}‘


在ubuntu 裏面,swappiness的值的大小對如何使用swap分區是有著很大的聯系的。swappiness=0的時候表示最大限度使用物理內存,然後才是 swap空間,swappiness=100的時候表示積極的使用swap分區,並且把內存上的數據及時的搬運到swap空間裏面。兩個極端,對於ubuntu的默認設置,這個值等於60,建議修改為10。具體這樣做:
1.查看你的系統裏面的swappiness
$ cat /proc/sys/vm/swappiness
不出意外的話,你應該看到是 60
2.修改swappiness值為10
$ sudo sysctl vm.swappiness=10
但是這只是臨時性的修改,在你重啟系統後會恢復默認的60,所以,還要做一步:
$ gksudo gedit /etc/sysctl.conf
在這個文檔的最後加上這樣一行:
vm.swappiness=10


查看節點信息 鏈接線程池 等
http://10.1.1.77:9200/_nodes/stats?pretty

ElasticSearch 性能調優筆記