HA代理分组请求

HA proxy grouping requests

我正在使用 HA 代理作为负载平衡器。 我已经指定了两个节点以循环方式进行负载平衡。如果我 post 手动请求,一切正常,我可以看到请求正在以循环方式路由到每个节点。当我使用 curl 触发大约 5000 个请求时,我看到大约 100 个请求将转到一个节点,然后 100 个请求将转到另一个节点。所以它不是根据要求交替的。我不认为这是正确的行为。我需要更改一些配置吗? 还是卷曲行为?

curl -k  <url>?name=[1-5000]

您要指示 curl 使用递增计数器发出顺序请求,这些数字在 URL 中的括号中,并且 curl 将通过 http keep-alive 重用与 HAProxy 的连接。

HAProxy 还将默认重用到后端的连接,因为这是最有效的行为,避免了建立新 TCP 连接的开销。当所有请求都来自重用连接上的单个客户端且并发性为 1 时,没有理由人为地强制执行循环分配。

您可以使用多个选项之一强制更改此行为,但这应该是不必要的,因为这主要是您的测试方法的产物。

By default HAProxy operates in keep-alive mode with regards to persistent connections: for each connection it processes each request and response, and leaves the connection idle on both sides between the end of a response and the start of a new request. This mode may be changed by several options such as "option http-server-close", "option forceclose", "option httpclose" or "option http-tunnel". Setting "option http-server-close" enables HTTP connection-close mode on the server side while keeping the ability to support HTTP keep-alive and pipelining on the client side. This provides the lowest latency on the client side (slow network) and the fastest session reuse on the server side to save server resources, similarly to "option forceclose". It also permits non-keepalive capable servers to be served in keep-alive mode to the clients if they conform to the requirements of RFC7230. Please note that some servers do not always conform to those requirements when they see "Connection: close" in the request. The effect will be that keep-alive will never be used. A workaround consists in enabling "option http-pretend-keepalive".

http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4-option%20http-server-close

那么为什么它每 ~100 次交替一次?保持连接通常不能无限期地使用,因此客户端或服务器最终将关闭连接并建立新的连接。