配置项作用 #
thread_pool.refresh 相关配置项控制用于执行索引刷新(Refresh)操作的线程池。索引刷新操作将内存中的文档写入新段,使文档对搜索可见。该线程池采用伸缩线程池类型。
配置项类型 #
该配置项为静态配置,需要在启动时设置,修改后需要重启节点才能生效。
默认值 #
thread_pool.refresh.core: 1
thread_pool.refresh.max: half_processors_max_10
计算公式: min(allocatedProcessors / 2, 10)
thread_pool.refresh.keep_alive: 5m
是否必需 #
可选配置项(有默认值)
配置格式 #
# 默认配置
thread_pool.refresh.core: 1
thread_pool.refresh.max: 10
thread_pool.refresh.keep_alive: 5m
# 增加最大线程数
thread_pool.refresh.core: 2
thread_pool.refresh.max: 20
# 减少最大线程数
thread_pool.refresh.core: 1
thread_pool.refresh.max: 5
# 调整线程保活时间
thread_pool.refresh.keep_alive: 2m
相关配置项 #
| 配置项 | 默认值 | 说明 |
|---|---|---|
thread_pool.refresh.core | 1 | 核心线程数 |
thread_pool.refresh.max | half_processors_max_10 | 最大线程数 |
thread_pool.refresh.keep_alive | 5m | 线程保活时间 |
index.refresh_interval | 1s | 索引刷新间隔 |
线程池类型 #
类型: SCALING (伸缩线程池)
特点:
- 核心线程数始终保持
- 根据负载动态扩展
- 空闲线程超时后回收
- 适用于间歇性工作负载
工作原理 #
索引刷新处理流程:
┌─────────────────────────────────────────────────────────────────┐
│ 索引刷新处理 │
└─────────────────────────────────────────────────────────────────┘
刷新请求到达(定时或手动)
│
▼
检查线程池状态
│
├── 活动线程 < core
│ │
│ └── 创建/使用核心线程处理
│
├── core <= 活动线程 < max
│ │
│ └── 扩展临时线程处理
│
└── 活动线程 >= max
│
└── 加入队列等待或拒绝
默认值计算 #
half_processors_max_10 = min(allocatedProcessors / 2, 10)
示例:
CPU 核心数 = 4
half_processors_max_10 = min(4/2, 10) = 2
CPU 核心数 = 8
half_processors_max_10 = min(8/2, 10) = 4
CPU 核心数 = 16
half_processors_max_10 = min(16/2, 10) = 8
CPU 核心数 = 32
half_processors_max_10 = min(32/2, 10) = 10
使用场景 #
1. 默认配置(推荐) #
thread_pool.refresh.core: 1
thread_pool.refresh.max: 10
thread_pool.refresh.keep_alive: 5m
适用于大多数集群配置。
2. 高频刷新场景 #
thread_pool.refresh.core: 2
thread_pool.refresh.max: 20
thread_pool.refresh.keep_alive: 5m
适用场景:
- 极短的刷新间隔
- 大量索引
- 实时搜索需求
3. 资源受限 #
thread_pool.refresh.core: 1
thread_pool.refresh.max: 3
thread_pool.refresh.keep_alive: 2m
适用场景:
- 资源受限环境
- 较长刷新间隔
- 减少线程开销
推荐设置建议 #
| CPU 核心数 | 推荐核心线程 | 推荐最大线程 | 说明 |
|---|---|---|---|
| 4 | 1 | 2-4 | 小型节点 |
| 8 | 1-2 | 4-8 | 中型节点 |
| 16 | 2 | 8-10 | 大型节点 |
| 32+ | 2-4 | 10-20 | 高性能节点 |
监控建议 #
# 查看线程池状态
GET /_cat/thread_pool/refresh?v
# 查看详细统计
GET /_nodes/stats/thread_pool/refresh
# 查看刷新操作
GET /_cat/indices?v&h=index,health,refresh*
与索引刷新间隔的关系 #
index.refresh_interval 设置越短:
- 刷新操作越频繁
- 需要更多的 refresh 线程
- 文档更快变为可搜索
- 更多的段文件创建
index.refresh_interval 设置越长:
- 刷新操作越少
- 需要较少的 refresh 线程
- 文档搜索延迟增加
- 段文件更大,合并压力小
性能影响 #
核心线程数过小(1) #
优点:
✓ 节省资源
✓ 减少线程开销
缺点:
✗ 并发刷新受限
✗ 可能延迟刷新
✗ 刷新操作排队
最大线程数过大(30) #
优点:
✓ 高并发刷新能力
✓ 快速完成刷新
缺点:
✗ 消耗更多 CPU
✗ 可能影响其他操作
✗ 增加段文件数量
注意事项 #
- 静态配置:修改需要重启节点
- 与刷新间隔配合:刷新间隔越短,需要更多线程
- 核心线程保持运行:core 线程不会因空闲而回收
- 临时线程会超时回收:max 线程在 keep_alive 时间后回收
- 影响段数量:频繁刷新会产生更多小段
- 实时性权衡:刷新间隔和线程数影响搜索实时性





