From 42d539b1863c153d96f6ba7249546deb50304147 Mon Sep 17 00:00:00 2001 From: Andrea Fontana Date: Fri, 26 Apr 2024 14:40:08 +0200 Subject: [PATCH] set nofile limit for Docker containers --- source/serverino/main.d | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/serverino/main.d b/source/serverino/main.d index fe6312d..2867e65 100644 --- a/source/serverino/main.d +++ b/source/serverino/main.d @@ -123,6 +123,20 @@ template ServerinoLoop(Modules...) int mainServerinoLoop(string[] args) { + + // Docker container has a too generous limit of open files, it slows down the server + 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; + + setrlimit(RLIMIT_NOFILE, &rlim); + } + // Enable terminal colors on older windows version(Windows) {