配置项作用 #
cluster.service.slow_master_task_logging_threshold 配置项控制主节点上执行的集群管理任务(如集群状态更新、分片分配决策等)执行时间的日志记录阈值。当任务执行时间超过此阈值时,会记录警告日志,用于识别主节点性能瓶颈。
配置项类型 #
该配置项为动态配置,可以在运行时通过集群设置 API 进行修改。
默认值 #
10s(10秒)
是否必需 #
可选配置项(有默认值)
取值范围 #
> 0(正数)
配置格式 #
# 默认配置
cluster.service.slow_master_task_logging_threshold: 10s
# 更敏感的阈值
cluster.service.slow_master_task_logging_threshold: 5s
# 更宽松的阈值
cluster.service.slow_master_task_logging_threshold: 30s
相关配置项 #
| 配置项 | 默认值 | 说明 |
|---|---|---|
cluster.service.slow_master_task_logging_threshold | 10s | 主节点慢任务阈值 |
cluster.service.slow_task_logging_threshold | 30s | 普通慢任务阈值 |
工作原理 #
主节点慢任务检测机制:
┌─────────────────────────────────────────────────────────────────┐
│ 主节点慢任务检测流程 │
└─────────────────────────────────────────────────────────────────┘
主节点任务执行开始
│
▼
记录开始时间
│
▼
执行主节点任务
├── 集群状态更新
├── 分片分配决策
├── 投票配置更新
└── 其他主节点任务
│
▼
记录结束时间
│
▼
计算执行时间
│
├── 执行时间 >= threshold (10s)
│ │
│ └── 记录警告日志
│ "master task [task_name] took [Xs] which is longer than the threshold [Ys]"
│
└── 执行时间 < threshold
│
└── 不记录额外日志
主节点任务类型 #
常见的主节点任务:
1. 集群状态更新任务
- 元数据变更
- 索引创建/删除
- 映射更新
- 设置变更
2. 分片分配任务
- 分片重新平衡
- 故障恢复
- 副本分配
3. 投票配置任务
- 节点加入/离开
- 投票排除添加
- 主节点选举相关
4. 其他管理任务
- 快照操作
- 持久化任务管理
- 生命周期管理
使用场景 #
1. 默认配置(推荐) #
cluster.service.slow_master_task_logging_threshold: 10s
适用场景:
- 大多数集群配置
- 主节点性能正常
- 需要监控主节点性能
2. 更敏感的监控 #
cluster.service.slow_master_task_logging_threshold: 5s
适用场景:
- 性能敏感环境
- 快速发现问题
- 主节点资源充足
3. 大规模集群 #
cluster.service.slow_master_task_logging_threshold: 30s
适用场景:
- 大规模集群
- 索引数量多
- 可容忍较慢的主节点操作
推荐设置建议 #
| 集群规模 | 索引数量 | 推荐阈值 | 说明 |
|---|---|---|---|
| 小型 | < 100 | 5-10s | 快速发现问题 |
| 中型 | 100-1000 | 10s | 默认配置 |
| 大型 | 1000-10000 | 10-30s | 根据实际情况调整 |
| 超大规模 | > 10000 | 30-60s | 容忍更长的执行时间 |
与普通慢任务阈值的对比 #
两种慢任务阈值的区别:
1. cluster.service.slow_master_task_logging_threshold
- 默认: 10s
- 作用: 主节点任务
- 更敏感: 主节点性能更关键
2. cluster.service.slow_task_logging_threshold
- 默认: 30s
- 作用: 所有集群任务
- 更宽松: 普通节点任务容忍度高
为什么主节点阈值更低:
- 主节点是集群瓶颈
- 所有操作都经过主节点
- 主节点慢影响整个集群
- 需要更密切的关注
监控建议 #
# 查看当前配置
GET /_cluster/settings?filter_path=*.cluster.service.slow_master_task_logging_threshold
# 查看主节点任务
GET /_tasks?actions=*cluster*&detailed=true&pretty
# 查看日志中的慢任务
grep "master task.*longer than threshold" logs/easysearch.log
# 查看主节点信息
GET /_cat/nodes?v&h=name,master,*,task*
动态配置示例 #
# 降低阈值以更敏感地检测
PUT /_cluster/settings
{
"transient": {
"cluster.service.slow_master_task_logging_threshold": "5s"
}
}
# 增加阈值以减少日志噪音
PUT /_cluster/settings
{
"transient": {
"cluster.service.slow_master_task_logging_threshold": "30s"
}
}
# 查看当前配置
GET /_cluster/settings?filter_path=*.cluster.service.slow_master_task_logging_threshold
常见慢任务及优化 #
常见慢主节点任务及优化:
1. 大量分片重新分配
慢任务日志: "cluster: update_state (shard allocation)"
优化:
- 减少 concurrent_recoveries
- 增加 allocation.decision 配置
2. 元数据更新
慢任务日志: "cluster: update_state (metadata)"
优化:
- 减少索引数量
- 批量操作改为单独操作
- 减少动态设置变更
3. 投票配置更新
慢任务日志: "cluster: update_state (voting config)"
优化:
- 减少节点变更频率
- 批量添加节点
4. 分片迁移
慢任务日志: "cluster: update_state (rebalance)"
优化:
- 减少 cluster.routing.allocation.balance
- 增加 rebalance 间隔
故障排查 #
主节点性能问题排查:
问题: 大量主节点慢任务日志
排查步骤:
1. 检查集群规模
GET /_cat/indices?v
# 索引数量是否过多
2. 检查分片数量
GET /_cat/shards?v
# 分片总数是否过多
3. 检查集群状态大小
GET /_cluster/state
# 响应大小是否过大
4. 检查主节点资源
GET /_nodes/stats
# 主节点 CPU/内存使用
5. 分析慢任务日志
# 找出最慢的任务类型
优化措施:
- 增加 slow_master_task_logging_threshold
- 减少索引和分片数量
- 优化分片分配配置
- 升级主节点硬件
- 使用专用的 master-eligible 节点
主节点性能优化建议 #
主节点性能优化策略:
1. 专用主节点
- node.roles: [ master ]
- 不存储数据
- 不处理搜索请求
- 专注于集群管理
2. 控制集群规模
- 减少索引数量
- 减少分片数量
- 使用索引生命周期管理
3. 优化配置
- 减少动态设置变更
- 批量操作元数据
- 合理设置分配限制
4. 硬件资源
- 更快的 CPU
- 充足的内存
- SSD 存储
5. 集群管理
- 避免频繁创建/删除索引
- 使用模板而非手动创建
- 减少手动配置变更
注意事项 #
- 动态更新:此配置为动态配置,可在线修改
- 仅记录日志:此配置不影响任务执行,仅记录警告
- 主节点关键:主节点性能影响整个集群
- 阈值过低:会产生大量日志噪音
- 阈值过高:可能遗漏重要的性能问题
- 与普通任务配合:与 slow_task_logging_threshold 配合使用





