AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1121009
Accepted
ns15
ns15
Asked: 2023-01-25 06:00:52 +0800 CST2023-01-25 06:00:52 +0800 CST 2023-01-25 06:00:52 +0800 CST

负载均衡器可以平衡在同一个 TCP 连接上收到的多个请求吗?

  • 772

(下面是一个假设场景,当我发现 gRPC 负载平衡的复杂性以及由于长期存在的 TCP 连接而效率低下时,我想到了这个问题)

假设有一个 HTTP 客户端维护单个 TCP 长期连接,用于向位于 HA 代理后面的 API 服务发出 HTTP 1.1 请求。该服务有多个冗余服务器部分,我想平衡不同上游服务器之间同一 TCP 连接上的所有请求。这样的事情可能吗?

我知道客户端可以打开多个连接到 LB,这将有助于解决问题。

但我想知道是否可以使用某些 HA 代理配置直接执行此操作。如果没有,为什么缺少这样的功能?是由于某种网络/HTTP 协议限制吗?还是因为有其他解决方法,所以从来不需要这样的功能?

假设 TLS 在 HA 代理处终止,因此它可以执行 L7 路由。HAProxy 也只是一个例子,任何其他 LB/代理,如 Envoy、Nginx 都具有此功能?

load-balancing
  • 1 1 个回答
  • 47 Views

1 个回答

  • Voted
  1. Best Answer
    diya
    2023-01-25T07:12:43+08:002023-01-25T07:12:43+08:00

    好问题。

    使用第 7 层 HTTP(S) 负载均衡器,您通常会得到一个“反向代理”样式的负载均衡器。在那种情况下,您(至少)会得到两个独立的连接;与客户端的 TCP 连接在反向代理上终止,反向代理建立并维护自己与后端服务器的连接(池)。

    客户端与反向代理交换 HTTP(S) 协议消息,反向代理随后与后端服务器交换它自己的 HTTP(S) 协议消息。

    在这样的设置中,没有理由无法在多个后端上平衡来自同一客户端通过同一 TCP 连接的后续 HTTP(S) 请求。

    请注意,当您必须处理封装在 HTTP(S) 中的许多其他协议之一时,可能需要特别考虑。不管怎样,首选配置通常是某种形式的会话持久性/粘性,以确保来自同一客户端的后续请求确实进入同一后端服务器。

    一切当然取决于你如何配置和调整你的负载均衡器......

    https://docs.haproxy.org/2.7/configuration.html#4

    In layer 7 mode, HAProxy analyzes the
    protocol, and can interact with it by allowing, blocking, switching, adding,
    modifying, or removing arbitrary contents in requests or responses, based on
    arbitrary criteria.
    
    In HTTP mode, the processing applied to requests and responses flowing over
    a connection depends in the combination of the frontend's HTTP options and
    the backend's. HAProxy supports 3 connection modes :
    
      - KAL : keep alive ("option http-keep-alive") which is the default mode : all
        requests and responses are processed, and connections remain open but idle
        between responses and new requests.
    
      - SCL: server close ("option http-server-close") : the server-facing
        connection is closed after the end of the response is received, but the
        client-facing connection remains open.
    
      - CLO: close ("option httpclose"): the connection is closed after the end of
        the response and "Connection: close" appended in both directions.
    
    The effective mode that will be applied to a connection passing through a
    frontend and a backend can be determined by both proxy modes according to the
    following matrix, 
    

    ……
    等等
    ……

    以及许多更复杂的选项。

    • 1

相关问题

  • 网络负载平衡服务器无法相互通信

  • 用于网络监控的路由/代理 SNMP 陷阱(或 Netflow、通用 UDP 等)的解决方案?

  • 防止拒绝服务攻击的最佳技术是什么?

  • 添加备份互联网连接需要哪些硬件?

  • 什么是最有效的 Windows 负载平衡解决方案?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve