查看當(dāng)前線程組狀態(tài)
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
}
}
上面截取了部分線程池的配置,其中,最需要關(guān)注的是rejected。當(dāng)某個線程池active==threads時,表示所有線程都在忙,那么后續(xù)新的請求就會進(jìn)入queue中,即queue>0,一旦queue大小超出限制,如bulk的queue默認(rèn)50,那么elasticsearch進(jìn)程將拒絕請求(碰到bulk HTTP狀態(tài)碼429),相應(yīng)的拒絕次數(shù)就會累加到rejected中。
解決方法是:
記錄失敗的請求并重發(fā),
減少并發(fā)寫的進(jìn)程個數(shù),同時加大每次bulk請求的size。
核心線程池
- index:此線程池用于索引和刪除操作。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為300。
- search:此線程池用于搜索和計數(shù)請求。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量乘以3,隊列的size默認(rèn)為1000。
- suggest:此線程池用于建議器請求。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為1000。
- get:此線程池用于實時的GET請求。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為1000。
- bulk:此線程池用于批量操作。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為50。
- percolate:此線程池用于預(yù)匹配器操作。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為1000。
線程池類型
1.cache
無限制的線程池,為每個請求創(chuàng)建一個線程
2.fixed
有著固定大小的線程池,大小由size屬性指定,允許你指定一個隊列(使用queue_size屬性指定)用來保存請求,直到有一個空閑的線程來執(zhí)行請求。如果Elasticsearch無法把請求放到隊列中(隊列滿了),該請求將被拒絕
bulk異常排查
EsRejectedExcutionException[rejected execution(queue capacity 50) on.......]
這個錯誤明顯是默認(rèn)大小為50的隊列(queue)處理不過來了,解決方法是增大bulk隊列的長度
elasticsearch.yml
threadpool.bulk.queue_size: 1000
threadpool.index.type: fixed
threadpool.index.size: 100
threadpool.index.queue_size: 500
Rest API
curl -XPUT 'localhost:9200/_cluster/settings' -d '{
"transient": {
"threadpool.index.type": "fixed",
"threadpool.index.size": 100,
"threadpool.index.queue_size": 500
}
}'
其他線程池配置
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