ElasticSearch 性能调优笔记

Posted phpshen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ElasticSearch 性能调优笔记相关的知识,希望对你有一定的参考价值。

一下内容来源于网络

对于不同的字段禁用 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 性能调优笔记的主要内容,如果未能解决你的问题,请参考以下文章

ElasticSearch 性能调优笔记

30 个 ElasticSearch 调优知识点,都给你整理好了!

Elasticsearch 学习笔记1 入门

ElasticsearcheBay上的Elasticsearch性能调优实践

ElasticSearch集群部署系统参数配置调优

ElasticSearch集群部署系统参数配置调优