From ee271fc486ba93bd8bee65197b54f7eeaa73fe14 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 13 Mar 2019 11:35:42 +0100 Subject: [PATCH] rec: Add a distribution-pipe-buffer-size setting --- pdns/misc.cc | 33 +++++++++++++++++++++++++++++ pdns/misc.hh | 5 ++++- pdns/pdns_recursor.cc | 16 ++++++++++++++ pdns/recursordist/docs/settings.rst | 15 +++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) 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<