在某个阈值之后,我的haproxy服务器拒绝新连接(或计时),我遇到了问题。代理服务器是AWSc5.大型EC2's,有两个cpus和4GB的ram。我们站点上的两种连接类型都使用相同的配置,一种用于websocket连接,通常具有2K-4K并发连接,请求速率约为10/s;另一种配置用于正常的web流量,以nginx为后端,并发连接约400至500个,请求速率约为100-150/s。这两种连接的典型cpu使用量在have进程中约为3-5%,websocket代理使用的内存(40-60MB)占2-3%,用于web代理(30-40MB)的内存占内存的1-3%。
根据附加的配置,cpus被映射到两个cpus之间,其中一个进程和两个线程正在运行。这两种类型的通信量通常为95% (或更高) SSL通信量。我已经使用watch -n 1 'echo "show info“颇具socat unix:/run/ case /admin.sock -‘查看代理信息,以查看我是否达到了任何限制,但情况似乎并非如此。
在高流量期间,当我们开始看到问题时,我们的websocket并发连接达到了大约5K,web请求速率达到了400请求/S。我在这里提到这两台服务器,因为我知道配置可以处理高并发连接和请求速率,但我没有达到其他资源限制。在正常情况下,一切正常工作;但是,我们看到的问题是ERR_CONNECTION_TIMED_OUT (来自铬)类型错误。我从来没有看到任何502错误。我也没有看到任何其他进程在服务器上使用更多的cpu或内存。我还附加了一些其他可能相关的信息,比如设置我的限制和sysctl设置。
知道我可能错过了什么吗?我是不是读错了top和ps aux \ grep代理,看到了错误的cpu/mem使用?我是否遗漏了tcp连接限制?后端服务器(nginx/websocket)正在工作,但似乎从未上税。我们已经用更多的连接和流量加载了这些测试,并且在限制后端服务器之前很久就受到代理的限制。
非常感谢。
global
ulimit-n 300057
quiet
maxconn 150000
maxconnrate 1000
nbproc 1
nbthread 2
cpu-map auto:1/1-2 0-1
daemon
stats socket /run/haproxy/admin.sock mode 600 level admin
stats timeout 2m
log 127.0.0.1:514 local0
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
ssl-default-bind-options no-sslv3 no-tlsv10
ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL:!RC4
defaults
maxconn 150000
mode http
log global
option forwardfor
timeout client 30s
timeout server 120s
timeout connect 10s
timeout queue 60s
timeout http-request 20s
frontend default_proxy
option httplog
bind :80
bind :443 ssl crt /etc/haproxy/ssl.pem
... acl stuff which may route to a different backend
... acl for websocket traffic
use_backend websocket if websocket_acl
default_backend default_web
backend default_web
log global
option httpclose
option http-server-close
option checkcache
balance roundrobin
option httpchk HEAD /index.php HTTP/1.1\r\nHost:website.com
server web1 192.168.1.2:80 check inter 6000 weight 1
server web2 192.168.1.3:80 check inter 6000 weight 1
backend websocket
# no option checkcache
option httpclose
option http-server-close
balance roundrobin
server websocket-1 192.168.1.4:80 check inter 6000 weight 1
server websocket-2 192.168.1.5:80 check inter 6000 weight 1来自haproxy -vv的输出:
HA-Proxy version 1.8.23-1ppa1~xenial 2019/11/26
Copyright 2000-2019 Willy Tarreau <willy@haproxy.org>
Build options :
TARGET = linux2628
CPU = generic
CC = gcc
CFLAGS = -O2 -g -O2 -fPIE -fstack-protector-strong -Wformat - Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv -Wno-unused-label
OPTIONS = USE_GETADDRINFO=1 USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=1 USE_SYSTEMD=1 USE_PCRE2=1 USE_PCRE2_JIT=1 USE_NS=1
Default settings :
maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Built with OpenSSL version : OpenSSL 1.0.2g 1 Mar 2016
Running on OpenSSL version : OpenSSL 1.0.2g 1 Mar 2016
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : TLSv1.0 TLSv1.1 TLSv1.2
Built with Lua version : Lua 5.3.1
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Encrypted password support via crypt(3): yes
Built with multi-threading support.
Built with PCRE2 version : 10.21 2016-01-12
PCRE2 library supports JIT : yes
Built with zlib version : 1.2.8
Running on zlib version : 1.2.8
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with network namespace support.
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available filters :
[SPOE] spoe
[COMP] compression
[TRACE] trace* soft nofile 120000
* soft nproc 120000net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_syncookies=1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ip_local_port_range = 1024 65023
net.ipv4.tcp_max_syn_backlog = 50000
net.ipv4.tcp_max_tw_buckets = 400000
net.ipv4.tcp_max_orphans = 60000
net.ipv4.tcp_synack_retries = 3
net.core.somaxconn = 50000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_moderate_rcvbuf = 1
net.core.netdev_max_backlog = 50000
fs.epoll.max_user_instances = 10000典型的load具有330个并发连接和80 req/s ps aux \ grep haproxy输出:
root 8122 4.5 1.2 159052 46200 ? Ssl Jan28 40:56 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -sf 29790
root 12893 0.0 0.3 49720 12832 ? Ss Jan21 0:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -sf 29790操作系统是Ubuntu 16.04。
发布于 2020-02-08 16:47:18
原来答案一直盯着我的脸。我把最大连接率设为1,000。然而,显示信息显示我的连接率在10-15之间较低,所以我不认为我达到了这个极限。我只能维持最多500个请求/S(由我的后端服务器确认),每个请求都需要一个连接到客户端,另一个连接到后端。因此,我每秒使用1000个连接。
我取消了这个限制,我能够维持更高的连接率。
https://serverfault.com/questions/1000891
复制相似问题