--- title: "分片存储获取线程池配置" date: 2026-03-26 lastmod: 2026-03-26 description: "控制分片存储获取操作线程池的配置项说明" tags: ["线程池配置", "性能调优", "分片管理"] summary: "配置项作用 # thread_pool.fetch_shard_store 相关配置项控制用于获取分片存储文件操作的线程池。当需要打开分片并获取其存储文件信息时使用此线程池。该线程池采用伸缩线程池类型。 配置项类型 # 该配置项为静态配置,需要在启动时设置,修改后需要重启节点才能生效。 默认值 # thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 2 * allocatedProcessors 计算公式: 2 * CPU 核心数 thread_pool.fetch_shard_store.keep_alive: 5m 是否必需 # 可选配置项(有默认值) 配置格式 # # 默认配置(假设 CPU 核心数为 8) thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 16 thread_pool.fetch_shard_store.keep_alive: 5m # 增加最大线程数 thread_pool.fetch_shard_store.core: 2 thread_pool.fetch_shard_store.max: 32 # 减少最大线程数 thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 8 相关配置项 # 配置项 默认值 说明 thread_pool.fetch_shard_store.core 1 核心线程数 thread_pool." --- ## 配置项作用 `thread_pool.fetch_shard_store` 相关配置项控制用于获取分片存储文件操作的线程池。当需要打开分片并获取其存储文件信息时使用此线程池。该线程池采用伸缩线程池类型。 ## 配置项类型 该配置项为**静态配置**,需要在启动时设置,修改后需要重启节点才能生效。 ## 默认值 ``` thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 2 * allocatedProcessors 计算公式: 2 * CPU 核心数 thread_pool.fetch_shard_store.keep_alive: 5m ``` ## 是否必需 **可选配置项**(有默认值) ## 配置格式 ```yaml # 默认配置(假设 CPU 核心数为 8) thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 16 thread_pool.fetch_shard_store.keep_alive: 5m # 增加最大线程数 thread_pool.fetch_shard_store.core: 2 thread_pool.fetch_shard_store.max: 32 # 减少最大线程数 thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 8 ``` ## 相关配置项 | 配置项 | 默认值 | 说明 | |-------|-------|------| | `thread_pool.fetch_shard_store.core` | 1 | 核心线程数 | | `thread_pool.fetch_shard_store.max` | 2 * processors | 最大线程数 | | `thread_pool.fetch_shard_store.keep_alive` | 5m | 线程保活时间 | | `thread_pool.fetch_shard_started.max` | 2 * processors | 分片启动获取最大线程数 | ## 线程池类型 ``` 类型: SCALING (伸缩线程池) 特点: - 核心线程数始终保持 - 根据负载动态扩展 - 空闲线程超时后回收 - 最大线程数为 CPU 核心数的 2 倍 ``` ## 工作原理 分片存储获取操作处理流程: ``` ┌─────────────────────────────────────────────────────────────────┐ │ 分片存储获取处理 │ └─────────────────────────────────────────────────────────────────┘ 需要获取分片存储信息 │ ├── 打开分片 ├── 读取段文件 ├── 获取元数据 └── 验证存储完整性 │ ▼ 检查线程池状态 │ ├── 活动线程 < core │ │ │ └── 创建/使用核心线程处理 │ ├── core <= 活动线程 < max │ │ │ └── 扩展临时线程处理 │ └── 活动线程 >= max │ └── 加入队列等待 ``` ## 默认值计算 ``` max = 2 * allocatedProcessors 示例: CPU 核心数 = 4 max = 2 * 4 = 8 CPU 核心数 = 8 max = 2 * 8 = 16 CPU 核心数 = 16 max = 2 * 16 = 32 CPU 核心数 = 32 max = 2 * 32 = 64 ``` ## 使用场景 ### 1. 默认配置(推荐) ```yaml thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 16 thread_pool.fetch_shard_store.keep_alive: 5m ``` 适用于大多数集群配置。 ### 2. 高并发场景 ```yaml thread_pool.fetch_shard_store.core: 2 thread_pool.fetch_shard_store.max: 32 thread_pool.fetch_shard_store.keep_alive: 5m ``` **适用场景:** - 大量分片同时打开 - 频繁的元数据访问 - 高并发查询场景 ### 3. 资源受限 ```yaml thread_pool.fetch_shard_store.core: 1 thread_pool.fetch_shard_store.max: 8 thread_pool.fetch_shard_store.keep_alive: 5m ``` **适用场景:** - 资源受限环境 - 磁盘 I/O 性能有限 - 限制并发访问 ## 推荐设置建议 | CPU 核心数 | 推荐核心线程 | 推荐最大线程 | 说明 | |-----------|-------------|-------------|------| | 4 | 1 | 8 | 小型节点 | | 8 | 1 | 16 | 中型节点 | | 16 | 1-2 | 32 | 大型节点 | | 32+ | 2 | 64 | 高性能节点 | ## 监控建议 ```bash # 查看线程池状态 GET /_cat/thread_pool/fetch_shard_store?v # 查看详细统计 GET /_nodes/stats/thread_pool/fetch_shard_store # 查看分片状态 GET /_cat/shards?v # 查看节点存储信息 GET /_nodes/stats/fs ``` ## 与 fetch_shard_started 的区别 | 特性 | fetch_shard_store | fetch_shard_started | |-----|-------------------|---------------------| | 用途 | 分片存储文件获取 | 分片启动后获取 | | 触发时机 | 打开分片时 | 分片启动后 | | 数据类型 | 段文件、元数据 | 段数据、事务日志 | | 操作阶段 | 分片打开阶段 | 分片恢复阶段 | | 默认 max | 2 * processors | 2 * processors | ## 存储获取操作类型 ``` 典型的 fetch_shard_store 操作: 1. 分片打开 - 读取段文件列表 - 加载段元数据 - 验证文件完整性 2. 段信息查询 - 获取段大小 - 读取文档数量 - 查询删除文档 3. 存储验证 - 校验文件存在 - 检查文件权限 - 验证磁盘空间 4. 合并操作 - 段合并准备 - 合并后验证 - 清理旧段 ``` ## 注意事项 1. **静态配置**:修改需要重启节点 2. **I/O 密集型**:存储获取操作消耗磁盘 I/O 3. **文件系统操作**:依赖文件系统性能 4. **与缓存配合**:良好的缓存可减少此线程池使用 5. **最大线程数较大**:max 为 CPU 核心数的 2 倍 6. **与存储性能相关**:慢速存储会降低此线程池效率