超时

Envoy 支持多种超时机制,保障代理和上游服务的健壮性。常见超时类型包括:

  • 请求超时(request_timeout):整个请求的最大等待时间
  • 空闲超时(idle_timeout):连接无活动时的最大保持时间
  • 请求头超时(request_headers_timeout):接收完整请求头的最大时间
  • 每次尝试超时(per_try_timeout):重试时每次尝试的超时时间

配置方法

超时可在 HCM 层(全局)和路由层分别配置,路由层可覆盖全局设置。

HCM 层配置示例

filters:
- name: envoy.filters.network.http_connection_manager
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
    stat_prefix: ingress_http
    common_http_protocol_options:
      idle_timeout: 600s  # 10 分钟

路由层配置示例

route_config:
  virtual_hosts:
  - name: example
    domains: ["*"]
    routes:
    - match:
        prefix: "/"
      route:
        cluster: example_cluster
        timeout: 30s           # 请求超时
        idle_timeout: 120s     # 流式连接空闲超时
        per_try_timeout: 5s    # 每次重试超时

实践建议

  • 路由级超时优先生效,适合细粒度控制
  • 流式/长连接建议关闭或单独设置 timeout,使用 stream_idle_timeout
  • 合理设置 per_try_timeout,避免重试拖慢整体响应

文章导航

章节完成

恭喜完成本章节!下一章节即将开始。下一章节:集群

章节概览