From: Remi Gacogne Date: Wed, 13 Mar 2019 10:35:42 +0000 (+0100) Subject: rec: Add a distribution-pipe-buffer-size setting X-Git-Tag: rec-4.2.0-beta1~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7571%2Fhead;p=thirdparty%2Fpdns.git rec: Add a distribution-pipe-buffer-size setting --- diff --git a/pdns/misc.cc b/pdns/misc.cc index 9b6eea36d5..1f90bbcbd1 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1485,3 +1485,36 @@ std::vector getResolvers(const std::string& resolvConfPath) return results; } + +size_t getPipeBufferSize(int fd) +{ +#ifdef F_GETPIPE_SZ + int res = fcntl(fd, F_GETPIPE_SZ); + if (res == -1) { + return 0; + } + return res; +#else + errno = ENOSYS; + return 0; +#endif /* F_GETPIPE_SZ */ +} + +bool setPipeBufferSize(int fd, size_t size) +{ +#ifdef F_SETPIPE_SZ + if (size > std::numeric_limits::max()) { + errno = EINVAL; + return false; + } + int newSize = static_cast(size); + int res = fcntl(fd, F_SETPIPE_SZ, newSize); + if (res == -1) { + return false; + } + return true; +#else + errno = ENOSYS; + return false; +#endif /* F_SETPIPE_SZ */ +} diff --git a/pdns/misc.hh b/pdns/misc.hh index 9adfe35dc4..ee255e9b90 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -537,8 +537,11 @@ bool isNonBlocking(int sock); bool setReceiveSocketErrors(int sock, int af); int closesocket(int fd); bool setCloseOnExec(int sock); -uint64_t udpErrorStats(const std::string& str); +size_t getPipeBufferSize(int fd); +bool setPipeBufferSize(int fd, size_t size); + +uint64_t udpErrorStats(const std::string& str); uint64_t getRealMemoryUsage(const std::string&); uint64_t getSpecialMemoryUsage(const std::string&); uint64_t getOpenFileDescriptors(const std::string&); diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index d0b8b121c2..1e171080c0 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2781,6 +2781,11 @@ static void houseKeeping(void *) static void makeThreadPipes() { + auto pipeBufferSize = ::arg().asNum("distribution-pipe-buffer-size"); + if (pipeBufferSize > 0) { + g_log< 0) { + if (!setPipeBufferSize(threadInfos.pipes.writeQueriesToThread, pipeBufferSize)) { + g_log< 0) { + g_log<