diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-12 19:20:51 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-12 19:20:51 +0200 |
| commit | f4ba5e54262ed2d67fdaee803a212bdafa1cf2aa (patch) | |
| tree | ba5c72255cfd8ce8317c2ec53403c2f863f7f404 | |
| parent | set file limit on zenserver test (diff) | |
| download | zen-f4ba5e54262ed2d67fdaee803a212bdafa1cf2aa.tar.xz zen-f4ba5e54262ed2d67fdaee803a212bdafa1cf2aa.zip | |
cleanup
| -rw-r--r-- | zencore/filesystem.cpp | 25 | ||||
| -rw-r--r-- | zencore/include/zencore/filesystem.h | 4 | ||||
| -rw-r--r-- | zenserver/zenserver.cpp | 48 | ||||
| -rw-r--r-- | zenstore-test/zenstore-test.cpp | 24 |
4 files changed, 33 insertions, 68 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index e2778089b..8e75ad773 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -986,6 +986,31 @@ GetRunningExecutablePath() #endif // ZEN_PLATFORM_WINDOWS } +void +InitializeOpenFileCount() +{ +#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 '{}'", zen::MakeErrorCode(Error).message()); + } + else + { + struct rlimit NewLimit = Limit; + NewLimit.rlim_cur = NewLimit.rlim_max; + ZEN_INFO("changing RLIMIT_NOFILE from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max); + + 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, zen::MakeErrorCode(Error).message()); + } + } +#endif +} + ////////////////////////////////////////////////////////////////////////// // // Testing related code follows... diff --git a/zencore/include/zencore/filesystem.h b/zencore/include/zencore/filesystem.h index d1a5f3e0c..98d2897cf 100644 --- a/zencore/include/zencore/filesystem.h +++ b/zencore/include/zencore/filesystem.h @@ -34,6 +34,10 @@ ZENCORE_API std::filesystem::path PathFromHandle(void* NativeHandle); ZENCORE_API std::filesystem::path GetRunningExecutablePath(); +/** Set the max open file handle count to max allowed for the current process on Linux and MacOS + */ +ZENCORE_API void InitializeOpenFileCount(); + struct FileContents { std::vector<IoBuffer> Data; diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index 9ee2d8b22..85d62c9f6 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -1024,28 +1024,7 @@ ZenEntryPoint::Run() InitializeLogging(ServerOptions); -#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 '{}'", zen::MakeErrorCode(Error).message()); - } - else - { - struct rlimit NewLimit = Limit; - // NewLimit.rlim_cur = 10240; - // NewLimit.rlim_max = 10240; - NewLimit.rlim_cur = NewLimit.rlim_max; - ZEN_INFO("changing RLIMIT_NOFILE from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max); - - 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, zen::MakeErrorCode(Error).message()); - } - } -#endif + zen::InitializeOpenFileCount(); ZEN_INFO(ZEN_APP_NAME " - using lock file at '{}'", LockFilePath); @@ -1185,31 +1164,10 @@ test_main(int argc, char** argv) zen::z$_forcelink(); zen::logging::InitializeLogging(); -#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 '{}'", zen::MakeErrorCode(Error).message()); - } - else - { - struct rlimit NewLimit = Limit; -// NewLimit.rlim_cur = 10240; -// NewLimit.rlim_max = 10240; - NewLimit.rlim_cur = NewLimit.rlim_max; - ZEN_INFO("changing RLIMIT_NOFILE from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max); - - 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, zen::MakeErrorCode(Error).message()); - } - } -#endif - spdlog::set_level(spdlog::level::debug); + zen::InitializeOpenFileCount(); + return doctest::Context(argc, argv).run(); } #endif diff --git a/zenstore-test/zenstore-test.cpp b/zenstore-test/zenstore-test.cpp index 6ebd60e95..704470f8e 100644 --- a/zenstore-test/zenstore-test.cpp +++ b/zenstore-test/zenstore-test.cpp @@ -23,29 +23,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) zen::zenstore_forcelinktests(); zen::logging::InitializeLogging(); - -#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 '{}'", zen::MakeErrorCode(Error).message()); - } - else - { - struct rlimit NewLimit = Limit; -// NewLimit.rlim_cur = 10240; -// NewLimit.rlim_max = 10240; - NewLimit.rlim_cur = NewLimit.rlim_max; - ZEN_INFO("changing RLIMIT_NOFILE from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max); - - 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, zen::MakeErrorCode(Error).message()); - } - } -#endif + zen::InitializeOpenFileCount(); return doctest::Context(argc, argv).run(); #else |