net.core.somaxconn,调整 somaxconn 内核参数的值即可增加 Nginx Ingress 连接队列。nginx.conf 。在 nginx.conf 中的 listen 端口配置项中,可以通过 backlog 参数配置连接队列大小,来决定 Nginx listen 端口的连接队列大小。配置示例如下:server {listen 80 backlog=1024;...
backlog=numbersets the backlog parameter in the listen() call that limits the maximum length for the queue of pending connections. By default, backlog is set to -1 on FreeBSD, DragonFly BSD, and macOS, and to 511 on other platforms.
sysctl -w net.core.somaxconn=65535
net.ipv4.ip_local_port_range 内核参数中定义的区间随机选取。在高并发环境下,端口范围小容易导致源端口耗尽,使得部分连接异常。
TKE 环境创建的 Pod 源端口范围默认为32768 - 60999,建议执行以下命令扩大源端口范围,调整为1024 - 65535:sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_tw_reuse=1
fs.file-max 内核参数控制,TKE 默认值为838860。建议执行以下命令,将最大文件句柄数设置为1048576:sysctl -w fs.file-max=1048576
initContainers:- name: setsysctlimage: busyboxsecurityContext:privileged: truecommand:- sh- -c- |sysctl -w net.core.somaxconn=65535sysctl -w net.ipv4.ip_local_port_range="1024 65535"sysctl -w net.ipv4.tcp_tw_reuse=1sysctl -w fs.file-max=1048576
keep-alive-requests,可以设置为10000,详情请参见 keep-alive-requests。 upstream-keepalive-requests,配置方法请参见 upstream-keepalive-requests。 max-worker-connections 控制每个 worker 进程可以打开的最大连接数,TKE 环境默认为16384。在高并发环境下建议调高该参数值,例如配置为65536,调高该值可以让 Nginx 拥有处理更多连接的能力,详情请参见 max-worker-connections。apiVersion: v1kind: ConfigMapmetadata:name: nginx-ingress-controller# nginx ingress 性能优化: https://www.nginx.com/blog/tuning-nginx/data:# nginx 与 client 保持的一个长连接能处理的请求数量,默认100,高并发场景建议调高。# 参考: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#keep-alive-requestskeep-alive-requests: "10000"# nginx 与 upstream 保持长连接的最大空闲连接数 (不是最大连接数),默认 320,在高并发下场景下调大,避免频繁建联导致 TIME_WAIT 飙升。# 参考: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#upstream-keepalive-connectionsupstream-keepalive-connections: "2000"# 每个 worker 进程可以打开的最大连接数,默认 16384。# 参考: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#max-worker-connectionsmax-worker-connections: "65536"
文档反馈