TCP/HTTP Keepalive

目录

基本概念

  1. ALB 支持在端口级别配置 keepalive,可在 frontend 上进行配置。

  2. Keepalive 是客户端与 ALB 之间的连接保持,不是 ALB 与后端之间的连接保持

  3. 通过 Nginx 配置实现,Nginx 需要且会在配置变更时自动重载

  4. TCP keepalive 和 HTTP keepalive 是两个不同的概念:

    1. TCP keepalive 是 TCP 协议的特性,当没有数据传输时,发送周期性的探测包以检测连接是否仍然存活,有助于检测并清理死连接。
    2. HTTP keepalive(也称为持久连接)允许多个 HTTP 请求复用同一个 TCP 连接,避免了建立新连接的开销,通过减少延迟和资源使用提升性能。

CRD

keepalive:
  properties:
    http:
      description: 下游 L7 keepalive
      properties:
        header_timeout:
          description: Keepalive header 超时,默认不设置。
          type: string
        requests:
          description: Keepalive 请求数,默认是 1000。
          type: integer
        timeout:
          description: Keepalive 超时,默认是 75s。
          type: string
      type: object
    tcp:
      description: TCPKeepAlive 定义 TCP keepalive 参数(SO_KEEPALIVE)
      properties:
        count:
          description: TCP_KEEPCNT 套接字选项。
          type: integer
        idle:
          description: TCP_KEEPIDLE 套接字选项。
          type: string
        interval:
          description: TCP_KEEPINTVL 套接字选项。
          type: string
      type: object
  type: object

仅能在 Frontend 的 .spec.config.keepalive 上配置。