From 926444e2c9722a134d42dbabc072728a037f20db Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 25 Jan 2018 22:57:11 +0100 Subject: [PATCH] remove all traces of selectmplexer, fix up pollmplexer select is scary when a lot of file descriptors are used. Use poll. --- pdns/Makefile.am | 4 +- pdns/dnsdist.cc | 18 ---- pdns/dnsdistdist/Makefile.am | 2 +- pdns/dnsdistdist/pollmplexer.cc | 1 + pdns/dnsdistdist/selectmplexer.cc | 1 - pdns/pollmplexer.cc | 21 ++++- pdns/recursordist/Makefile.am | 2 +- pdns/recursordist/pollmplexer.cc | 1 + pdns/recursordist/selectmplexer.cc | 1 - pdns/selectmplexer.cc | 131 ----------------------------- 10 files changed, 26 insertions(+), 156 deletions(-) create mode 120000 pdns/dnsdistdist/pollmplexer.cc delete mode 120000 pdns/dnsdistdist/selectmplexer.cc create mode 120000 pdns/recursordist/pollmplexer.cc delete mode 120000 pdns/recursordist/selectmplexer.cc delete mode 100644 pdns/selectmplexer.cc diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 0aa947874..e3cce9a17 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -945,9 +945,9 @@ nproxy_SOURCES = \ mplexer.hh \ nproxy.cc \ nsecrecords.cc \ + pollmplexer.cc \ qtype.cc \ rcpgenerator.cc rcpgenerator.hh \ - selectmplexer.cc \ sillyrecords.cc \ statbag.cc \ unix_utility.cc @@ -975,9 +975,9 @@ pdns_notify_SOURCES = \ misc.cc \ notify.cc \ nsecrecords.cc \ + pollmplexer.cc \ qtype.cc \ rcpgenerator.cc rcpgenerator.hh \ - selectmplexer.cc \ sillyrecords.cc \ statbag.cc \ unix_utility.cc diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index bd464f8ff..6e1e970dd 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -121,24 +121,6 @@ DNSDistSNMPAgent* g_snmpAgent{nullptr}; IDs are assigned by atomic increments of the socket offset. */ -/* for our load balancing, we want to support: - Round-robin - Round-robin with basic uptime checks - Send to least loaded server (least outstanding) - Send it to the first server that is not overloaded - Hashed weighted random -*/ - -/* Idea: - Multiple server groups, by default we load balance to the group with no name. - Each instance is either 'up', 'down' or 'auto', where 'auto' means that dnsdist - determines if the instance is up or not. Auto should be the default and very very good. - - In addition, to each instance you can attach a QPS object with rate & burst, which will optionally - limit the amount of queries we send there. - - If all downstreams are over QPS, we pick the fastest server */ - GlobalStateHolder > g_rulactions; GlobalStateHolder > g_resprulactions; GlobalStateHolder > g_cachehitresprulactions; diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index 30b4eddab..11cd271b2 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -119,7 +119,7 @@ dnsdist_SOURCES = \ protobuf.cc protobuf.hh \ qtype.cc qtype.hh \ remote_logger.cc remote_logger.hh \ - selectmplexer.cc \ + pollmplexer.cc \ sholder.hh \ snmp-agent.cc snmp-agent.hh \ sodcrypto.cc sodcrypto.hh \ diff --git a/pdns/dnsdistdist/pollmplexer.cc b/pdns/dnsdistdist/pollmplexer.cc new file mode 120000 index 000000000..008cc9199 --- /dev/null +++ b/pdns/dnsdistdist/pollmplexer.cc @@ -0,0 +1 @@ +../pollmplexer.cc \ No newline at end of file diff --git a/pdns/dnsdistdist/selectmplexer.cc b/pdns/dnsdistdist/selectmplexer.cc deleted file mode 120000 index 85b38bcdc..000000000 --- a/pdns/dnsdistdist/selectmplexer.cc +++ /dev/null @@ -1 +0,0 @@ -../selectmplexer.cc \ No newline at end of file diff --git a/pdns/pollmplexer.cc b/pdns/pollmplexer.cc index 5f1a6ffb8..b8c565975 100644 --- a/pdns/pollmplexer.cc +++ b/pdns/pollmplexer.cc @@ -8,6 +8,25 @@ #include "misc.hh" #include "namespaces.hh" +class PollFDMultiplexer : public FDMultiplexer +{ +public: + PollFDMultiplexer() + {} + virtual ~PollFDMultiplexer() + { + } + + virtual int run(struct timeval* tv, int timeout=500); + + virtual void addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const funcparam_t& parameter); + virtual void removeFD(callbackmap_t& cbmap, int fd); + string getName() + { + return "poll"; + } +private: +}; static FDMultiplexer* make() { @@ -46,7 +65,7 @@ bool pollfdcomp(const struct pollfd& a, const struct pollfd& b) return a.fd < b.fd; } -int PollFDMultiplexer::run(struct timeval* now, int timeout=500) +int PollFDMultiplexer::run(struct timeval* now, int timeout) { if(d_inrun) { throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n"); diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index 4770fd6f3..a30b05780 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -125,6 +125,7 @@ pdns_recursor_SOURCES = \ packetcache.hh \ pdns_recursor.cc \ pdnsexception.hh \ + pollmplexer.cc \ protobuf.cc protobuf.hh \ pubsuffix.hh pubsuffix.cc \ qtype.hh qtype.cc \ @@ -148,7 +149,6 @@ pdns_recursor_SOURCES = \ rpzloader.cc rpzloader.hh \ secpoll-recursor.cc \ secpoll-recursor.hh \ - selectmplexer.cc \ sholder.hh \ sillyrecords.cc \ snmp-agent.hh snmp-agent.cc \ diff --git a/pdns/recursordist/pollmplexer.cc b/pdns/recursordist/pollmplexer.cc new file mode 120000 index 000000000..008cc9199 --- /dev/null +++ b/pdns/recursordist/pollmplexer.cc @@ -0,0 +1 @@ +../pollmplexer.cc \ No newline at end of file diff --git a/pdns/recursordist/selectmplexer.cc b/pdns/recursordist/selectmplexer.cc deleted file mode 120000 index 85b38bcdc..000000000 --- a/pdns/recursordist/selectmplexer.cc +++ /dev/null @@ -1 +0,0 @@ -../selectmplexer.cc \ No newline at end of file diff --git a/pdns/selectmplexer.cc b/pdns/selectmplexer.cc deleted file mode 100644 index 9e3d6f7c9..000000000 --- a/pdns/selectmplexer.cc +++ /dev/null @@ -1,131 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include "mplexer.hh" -#include "sstuff.hh" -#include -#include "misc.hh" - -#include "namespaces.hh" - -static FDMultiplexer* make() -{ - return new SelectFDMultiplexer(); -} - -static struct RegisterOurselves -{ - RegisterOurselves() { - FDMultiplexer::getMultiplexerMap().insert(make_pair(1, &make)); - } -} doIt; - -void SelectFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, const boost::any& parameter) -{ - Callback cb; - cb.d_callback=toDo; - cb.d_parameter=parameter; - memset(&cb.d_ttd, 0, sizeof(cb.d_ttd)); - if(cbmap.count(fd)) - throw FDMultiplexerException("Tried to add fd "+std::to_string(fd)+ " to multiplexer twice"); - cbmap[fd]=cb; -} - -void SelectFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) -{ - if(d_inrun && d_iter->first==fd) // trying to remove us! - d_iter++; - - if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); -} - -int SelectFDMultiplexer::run(struct timeval* now, int timeout) -{ - if(d_inrun) { - throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n"); - } - fd_set readfds, writefds; - FD_ZERO(&readfds); - FD_ZERO(&writefds); - - int fdmax=0; - - for(callbackmap_t::const_iterator i=d_readCallbacks.begin(); i != d_readCallbacks.end(); ++i) { - FD_SET(i->first, &readfds); - fdmax=max(i->first, fdmax); - } - - for(callbackmap_t::const_iterator i=d_writeCallbacks.begin(); i != d_writeCallbacks.end(); ++i) { - FD_SET(i->first, &writefds); - fdmax=max(i->first, fdmax); - } - - struct timeval tv={timeout / 1000 , (timeout % 1000) * 1000}; - int ret=select(fdmax + 1, &readfds, &writefds, 0, &tv); - gettimeofday(now, 0); // MANDATORY! - - if(ret < 0 && errno!=EINTR) - throw FDMultiplexerException("select returned error: "+stringerror()); - - if(ret < 1) // nothing - thanks AB - return 0; - - d_iter=d_readCallbacks.end(); - d_inrun=true; - - int got = 0; - for(callbackmap_t::iterator i=d_readCallbacks.begin(); i != d_readCallbacks.end() && i->first <= fdmax; ) { - d_iter=i++; - - if(FD_ISSET(d_iter->first, &readfds)) { - d_iter->second.d_callback(d_iter->first, d_iter->second.d_parameter); - got++; - continue; // so we don't refind ourselves as writable - } - } - - for(callbackmap_t::iterator i=d_writeCallbacks.begin(); i != d_writeCallbacks.end() && i->first <= fdmax; ) { - d_iter=i++; - if(FD_ISSET(d_iter->first, &writefds)) { - d_iter->second.d_callback(d_iter->first, d_iter->second.d_parameter); - got++; - } - } - - d_inrun=false; - return got; -} - -#if 0 - -void acceptData(int fd, boost::any& parameter) -{ - cout<<"Have data on fd "<(parameter); - string packet; - IPEndpoint rem; - sock->recvFrom(packet, rem); - cout<<"Received "<