From 80aa07f5599d3501f3921a8289d861ee79f81d24 Mon Sep 17 00:00:00 2001 From: spacewander Date: Sat, 1 Feb 2020 20:03:18 +0800 Subject: [PATCH] feature: make the number of file is as configurable as the connections. --- bin/apisix | 9 ++++++++- conf/config.yaml | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/apisix b/bin/apisix index 89b26326258e..0102c389c135 100755 --- a/bin/apisix +++ b/bin/apisix @@ -88,7 +88,7 @@ worker_cpu_affinity auto; error_log {* error_log *} {* error_log_level or "error" *}; pid logs/nginx.pid; -worker_rlimit_nofile 20480; +worker_rlimit_nofile {* worker_rlimit_nofile *}; events { accept_mutex off; @@ -524,6 +524,13 @@ local function init() sys_conf[k] = v end + local wrn = sys_conf["worker_rlimit_nofile"] + local wc = sys_conf["event"]["worker_connections"] + if not wrn or wrn <= wc then + -- ensure the number of fds is slightly larger than the number of conn + sys_conf["worker_rlimit_nofile"] = wc + 128 + end + if(sys_conf["enable_dev_mode"] == true) then sys_conf["worker_processes"] = 1 else diff --git a/conf/config.yaml b/conf/config.yaml index 18d1ec3f4113..274a8cfed08c 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -59,6 +59,7 @@ apisix: nginx_config: # config for render the template to genarate nginx.conf error_log: "logs/error.log" error_log_level: "warn" # warn,error + worker_rlimit_nofile: 20480 # the number of files a worker process can open, should be larger than worker_connections event: worker_connections: 10620 http: