perf(deploy): 边缘 nginx 承压调优与连接池/PG 参数(P0-2/P0-3)
- 主配置 nginx.conf 进镜像(worker_connections 16384 + rlimit 65536 + gzip + 带上游耗时的访问日志):官方默认 1024×4=4096 连接硬顶是 1w 并发第一道墙 - admin.conf:upstream keepalive 64(proxy_http 1.1 + Connection "")、 /public/ /v2-api/ 限流 50r/s burst 200(429)、代理超时 5s/30s、 /uploads/ /assets/ 30d 缓存头;admin.v2.conf 的 /v2/h5/ 哈希产物长缓存 - compose:PG 显式参数(statement_timeout=10s/max_connections=200/ shared_buffers=512MB)、DATABASE_URL connection_limit=50&pool_timeout=3 (单位秒,勿写毫秒;勿加 statement_cache_size=0)、admin ulimits nofile 65536 - 部署注意:主配置走镜像须 rebuild;PG 参数重启前按全局约束 pg_dump+快照存档
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
# 边缘 nginx 主配置(性能整改 P0-2,plans/refactor/public-capacity-10k-refactor.md)
|
||||
# 由 deploy/admin.Dockerfile COPY 进镜像替换官方默认——官方默认 worker_connections 1024
|
||||
# × 4 worker = 4096 连接硬顶,扛不住 1w 并发口径;events{} 只存在于主配置,conf.d 覆盖不了。
|
||||
# 注意:admin 与 v2-admin 共用本 Dockerfile,两侧都会得到本主配置(upstream/gzip 对
|
||||
# v2-admin 无害;worker_connections 抬升对静态服务同样受益)。
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
# 每 worker 连接预算上限(4 × 16384 客户端连接 + 上游 keepalive 连接)
|
||||
worker_rlimit_nofile 65536;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 16384;
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# 1w 并发下无访问日志无从排障:带上游耗时的结构化日志(rt=总耗时 urt=上游耗时)
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
|
||||
'rt=$request_time uct=$upstream_connect_time urt=$upstream_response_time';
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
# 压缩:API JSON(详情含 ~11KB price_matrix)与 SPA 静态资源,带宽降 5~10x
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 5;
|
||||
gzip_min_length 1024;
|
||||
gzip_types application/json application/javascript text/css text/plain text/xml image/svg+xml;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
Reference in New Issue
Block a user