]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #8793 from rgacogne/auth-reserve-caches
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Wed, 12 Feb 2020 20:06:24 +0000 (21:06 +0100)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 20:06:24 +0000 (21:06 +0100)
auth: Prepare the caches' buckets in advance

pdns/auth-packetcache.cc
pdns/auth-packetcache.hh
pdns/auth-querycache.cc
pdns/auth-querycache.hh
pdns/common_startup.cc
pdns/dbdnsseckeeper.cc
pdns/dnsseckeeper.hh

index 094c1f63ba1c15aae7fdca130378d57c797d3ed7..7759c8c07156ecbcd110496de81da0feb7d0aa3b 100644 (file)
@@ -58,6 +58,14 @@ AuthPacketCache::~AuthPacketCache()
   }
 }
 
+void AuthPacketCache::MapCombo::reserve(size_t numberOfEntries)
+{
+#if BOOST_VERSION >= 105600
+  WriteLock wl(&d_mut);
+  d_map.get<HashTag>().reserve(numberOfEntries);
+#endif /* BOOST_VERSION >= 105600 */
+}
+
 bool AuthPacketCache::get(DNSPacket& p, DNSPacket& cached)
 {
   if(!d_ttl) {
index 91b41528bcc1c09562dcb445093a2f560df429b1..5fa324c99172e838630cc007d183a4103d9f2b6c 100644 (file)
@@ -66,6 +66,9 @@ public:
   void setMaxEntries(uint64_t maxEntries) 
   {
     d_maxEntries = maxEntries;
+    for (auto& shard : d_maps) {
+      shard.reserve(maxEntries / d_maps.size());
+    }
   }
   void setTTL(uint32_t ttl)
   {
@@ -115,6 +118,8 @@ private:
     MapCombo(const MapCombo&) = delete; 
     MapCombo& operator=(const MapCombo&) = delete;
 
+    void reserve(size_t numberOfEntries);
+
     pthread_rwlock_t d_mut;
     cmap_t d_map;
   };
index e790e9e16523ec67c9ee30efa9160164ab8167bf..b9b13602c15a7159bafa6c62dd91c853c15875d8 100644 (file)
@@ -59,6 +59,14 @@ AuthQueryCache::~AuthQueryCache()
   }
 }
 
+void AuthQueryCache::MapCombo::reserve(size_t numberOfEntries)
+{
+#if BOOST_VERSION >= 105600
+  WriteLock wl(&d_mut);
+  d_map.get<HashTag>().reserve(numberOfEntries);
+#endif /* BOOST_VERSION >= 105600 */
+}
+
 // called from ueberbackend
 bool AuthQueryCache::getEntry(const DNSName &qname, const QType& qtype, vector<DNSZoneRecord>& value, int zoneID)
 {
index 2dd27c835d9e4bae4e87e39f3a27d42e8f82aedc..5fc4c55e308941e41085b3367f65c53073bae9f4 100644 (file)
@@ -56,6 +56,9 @@ public:
   void setMaxEntries(uint64_t maxEntries)
   {
     d_maxEntries = maxEntries;
+    for (auto& shard : d_maps) {
+      shard.reserve(maxEntries / d_maps.size());
+    }
   }
 private:
 
@@ -98,6 +101,8 @@ private:
     MapCombo(const MapCombo &) = delete; 
     MapCombo & operator=(const MapCombo &) = delete;
 
+    void reserve(size_t numberOfEntries);
+
     pthread_rwlock_t d_mut;
     cmap_t d_map;
   };
index 8da7f9c10c558c0f6812733f861c5483fdb36e32..3b0e93b0bd83c75d19db36e60f09ca3b50fa53a6 100644 (file)
@@ -546,6 +546,7 @@ void mainthread()
    PC.setTTL(::arg().asNum("cache-ttl"));
    PC.setMaxEntries(::arg().asNum("max-packet-cache-entries"));
    QC.setMaxEntries(::arg().asNum("max-cache-entries"));
+   DNSSECKeeper::setMaxEntries(::arg().asNum("max-cache-entries"));
 
    if (!PC.enabled() && ::arg().mustDo("log-dns-queries")) {
      g_log<<Logger::Warning<<"Packet cache disabled, logging queries without HIT/MISS"<<endl;
index a3bd4ac45c865d5b98d742433a41c6d9a927f3b8..e7f42a14770258378e8dddde6e52c60955b971dc 100644 (file)
@@ -51,6 +51,7 @@ pthread_rwlock_t DNSSECKeeper::s_metacachelock = PTHREAD_RWLOCK_INITIALIZER;
 pthread_rwlock_t DNSSECKeeper::s_keycachelock = PTHREAD_RWLOCK_INITIALIZER;
 AtomicCounter DNSSECKeeper::s_ops;
 time_t DNSSECKeeper::s_last_prune;
+size_t DNSSECKeeper::s_maxEntries = 0;
 
 bool DNSSECKeeper::doesDNSSEC()
 {
@@ -860,12 +861,21 @@ void DNSSECKeeper::cleanup()
   if(now.tv_sec - s_last_prune > (time_t)(30)) {
     {
         WriteLock l(&s_metacachelock);
-        pruneCollection<SequencedTag>(*this, s_metacache, ::arg().asNum("max-cache-entries"));
+        pruneCollection<SequencedTag>(*this, s_metacache, s_maxEntries);
     }
     {
         WriteLock l(&s_keycachelock);
-        pruneCollection<SequencedTag>(*this, s_keycache, ::arg().asNum("max-cache-entries"));
+        pruneCollection<SequencedTag>(*this, s_keycache, s_maxEntries);
     }
-    s_last_prune=time(0);
+    s_last_prune = time(nullptr);
   }
 }
+
+void DNSSECKeeper::setMaxEntries(size_t maxEntries)
+{
+  s_maxEntries = maxEntries;
+#if BOOST_VERSION >= 105600
+  WriteLock wl(&s_keycachelock);
+  s_keycache.get<KeyCacheTag>().reserve(s_maxEntries);
+#endif /* BOOST_VERSION >= 105600 */
+}
index 92df79203d0c93a6f388a29a1d936446c013634e..c2fa1c0ab631b72475da626931492002d9d93ac6 100644 (file)
@@ -235,6 +235,9 @@ public:
   void getSoaEdit(const DNSName& zname, std::string& value);
   bool unSecureZone(const DNSName& zone, std::string& error, std::string& info);
   bool rectifyZone(const DNSName& zone, std::string& error, std::string& info, bool doTransaction);
+
+  static void setMaxEntries(size_t maxEntries);
+
 private:
 
 
@@ -277,6 +280,7 @@ private:
       sequenced<tag<SequencedTag>>
     >
   > keycache_t;
+
   typedef multi_index_container<
     METACacheEntry,
     indexed_by<
@@ -298,6 +302,7 @@ private:
   static pthread_rwlock_t s_keycachelock;
   static AtomicCounter s_ops;
   static time_t s_last_prune;
+  static size_t s_maxEntries;
 
 public:
   void preRemoval(const KeyCacheEntry&)