ES线程池设置

参考文章: ES线程池设置

每个Elasticsearch节点内部都维护着多个线程池,如index、search、get、bulk等,用户可以修改线程池的类型和大小,线程池默认大小跟CPU逻辑一致

一、查看当前线程组状态

curl -XGET 'http://localhost:9200/_nodes/stats?pretty'

"thread_pool": {
	"bulk": {
		"threads": 32,
		"queue": 0,
		"active": 0,
		"rejected": 0,
		"largest": 32,
		"completed": 659997
	},
	"index": {
		"threads": 2,
		"queue": 0,
		"active": 0,
		"rejected": 0,
		"largest": 2,
		"completed": 2
	}
}
上面截取了部分线程池的配置,其中,最需要关注的是rejected。当某个线程池active==threads时,表示所有线程都在忙,那么后续新的请求就会进入queue中,即queue>0,一旦queue大小超出限制,如bulk的queue默认50,那么elasticsearch进程将拒绝请求(碰到bulk HTTP状态码429),相应的拒绝次数就会累加到rejected中。

解决方法是:

  1. 记录失败的请求并重发
  2. 减少并发写的进程个数,同时加大每次bulk请求的size

二、核心线程池

  • index:此线程池用于索引和删除操作。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为300。
  • search:此线程池用于搜索和计数请求。它的类型默认为fixed,size默认为可用处理器的数量乘以3,队列的size默认为1000。
  • suggest:此线程池用于建议器请求。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为1000。
  • get:此线程池用于实时的GET请求。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为1000。
  • bulk:此线程池用于批量操作。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为50。
  • percolate:此线程池用于预匹配器操作。它的类型默认为fixed,size默认为可用处理器的数量,队列的size默认为1000。

三、线程池类型

1、cache

无限制的线程池,为每个请求创建一个线程

2、fixed

有着固定大小的线程池,大小由size属性指定,允许你指定一个队列(使用queue_size属性指定)用来保存请求,直到有一个空闲的线程来执行请求。如果Elasticsearch无法把请求放到队列中(队列满了),该请求将被拒绝

四、修改线程池配置

1、elasticsearch.yml

threadpool.index.type: fixed
threadpool.index.size: 100
threadpool.index.queue_size: 500

2、Rest API

curl -XPUT 'localhost:9200/_cluster/settings' -d '{
    "transient": {
        "threadpool.index.type": "fixed",
        "threadpool.index.size": 100,
        "threadpool.index.queue_size": 500
    }
}'

五、bulk异常排查

使用es bulk api时报错如下

EsRejectedExcutionException[rejected execution(queue capacity 50) on.......]

这个错误明显是默认大小为50的队列(queue)处理不过来了,解决方法是增大bulk队列的长度

elasticsearch.yml

threadpool.bulk.queue_size: 1000

六、其它参数设置

thread_pool.search.queue_size: 500
thread_pool.search.size: 200
thread_pool.search.min_queue_size: 10
thread_pool.search.max_queue_size: 1000
thread_pool.search.auto_queue_frame_size: 2000
thread_pool.search.target_response_time: 6s

thread_pool.bulk.queue_size: 1024

cluster.routing.allocation.disk.include_relocations: false

indices.memory.index_buffer_size: 15%

indices.breaker.total.limit: 30%
indices.breaker.request.limit: 6%
indices.breaker.fielddata.limit: 3%

indices.query.bool.max_clause_count: 300000
indices.queries.cache.count: 500
indices.queries.cache.size: 5%

 

你可能感兴趣的:(Elasticsearch,elasticsearch)