--- title: "每节点常规操作连接数配置" date: 2026-02-28 lastmod: 2026-02-28 description: "控制每节点常规操作连接数量的配置项说明" tags: ["传输配置", "性能优化", "请求处理"] summary: "配置项作用 # transport.connections_per_node.reg 配置项控制集群中每个节点之间用于常规操作(Regular Operations)的并发连接数。常规操作包括搜索请求、单文档索引、获取文档等日常操作。这是最常用的连接类型,对集群整体性能影响最大。 配置项类型 # 该配置项为静态配置,需要在启动时设置,修改后需要重启节点才能生效。 默认值 # 6 是否必需 # 可选配置项(有默认值) 取值范围 # 1 ~ 正整数 配置格式 # # 默认配置 transport.connections_per_node.reg: 6 # 增加常规连接数 transport.connections_per_node.reg: 12 # 减少常规连接数 transport.connections_per_node.reg: 4 # 高并发场景 transport.connections_per_node.reg: 20 相关配置项 # 配置项 默认值 说明 transport.connections_per_node.reg 6 常规操作连接数 transport.connections_per_node.bulk 3 批量操作连接数 transport.connections_per_node.recovery 2 恢复连接数 transport." --- ## 配置项作用 `transport.connections_per_node.reg` 配置项控制集群中每个节点之间用于常规操作(Regular Operations)的并发连接数。常规操作包括搜索请求、单文档索引、获取文档等日常操作。这是最常用的连接类型,对集群整体性能影响最大。 ## 配置项类型 该配置项为**静态配置**,需要在启动时设置,修改后需要重启节点才能生效。 ## 默认值 ``` 6 ``` ## 是否必需 **可选配置项**(有默认值) ## 取值范围 ``` 1 ~ 正整数 ``` ## 配置格式 ```yaml # 默认配置 transport.connections_per_node.reg: 6 # 增加常规连接数 transport.connections_per_node.reg: 12 # 减少常规连接数 transport.connections_per_node.reg: 4 # 高并发场景 transport.connections_per_node.reg: 20 ``` ## 相关配置项 | 配置项 | 默认值 | 说明 | |-------|-------|------| | `transport.connections_per_node.reg` | 6 | 常规操作连接数 | | `transport.connections_per_node.bulk` | 3 | 批量操作连接数 | | `transport.connections_per_node.recovery` | 2 | 恢复连接数 | | `transport.connections_per_node.state` | 1 | 状态操作连接数 | ## 工作原理 常规操作连接管理: ``` ┌─────────────────────────────────────────────────────────────────┐ │ 常规操作连接使用场景 │ └─────────────────────────────────────────────────────────────────┘ 客户端发起请求 │ ├── 搜索请求 (Search) │ └── 使用 reg 连接池 │ ├── 单文档索引 (Index) │ └── 使用 reg 连接池 │ ├── 获取文档 (Get) │ └── 使用 reg 连接池 │ ├── 更新文档 (Update) │ └── 使用 reg 连接池 │ └── 删除文档 (Delete) └── 使用 reg 连接池 连接池大小 = reg 配置值 - 并发常规操作数受此限制 - 默认 6 个连接 - 通常是最繁忙的连接池 ``` ## 常规操作类型 ``` 使用 reg 连接的操作类型: 1. 搜索操作 (Search) GET /_search - 最常见的操作 - 小数据量传输 - 高并发需求 2. 单文档操作 (Single Document) PUT /index/_doc/id GET /index/_doc/id - 小数据量 - 低延迟要求 3. 更新操作 (Update) POST /index/_update/id - 中等数据量 - 中等延迟要求 4. 删除操作 (Delete) DELETE /index/_doc/id - 极小数据量 - 低延迟要求 5. 聚合操作 (Aggregation) GET /index/_search - 可返回大数据量 - 中等延迟要求 ``` ## 使用场景 ### 1. 默认配置(推荐) ```yaml transport.connections_per_node.reg: 6 ``` 适用于大多数集群配置,平衡性能和资源使用。 ### 2. 高并发搜索场景 ```yaml transport.connections_per_node.reg: 12 ``` **适用场景:** - 大量并发搜索 - 高 QPS 需求 - 低延迟要求 - 资源充足 ### 3. 资源受限环境 ```yaml transport.connections_per_node.reg: 4 ``` **适用场景:** - 内存有限 - 连接数受限 - 小规模集群 - 低并发需求 ### 4. 极致性能场景 ```yaml transport.connections_per_node.reg: 20 ``` **适用场景:** - 极高 QPS 需求 - 高性能网络 - 大量内存 - 专用搜索节点 ## 推荐设置建议 | 场景 | QPS 需求 | 推荐值 | 说明 | |-----|---------|-------|------| | 小型应用 | < 100 | 4-6 | 默认即可 | | 中型应用 | 100-1000 | 6-10 | 适度增加 | | 大型应用 | 1000-10000 | 10-20 | 增加连接 | | 超大规模 | > 10000 | 20-40 | 需要充分测试 | | 资源受限 | 任意 | 3-4 | 最小化使用 | ## 性能影响分析 ``` 连接数对常规性能的影响: 增加连接数 (从 6 增加到 12): 优点: ✓ 提高并发处理能力 ✓ 减少请求排队 ✓ 降低延迟 ✓ 提高 QPS 缺点: ✗ 显著增加内存使用 ✗ 增加线程开销 ✗ 连接管理复杂 ✗ 边际收益递减 减少连接数 (从 6 减少到 3): 优点: ✓ 减少内存使用 ✓ 简化连接管理 缺点: ✗ 降低并发能力 ✗ 增加延迟 ✗ 可能成为瓶颈 ``` ## 与其他连接池的关系 ``` 连接池优先级和选择: 操作类型 连接池 默认大小 优先级 ───────────────────────────────────────────────── 搜索/单文档操作 reg 6 最高 批量索引/更新 bulk 3 高 分片恢复 recovery 2 中 状态更新 state 1 低 心跳检测 ping 1 最低 分配策略: - 每种操作类型使用独立的连接池 - 不会互相抢占连接 - 但共享总网络带宽 - 需要平衡各类连接数 ``` ## 高并发优化建议 ``` 高并发场景完整配置: # 传输层配置 transport.connections_per_node.reg: 12 transport.connections_per_node.bulk: 6 # 搜索线程池 thread_pool.search.size: 13 thread_pool.search.queue_size: 1000 # 通用线程池 thread_pool.generic.size: 16 # 网络配置 network.tcp.no_delay: true transport.tcp.keep_alive: true ``` ## 配置示例 ```yaml # 场景 1: 高并发搜索集群 cluster.name: search-cluster transport.connections_per_node.reg: 12 thread_pool.search.size: 26 thread_pool.search.queue_size: 2000 # 场景 2: 标准业务集群 cluster.name: business-cluster transport.connections_per_node.reg: 6 thread_pool.search.size: 13 # 场景 3: 资源受限集群 cluster.name: small-cluster transport.connections_per_node.reg: 4 thread_pool.search.size: 8 ``` ## 监控建议 ```bash # 查看当前配置 GET /_nodes/settings?filter_path=nodes.*.transport.connections_per_node # 查看连接统计 GET /_nodes/stats/transport # 查看搜索线程池 GET /_cat/thread_pool/search?v # 查看请求统计 GET /_nodes/stats/indices?filter_path=**.search # 查看当前连接数 GET /_cat/nodes?v&h=name,*,transport* ``` ## 资源消耗估算 ``` 资源消耗估算: 内存消耗: 每连接约 1-2 MB 默认 (6): 每节点对约 12 MB 增加 (12): 每节点对约 24 MB 10 节点集群总消耗: 默认: 45 * 12 MB ≈ 540 MB 增加: 45 * 24 MB ≈ 1080 MB 线程消耗: 每连接需要 1 个线程 需要与线程池配置协调 ``` ## 性能测试建议 ``` 常规操作性能测试步骤: 1. 设置基准配置 transport.connections_per_node.reg: 6 2. 运行基准测试 - 搜索 QPS - 平均延迟 - P95/P99 延迟 - CPU/内存使用 3. 逐步增加连接数 - 6 → 10 → 14 → 20 4. 分析性能曲线 - 找出拐点 - 评估边际收益 5. 选择最优配置 - 平衡性能和资源 ``` ## 故障排查 ``` 请求延迟高问题排查: 1. 检查连接配置 GET /_nodes/settings?filter_path=*.transport.connections_per_node.reg 2. 检查线程池状态 GET /_cat/thread_pool?v # 如果队列满,考虑增加连接 3. 检查连接使用率 GET /_nodes/stats/transport # 如果连接用满,增加连接数 4. 检查请求拒绝率 GET /_cat/thread_pool/search?v # 如果 rejected 高,增加资源 5. 检查系统资源 top, htop # 如果 CPU/内存满,优化代码或扩容 ``` ## 注意事项 1. **静态配置**:修改需要重启节点 2. **最常用连接池**:影响大部分操作 3. **内存消耗大**:是最大的连接池 4. **与线程池配合**:应与搜索线程池协调 5. **边际收益递减**:超过一定值收益有限 6. **网络带宽**:确保网络带宽足够