]> granicus.if.org Git - pdns/commitdiff
remove all traces of selectmplexer, fix up pollmplexer
authorbert hubert <bert.hubert@netherlabs.nl>
Thu, 25 Jan 2018 21:57:11 +0000 (22:57 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Thu, 25 Jan 2018 21:58:07 +0000 (22:58 +0100)
select is scary when a lot of file descriptors are used. Use poll.

pdns/Makefile.am
pdns/dnsdist.cc
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/pollmplexer.cc [new symlink]
pdns/dnsdistdist/selectmplexer.cc [deleted symlink]
pdns/pollmplexer.cc
pdns/recursordist/Makefile.am
pdns/recursordist/pollmplexer.cc [new symlink]
pdns/recursordist/selectmplexer.cc [deleted symlink]
pdns/selectmplexer.cc [deleted file]

index 0aa9478746fde3cd041cb173ebb178e9e349b7dd..e3cce9a17fd9e8da54b4ffd862ef0228cf41940b 100644 (file)
@@ -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
index bd464f8ff430abdd076e83b304a088101ccef3d3..6e1e970dd3a8ae3d835a0a01075247f95b807b1a 100644 (file)
@@ -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<vector<DNSDistRuleAction> > g_rulactions;
 GlobalStateHolder<vector<DNSDistResponseRuleAction> > g_resprulactions;
 GlobalStateHolder<vector<DNSDistResponseRuleAction> > g_cachehitresprulactions;
index 30b4eddab5feebe3aa85f6c2e4b4386f4131b9af..11cd271b2ed690af54a3c39f8e3783832411147d 100644 (file)
@@ -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 (symlink)
index 0000000..008cc91
--- /dev/null
@@ -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 (symlink)
index 85b38bc..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../selectmplexer.cc
\ No newline at end of file
index 5f1a6ffb8eaeffebcc0d31c5dcb5aea3a1cde6b4..b8c565975ce62da7e84db9093b7df1dff387baae 100644 (file)
@@ -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");
index 4770fd6f341b360a8d194ed9b04861d6e11b8a85..a30b0578076df6cd4f17269f0adf7283ed74742c 100644 (file)
@@ -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 (symlink)
index 0000000..008cc91
--- /dev/null
@@ -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 (symlink)
index 85b38bc..0000000
+++ /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 (file)
index 9e3d6f7..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-#include "mplexer.hh"
-#include "sstuff.hh"
-#include <iostream>
-#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 "<<fd<<endl;
-  Socket* sock=boost::any_cast<Socket*>(parameter);
-  string packet;
-  IPEndpoint rem;
-  sock->recvFrom(packet, rem);
-  cout<<"Received "<<packet.size()<<" bytes!\n";
-}
-
-
-int main()
-{
-  Socket s(AF_INET, SOCK_DGRAM);
-  
-  IPEndpoint loc("0.0.0.0", 2000);
-  s.bind(loc);
-
-  SelectFDMultiplexer sfm;
-
-  sfm.addReadFD(s.getHandle(), &acceptData, &s);
-
-  for(int n=0; n < 100 ; ++n) {
-    sfm.run();
-  }
-  sfm.removeReadFD(s.getHandle());
-  sfm.removeReadFD(s.getHandle());
-}
-#endif
-