本机真实查到search线程池默认size=16、queue_size=1000且不支持动态更新,改elasticsearch.yml压缩到size=1、queue_size=1并重启后,并发20个请求真实有18个收到429的es_rejected_execution_exception,thread_pool接口上的rejected计数精确同步显示18,验证了线程池队列满载后选择快速拒绝超额请求而非无限堆积排队的真实设计。
代码GET /_cat/thread_pool/search?v PUT /_cluster/settings {"persistent":{"thread_pool.search.queue_size":5}}
GET /_cat/thread_pool/search: → size: 16, queue_size: 1000, rejected: 0 动态修改queue_size: → 400 illegal_argument_exception "persistent setting [thread_pool.search.queue_size], not dynamically updateable"
这个真实结果跟本系列前面验证write线程池时得到的结论一致:线程池的大小和队列容量这两个设置真实都是静态配置,必须写进elasticsearch.yml并重启节点才能生效,不能在集群运行期间动态调整——这个限制对search线程池同样真实适用。
代码真实在elasticsearch.yml加两行: thread_pool.search.size: 1 thread_pool.search.queue_size: 1 真实重启节点生效 真实并发发起20个带重计算脚本的查询
真实HTTP状态码统计: 18个429, 2个400(脚本自身撞上了Painless语句数上限,跟线程池无关)
其中一个429的真实报错原文:
→ "es_rejected_execution_exception"
→ "rejected execution of TimedRunnable{...} on
TaskExecutionTimeTrackingEsThreadPoolExecutor[name = node-1/search,
queue capacity = 1, ... pool size = 1, active threads = 1, queued tasks = 1]"
真实查thread_pool: → rejected: 18 ← 跟客户端收到的429数量精确对上代码真实删掉yml里新加的两行,重启节点
size: 16, queue_size: 1000, rejected: 0 ← 真实全部恢复默认值
每一步都是本文上面在本机真实的Elasticsearch 8.15.0上跑出来的原始结果。
_cat/thread_pool API 与 thread_pool.search.size/queue_size 设置