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: