配置项作用 #
gateway.slow_write_logging_threshold 配置项用于设置集群状态写入操作的慢日志记录阈值。
当集群状态写入操作的时间超过此阈值时,会记录 WARN 级别的日志;低于此阈值时,记录 DEBUG 级别的日志。
配置项属性 #
- 配置路径:
gateway.slow_write_logging_threshold - 数据类型:
TimeValue(时间值) - 默认值:
10s(10秒) - 最小值:
0s - 是否可选: 是
- 是否动态: 是(支持动态更新)
配置项详解 #
工作机制 #
集群状态写入操作
开始写入
│
↓
执行写入...
│
↓
写入完成,计算耗时
│
├──────── 耗时 ≥ 阈值
│ │
│ ↓
│ 记录 WARN 级别日志
│ │
│ "writing cluster state took [15000ms]
│ which is above the warn threshold of [10s]"
│
└──────── 耗时 < 阈值
│
↓
记录 DEBUG 级别日志
│
"writing cluster state took [500ms]"
应用场景 #
此配置应用于两种集群状态写入操作:
完整状态写入 (
writeFullStateAndCommit)- 写入完整的集群状态
- 包含所有索引的元数据
增量状态写入 (
writeIncrementalStateAndCommit)- 只写入变更的部分
- 跳过未改变的索引
配置建议 #
生产环境(标准) #
gateway.slow_write_logging_threshold: 10s
建议: 保持默认值 10s。适用于大多数生产环境。
大型集群 #
gateway.slow_write_logging_threshold: 30s
建议: 增加到 30s-60s。当集群中有大量索引(如 1000+)时,状态写入需要更长时间。
性能敏感环境 #
gateway.slow_write_logging_threshold: 5s
建议: 减少到 3s-5s。当需要更敏感地检测性能问题时使用。
测试/调试环境 #
gateway.slow_write_logging_threshold: 1s
建议: 减少到 1s-3s。测试环境中可以捕获更多性能信息。
禁用慢日志 #
gateway.slow_write_logging_threshold: 0s
建议: 设置为 0s 可以让所有写入操作都记录 WARN 日志,用于详细性能分析。
代码示例 #
easysearch.yml 配置 #
gateway:
slow_write_logging_threshold: 10s # 默认值
大型集群配置 #
gateway:
slow_write_logging_threshold: 60s # 大集群需要更长的写入时间
动态更新配置 #
# 通过 API 动态更新阈值
PUT _cluster/settings
{
"transient": {
"gateway.slow_write_logging_threshold": "15s"
}
}
查看当前配置 #
GET _cluster/settings?flat_settings=true
日志示例 #
慢写入日志(WARN 级别) #
[WARN ][gateway ] writing cluster state took [15023ms] which is above the warn threshold of [10s];
wrote full state with [150] indices
正常写入日志(DEBUG 级别) #
[DEBUG][gateway ] writing cluster state took [523ms]; wrote full state with [50] indices
增量写入日志 #
[WARN ][gateway ] writing cluster state took [12000ms] which is above the warn threshold of [10s];
wrote metadata for [25] indices and skipped [125] unchanged indices
相关配置 #
| 配置项 | 作用 | 默认值 |
|---|---|---|
gateway.recover_after_data_nodes | 恢复所需的数据节点数量 | -1 |
gateway.recover_after_time | 恢复等待的超时时间 | 0 |
性能监控建议 #
监控指标 #
建议监控以下指标:
- 写入频率: 集群状态写入的频率
- 写入耗时: 每次写入的实际耗时
- 索引数量: 集群中的索引总数
- 慢写入次数: 超过阈值的写入次数
日志分析 #
# 统计慢写入次数
grep "writing cluster state took" /var/log/easysearch/*.log | \
grep "above the warn threshold" | wc -l
# 查看最慢的写入操作
grep "writing cluster state took" /var/log/easysearch/*.log | \
sort -t'[' -k3 -nr | head -10
性能影响分析 #
| 阈值设置 | 优点 | 缺点 |
|---|---|---|
| 较短(1-3s) | 捕获更多性能问题 | 可能产生大量 WARN 日志 |
| 中等(10s) | 平衡监控和噪音 | 标准设置 |
| 较长(30-60s) | 减少日志噪音 | 可能漏掉轻微性能问题 |
注意事项 #
动态更新: 此配置支持动态更新,修改后立即生效。
日志级别: 需要确保日志级别设置正确(DEBUG 或 INFO)才能看到正常写入日志。
索引数量影响: 集群中索引越多,状态写入时间越长。
磁盘性能: 慢速磁盘会导致写入时间增加。
集群状态大小: 频繁的集群状态变更会增加写入频率。
监控建议: 定期检查慢写入日志,及时发现性能问题。
阈值调整: 根据集群规模和性能表现动态调整阈值。
与 GC 的关系: 长时间的 GC 停顿也可能导致写入变慢。





