close

引用網址:https://www.jianshu.com/p/a94e38da0039

[Elasticsearch常用配置及性能参数]

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

性能测试
在一个节点的一个分片,不设置副本,测试性能
在完全默认设置上记录性能数据,作为测试的基准线
确保性能测试持续30分钟以上以确认长时间的性能;短时间的测试可能不会碰到segment合并和GC,无法确认这些因素的影响
每次基于默认基准线更改一个参数,如果性能有提升就保留设置,并基于此设置做后续的测试
bulk使用建议
每个请求大小建议在5-15MB,逐步增大测试,当接收到EsRejectedExecutionException,就说明已经到达节点的瓶颈了,就需要减少并发或者升级硬件增加节点
当写入数据时,确保bulk请求时轮询访问所有节点,不要发送所有请求到一个结点导致这一个节点要在内存存储所有请求的数据去处理
优化磁盘IO
使用SSD
使用RAID 0,不用镜像备份,用replicas保证数据正确性,增大磁盘IO
使用多个磁盘给Elasticsearch访问,通过在path.data中添加
不使用远程存储,如NFS/SMB/CIFS;延时将成为性能瓶颈
段合并
段合并是很消耗计算资源和磁盘IO的操作,特别是出现比较大的段合并。

throttle

当出现段合并的速度落后于索引写入的速度,Elasticsearch为了避免出现堆积的段数量爆发,会降低单个线程的索引写入速度,并且会在INFO的log里记录“now throttling indexing“

Elasticsearch默认比较保守,不想让搜索的性能被后台的段合并影响,默认的段合并速率限制比较低,默认是20MB/s,但如果使用的是SSD,可以考虑把这个参数设置到100-200MB/s

PUT /_cluster/settings
{
"persistent" : {
"indices.store.throttle.max_bytes_per_sec" : "100mb"
}
}

如果你只是用bulk导入数据而不关注查询性能,可以关闭合并的阈值

PUT /_cluster/settings
{
"transient" : {
"indices.store.throttle.type" : "none"
}
}

然后在导入完数据之后恢复成“merge”来恢复这个阈值设置

如果是机械硬盘,你需要增加下面的配置到elasticsearch.yml中

index.merge.scheduler.max_thread_count: 1

机械硬盘的并发IO性能较差,我们需要减少每个索引并发访问磁盘的线程数,这个设置会有max_thread_count+2个线程并发访问磁盘
如果是SSD可以忽略这个参数,默认线程数是Math.min(3, Runtime.getRuntime().availableProcessors() / 2),对于SSD来说没有问题。

可以增大index.translog.flush_threshold_size参数,默认是200M,可以增大到如1GB。增大这个参数可以允许translog在flush前存放更大的段(segment);更大的段的创建会减少flush的频率,并且更大的段合并越少,会减少磁盘IO,索引性能更高。

其他优化
如果不需要实时精确的查询结果,可以把每个索引的index.refresh_interval设置为30s,如果在导入大量的数据,可以把这个值先设置为-1,完成数据导入之后在设置回来
如果在用bulk导入大量的数据,可以考虑不要副本,设置index.number_of_replicas: 0。有副本存在的时候,导入数据需要同步到副本,并且副本也要完成分析,索引和段合并的操作,影响导入性能。可以不设置副本导入数据然后在恢复副本。
如果导入的文档没有唯一的ID,可以使用Elasticsearch自动生成的唯一ID



作者:达微
链接:https://www.jianshu.com/p/a94e38da0039
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
arrow
arrow
    文章標籤
    elk elasticsearch
    全站熱搜

    龍之家族 發表在 痞客邦 留言(0) 人氣()