elasticsearch线程池解析
每个Elasticsearch节点内部都维护着多个线程池,如index、search、get、bulk等,用户可以修改线程池的类型和大小,线程池默认大小跟CPU逻辑一致。
一、查看当前线程组状态
[html]view plaincopy
curl-XGET'https://localhost:9200/_nodes/stats?pretty'[html]view plaincopy
"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
}
[html]view plaincopy
threadpool:
generic:
keep_alive:2m[html]view plaincopy
threadpool:
index:
size:30
queue_size:1000
3、scaling
可变大小的pool,大小根据负载在1到size间,同样keep_alive参数指定了闲置线程被回收的时间。
[html]view plaincopy
threadpool:
warmer:
size:8
keep_alive:2m
四、修改线程池配置
1、elasticsearch.yml
[html]view plaincopy
threadpool.index.type:fixed
threadpool.index.size:100
threadpool.index.queue_size:500[html]view plaincopy
curl-XPUT'localhost:9200/_cluster/settings'-d'{
"transient":{
"threadpool.index.type":"fixed",
"threadpool.index.size":100,
"threadpool.index.queue_size":500
}
}'[html]view plaincopy
EsRejectedExcutionException[rejectedexecution(queuecapacity50)on.......] 这个错误明显是默认大小为50的队列(queue)处理不过来了,解决方法是增大bulk队列的长度[html]view plaincopy
threadpool.bulk.queue_size:1000