gpt4 book ai didi

Nginx 轮询负载均衡不如预期

转载 作者:行者123 更新时间:2023-12-01 09:04:40 24 4
gpt4 key购买 nike

我们正在连接到一个系统,其中暴露了 4 个端口来服务 grpc 请求。使用 nginx 作为负载均衡器来转发 4 个客户端 grpc 请求,配置如下:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream backend{
#least_conn;
server localhost:9000 weight=1 max_conns=1;
server localhost:9001 weight=1 max_conns=1;
server localhost:9002 weight=1 max_conns=1;
server localhost:9003 weight=1 max_conns=1;
}

server {
listen 80 http2;

access_log /tmp/access.log main;
error_log /tmp/error.log error;

proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header Host $http_host;

location / {
#eepalive_timeout 0;
grpc_pass grpc://backend;
grpc_pass_header userid;
grpc_pass_header transid;
}
}
}

可以观察到,所有客户端 4 请求很少会发送到所有 4 个端口,但有时(比如 30%)只发送到 2 个端口/3 个端口。似乎 NGINX 没有像预期的那样发生默认的循环。我们尝试了所有可能性,例如 max_conns、least_conn、重量,但没有运气。

好像我遇到了以下链接中的问题:
https://serverfault.com/questions/895116/nginx-round-robin-nor-exactly-round-robin
https://stackoverflow.com/questions/40859396/how-to-test-load-balancing-in-nginx

当我浏览 Quora 时,发现 nginx 中的“公平”模块可以解决这个问题。
    "The Nginx fair proxy balancer enhances the standard round-robin load 
balancer provided with Nginx so that it will track busy back end servers (e.g. Thin, Ebb, Mongrel) and balance the load to non-busy server processes. "

https://www.quora.com/What-is-the-best-way-to-get-Nginx-to-do-smart-load-balancing

我尝试从源代码中使用 NGINX 的“公平”模块,但遇到了很多问题。我无法启动 NGINX 本身。任何人都可以帮助解决这个问题吗?

最佳答案

我们得到了答案!!!!刚刚更改了“worker_processes auto;”到“worker_processes 1;”现在,它工作正常。

所有请求都正确地进行了负载平衡。在这里,我们觉得如果您使用单个工作人员以外的其他工作人员,多个工作人员可能会将请求发送到同一个端口。

关于Nginx 轮询负载均衡不如预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55257595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com