Elasticsearch線程池配置

查看當(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。

核心線程池

  1. index:此線程池用于索引和刪除操作。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為300。
  2. search:此線程池用于搜索和計數(shù)請求。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量乘以3,隊列的size默認(rèn)為1000。
  3. suggest:此線程池用于建議器請求。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為1000。
  4. get:此線程池用于實時的GET請求。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為1000。
  5. bulk:此線程池用于批量操作。它的類型默認(rèn)為fixed,size默認(rèn)為可用處理器的數(shù)量,隊列的size默認(rèn)為50。
  6. 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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容