You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2021/09/21 12:25:09 UTC

[apisix] branch master updated: feat: add ulimit too small prompt (#5078)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 996ad9c  feat: add ulimit too small prompt (#5078)
996ad9c is described below

commit 996ad9c6d6d482a9aaa2b32a48ed9cedadad2d73
Author: rao yunkun <yu...@gmail.com>
AuthorDate: Tue Sep 21 20:25:04 2021 +0800

    feat: add ulimit too small prompt (#5078)
---
 apisix/cli/env.lua | 13 ++++++++++++-
 apisix/cli/ops.lua |  9 ++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/apisix/cli/env.lua b/apisix/cli/env.lua
index 0de10cb..838ef63 100644
--- a/apisix/cli/env.lua
+++ b/apisix/cli/env.lua
@@ -25,9 +25,19 @@ local stderr = io.stderr
 local str_find = string.find
 local arg = arg
 local package = package
-
+local tonumber = tonumber
 
 return function (apisix_home, pkg_cpath_org, pkg_path_org)
+    -- ulimit setting should be checked when APISIX starts
+    local res, err = util.execute_cmd("ulimit -n")
+    if not res or err ~= nil then
+        error("failed to exec ulimit cmd \'ulimit -n \', err: " .. err)
+    end
+    local ulimit = tonumber(util.trim(res))
+    if not ulimit then
+        error("failed to fetch current maximum number of open file descriptors")
+    end
+
     -- only for developer, use current folder as working space
     local is_root_path = false
     local script_path = arg[0]
@@ -80,5 +90,6 @@ return function (apisix_home, pkg_cpath_org, pkg_path_org)
         pkg_cpath_org = pkg_cpath_org,
         pkg_path_org = pkg_path_org,
         min_etcd_version = min_etcd_version,
+        ulimit = ulimit,
     }
 end
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index c670d1e..ebacd3b 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -41,7 +41,7 @@ local floor = math.floor
 local str_find = string.find
 local str_byte = string.byte
 local str_sub = string.sub
-
+local str_format = string.format
 
 local _M = {}
 
@@ -310,6 +310,13 @@ local function init(env)
               .. 'other than /root.')
     end
 
+    if env.ulimit <= 1024 then
+        print(str_format("Warning! Current maximum number of open file "
+                .. "descriptors [%d] is too small, please increase user limits by "
+                .. "execute \'ulimit -n <new user limits>\' , otherwise the performance"
+                .. " is low.", env.ulimit))
+    end
+
     -- read_yaml_conf
     local yaml_conf, err = file.read_yaml_conf(env.apisix_home)
     if not yaml_conf then