Skip to content

Commit

Permalink
Workaround for RLIMIT_NOFILE issue
Browse files Browse the repository at this point in the history
  • Loading branch information
trikko committed Apr 27, 2024
1 parent 42d539b commit 1ab1dd3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/serverino/main.d
Expand Up @@ -125,15 +125,17 @@ template ServerinoLoop(Modules...)
{

// Docker container has a too generous limit of open files, it slows down the server
// NOTE: Workaround for #issue 24524
// NOTE: Waiting for https://github.com/dlang/phobos/pull/8990
version(Posix)
{
import core.sys.posix.sys.resource : rlimit, setrlimit, getrlimit, RLIMIT_NOFILE;
rlimit rlim;
getrlimit(RLIMIT_NOFILE, &rlim);

if (rlim.rlim_cur > 65536)
rlim.rlim_cur = 4096;

// 16k seems to be a good value that balances performance and resources
// until the issue is fixed
rlim.rlim_cur = max(rlim.rlim_max, 16_768);
setrlimit(RLIMIT_NOFILE, &rlim);
}

Expand Down

0 comments on commit 1ab1dd3

Please sign in to comment.