elasticsearch运维实战之2 - 系统性能调优
elasticsearch性能調(diào)優(yōu)
集群規(guī)劃
- 獨立的master節(jié)點,不存儲數(shù)據(jù), 數(shù)量不少于2
- 數(shù)據(jù)節(jié)點(Data Node)
- 查詢節(jié)點(Query Node),起到負載均衡的作用
Linux系統(tǒng)參數(shù)配置
文件句柄
Linux中,每個進程默認打開的最大文件句柄數(shù)是1000,對于服務器進程來說,顯然太小,通過修改/etc/security/limits.conf來增大打開最大句柄數(shù)
* - nofile 65535虛擬內(nèi)存設置
max_map_count定義了進程能擁有的最多內(nèi)存區(qū)域
sysctl -w vm.max_map_count=262144修改/etc/elasticsearch/elasticsearch.yml
bootstrap.mlockall: true修改/etc/security/limits.conf, 在limits.conf中添加如下內(nèi)容
* soft memlock unlimited * hard memlock unlimitedmemlock 最大鎖定內(nèi)存地址空間, 要使limits.conf文件配置生效,必須要確保pam_limits.so文件被加入到啟動文件中。
確保/etc/pam.d/login文件中有如下內(nèi)容
session required /lib/security/pam_limits.so驗證是否生效
curl localhost:9200/_nodes/stats/process?pretty磁盤緩存相關(guān)參數(shù)
vm.dirty_background_ratio 這個參數(shù)指定了當文件系統(tǒng)緩存臟頁數(shù)量達到系統(tǒng)內(nèi)存百分之多少時(如5%)就會觸發(fā)pdflush/flush/kdmflush等后臺回寫進程運行,將一定緩存的臟頁異步地刷入外存;
vm.dirty_ratio
該參數(shù)則指定了當文件系統(tǒng)緩存臟頁數(shù)量達到系統(tǒng)內(nèi)存百分之多少時(如10%),系統(tǒng)不得不開始處理緩存臟頁(因為此時臟頁數(shù)量已經(jīng)比較多,為了避免數(shù)據(jù)丟失需要將一定臟頁刷入外存);在此過程中很多應用進程可能會因為系統(tǒng)轉(zhuǎn)而處理文件IO而阻塞。
把該參數(shù)適當調(diào)小,原理通(1)類似。如果cached的臟數(shù)據(jù)所占比例(這里是占MemTotal的比例)超過這個設置,系統(tǒng)會停止所有的應用層的IO寫操作,等待刷完數(shù)據(jù)后恢復IO。所以萬一觸發(fā)了系統(tǒng)的這個操作,對于用戶來說影響非常大的。
為了將設置永久保存,將上述配置項寫入/etc/sysctl.conf文件中
vm.dirty_ratio = 10 vm.dirty_background_ratio = 5swap調(diào)優(yōu)
swap空間是一塊磁盤空間,操作系統(tǒng)使用這塊空間保存從內(nèi)存中換出的操作系統(tǒng)不常用page數(shù)據(jù),這樣可以分配出更多的內(nèi)存做page cache。這樣通常會提升系統(tǒng)的吞吐量和IO性能,但同樣會產(chǎn)生很多問題。頁面頻繁換入換出會產(chǎn)生IO讀寫、操作系統(tǒng)中斷,這些都很影響系統(tǒng)的性能。這個值越大操作系統(tǒng)就會更加積極的使用swap空間。
調(diào)節(jié)swappniess方法如下
sudo sh -c 'echo "0">/proc/sys/vm/swappiness'io sched
如果集群中使用的是SSD磁盤,那么可以將默認的io sched由cfq設置為noop
sudo sh -c 'echo "noop">/sys/block/sda/queue/scheduler'JVM參數(shù)設置
在/etc/sysconfig/elasticsearch中設置最大堆內(nèi)存,該值不應超過32G
ES_HEAP_SIZE=32g ES_JAVA_OPTS="-Xms32g" MAX_LOCKED_MEMORY=unlimited MAX_OPEN_FILES=65535indice參數(shù)調(diào)優(yōu)
以創(chuàng)建demo_logs模板為例,說明可以調(diào)優(yōu)的參數(shù)及其數(shù)值設定原因。
PUT _template/demo_logs {"order": 6,"template": "demo-*","settings": {"index.merge.policy.segments_per_tier": "25","index.mapping._source.compress": "true","index.mapping._all.enabled": "false","index.warmer.enabled": "false","index.merge.policy.min_merge_size": "10mb","index.refresh_interval": "60s","index.number_of_shards": "7","index.translog.durability": "async","index.store.type": "mmapfs","index.merge.policy.floor_segment": "100mb","index.merge.scheduler.max_thread_count": "1","index.translog.translog.flush_threshold_size": "1g","index.merge.policy.merge_factor": "15","index.translog.translog.flush_threshold_period": "100m","index.translog.sync_interval": "5s","index.number_of_replicas": "1","index.indices.store.throttle.max_bytes_per_sec": "50mb","index.routing.allocation.total_shards_per_node": "2","index.translog.flush_threshold_ops": "1000000"},"mappings": {"_default_": {"dynamic_templates": [{"string_template": {"mapping": {"index": "not_analyzed","ignore_above": "10915","type": "string"},"match_mapping_type": "string"}},{"level_fields": {"mapping": {"index": "no","type": "string"},"match": "Level*Exception*"}}]}}"aliases": {}}replica數(shù)目
為了讓創(chuàng)建的es index在每臺datanode上均勻分布,同一個datanode上同一個index的shard數(shù)目不應超過3個。
計算公式: (number_of_shard * (1+number_of_replicas)) < 3*number_of_datanodes
每臺機器上分配的shard數(shù)目
"index.routing.allocation.total_shards_per_node": "2",refresh時間間隔
默認的刷新時間間隔是1s,對于寫入量很大的場景,這樣的配置會導致寫入吞吐量很低,適當提高刷新間隔,可以提升寫入量,代價就是讓新寫入的數(shù)據(jù)在60s之后可以被搜索,新數(shù)據(jù)可見的及時性有所下降。
"index.refresh_interval": "60s"translog
降低數(shù)據(jù)flush到磁盤的頻率。如果對數(shù)據(jù)丟失有一定的容忍,可以打開async模式。
"index.translog.flush_threshold_ops": "1000000", "index.translog.durability": "async",merge相關(guān)參數(shù)
"index.merge.policy.floor_segment": "100mb", "index.merge.scheduler.max_thread_count": "1", "index.merge.policy.min_merge_size": "10mb"mapping設置
對于不參與搜索的字段(fields), 將其index方法設置為no, 如果對分詞沒有需求,對參與搜索的字段,其index方法設置為not_analyzed
多使用dynamic_template
集群參數(shù)調(diào)優(yōu)
{"persistent": {"cluster": {"routing": {"allocation": {"enable": "new_primaries","cluster_concurrent_rebalance": "8","allow_rebalance": "indices_primaries_active","node_concurrent_recoveries": "8"}}},"indices": {"breaker": {"fielddata": {"limit": "30%"},"request": {"limit": "30%"}},"recovery": {"concurrent_streams": "10","max_bytes_per_sec": "200mb"}}},"transient": {"indices": {"store": {"throttle": {"type": "merge","max_bytes_per_sec": "50mb"}},"recovery": {"concurrent_streams": "8"}},"threadpool": {"bulk": {"type": "fixed""queue_size": "1000","size": "30"},"index": {"type": "fixed","queue_size": "1200","size": "30"}},"cluster": {"routing": {"allocation": {"enable": "all","cluster_concurrent_rebalance": "8","node_concurrent_recoveries": "15"}}}} }避免shard的頻繁rebalance,將allocation的類型設置為new_primaries, 將默認并行rebalance由2設置為更大的一些的值
避免每次更新mapping, 針對2.x以下的版本
"indices.cluster.send_refresh_mapping": false調(diào)整threadpool, size不要超過core數(shù)目,否則線程之間的context switching會消耗掉大量的cpu時間,導致load過高。 如果沒有把握,那就不要去調(diào)整。
定期清理cache
為避免fields data占用大量的jvm內(nèi)存,可以通過定期清理的方式來釋放緩存的數(shù)據(jù)。釋放的內(nèi)容包括field data, filter cache, query cache
curl -XPOST "localhost:9200/_cache/clear"其它
- marvel: 安裝marvel插件,多觀察系統(tǒng)資源占用情況,包括內(nèi)存,cpu
- 日志: 對es的運行日志要經(jīng)常查看,檢查index配置是否合理,以及入庫數(shù)據(jù)是否存在異常
調(diào)優(yōu)之后的運行效果
寫入量穩(wěn)定在30K/s
轉(zhuǎn)載于:https://www.cnblogs.com/hseagle/p/6015245.html
總結(jié)
以上是生活随笔為你收集整理的elasticsearch运维实战之2 - 系统性能调优的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: thinkPHP5中hasOne和bel
- 下一篇: 泰拉瑞亚怎么卡地牢五神器(汉典泰字的基本