aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-04-12 16:48:16 +0200
committerDan Engelbrecht <[email protected]>2022-04-12 17:02:41 +0200
commit69d1f328c7651489919c72f1d5b782b8caf61c20 (patch)
tree0d85f8f0f678670be84c522340d30c83810167e9 /zenserver
parentreduce number of chunks in compactcas.threadedinsert (diff)
downloadzen-69d1f328c7651489919c72f1d5b782b8caf61c20.tar.xz
zen-69d1f328c7651489919c72f1d5b782b8caf61c20.zip
set open file limit at startup
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/zenserver.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index f81deb167..d8e46baf7 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -25,6 +25,12 @@
# include <zencore/windows.h>
#endif
+#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+# include <sys/time.h>
+# include <sys/resource.h>
+# include <zencore/except.h>
+#endif
+
#if ZEN_USE_MIMALLOC
ZEN_THIRD_PARTY_INCLUDES_START
# include <mimalloc-new-delete.h>
@@ -1226,6 +1232,27 @@ main(int argc, char* argv[])
ZenWindowsService App(ServerOptions);
return App.ServiceMain();
#else
+
+#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC
+ struct rlimit Limit;
+ int Error = getrlimit(RLIMIT_NOFILE, &Limit);
+ if (Error)
+ {
+ ZEN_WARN("failed getting rlimit RLIMIT_NOFILE, reason '{}'", MakeErrorCode(Error).message());
+ }
+ else
+ {
+ struct rlimit NewLimit = Limit;
+ NewLimit.rlim_cur = 10240;
+ NewLimit.rlim_max = 10240;
+ Error = setrlimit(RLIMIT_NOFILE, &NewLimit);
+ if (Error != 0)
+ {
+ ZEN_WARN("failed to set RLIMIT_NOFILE limits from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}, reason '{}'", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max, MakeErrorCode(Error).message());
+ }
+ }
+#endif
+
if (ServerOptions.InstallService || ServerOptions.UninstallService)
{
throw std::runtime_error("Service mode is not supported on this platform");