Open diaosj opened 6 months ago
- To achieve load balancing based on the number of requests, would it be necessary to configure Nginx to use a single worker and disable
keepalive
least active connection.
To achieve load balancing based on the number of requests, would it be necessary to configure Nginx to use a single worker and disable keepalive? Specifically, are these the configurations to adjust?
I'm saying this by my obvious reasoning that you don't have to do this to make it work. If least-conn
was supposed to be used this way, it would make no sense.
To achieve load balancing based on the number of requests, would it be necessary to configure Nginx to use a single worker and disable keepalive? Specifically, are these the configurations to adjust?
I'm saying this by my obvious reasoning that you don't have to do this to make it work. If
least-conn
was supposed to be used this way, it would make no sense.
Thank you for your response.
May I clarify if this implies that the least_conn
algorithm is independent of the keepalive
setting? In my understanding, if keepalive connections are reused, wouldn't this result in an inaccurate count of connections for each node in the upstream? Greatly appreciate your insight on this matter.
wouldn't this result in an inaccurate count of connections for each node in the upstream
least active connection. When the pool has an idle connection, the least active connection policy will be satisfied. Worker will count the upstream with the smallest number of active connections. Connection will not close if keepalive
and http request with header connection: keep-alive. Worker will monitor the status of this connection in pool.
Description
Hi,
I have some questions about the
least_conn
load balancing algorithm and would appreciate some clarification:I want to confirm my understanding: When using least_conn, the metric used is the number of connections in Nginx rather than the actual number of requests to the upstream servers. To achieve load balancing based on the number of requests, would it be necessary to configure Nginx to use a single worker and disable
keepalive
? Specifically, are these the configurations to adjust?By doing so, would this effectively balance the load based on the number of requests received by the upstream servers?
Upon reviewing the code for the
least_conn
algorithm, I noticed that the weight is updated in theafter_balance()
method, which is called during thehttp_log_phase
. init.lualeast_conn.lua
At this stage, has the request/connection already been released? Could updating at this time cause a brief inaccuracy in the connection count? Might this lead to a slight imbalance in the distribution of a small number of requests?
Thank you for your time and assistance.
Environment
apisix version
): 2.7uname -a
): Linux ti-ai-gateway-yuewen-84f46c6c74-2s5qt 5.4.119-1-tlinux4-0009-eks #1 SMP Wed Jan 3 17:12:20 CST 2024 x86_64 x86_64 x86_64 GNU/Linuxopenresty -V
ornginx -V
):curl http://127.0.0.1:9090/v1/server_info
):luarocks --version
):