uint32_t hash{0};
uint16_t qtype{0};
bool tcp{false};
-
- time_t getTTD() const
- {
- return ttd;
- }
};
struct HashTag{};
bool d_cleanskipped{false};
static const unsigned int s_mincleaninterval=1000, s_maxcleaninterval=300000;
-
-public:
- void preRemoval(const CacheEntry&)
- {
- }
};
mutable time_t ttd{0};
uint16_t qtype{0};
int zoneID{-1};
-
- time_t getTTD() const
- {
- return ttd;
- }
};
struct HashTag{};
bool d_cleanskipped{false};
static const unsigned int s_mincleaninterval=1000, s_maxcleaninterval=300000;
-
-public:
- void preRemoval(const CacheEntry&)
- {
- }
};
auto& sidx = boost::multi_index::get<S>(mc.d_map);
uint64_t erased = 0, lookedAt = 0;
for(auto i = sidx.begin(); i != sidx.end(); lookedAt++) {
- if (i->getTTD() < now) {
+ if (i->ttd < now) {
i = sidx.erase(i);
erased++;
} else {
container.preRemoval(*i);
i = sidx.erase(i);
erased++;
+ mc.d_entriesCount--;
} else {
++i;
}
auto i = sidx.begin();
container.preRemoval(*i);
i = sidx.erase(i);
+ mc.d_entriesCount--;
totErased++;
toTrim--;
if (toTrim == 0)
static time_t lastOutputTime;
static uint64_t lastQueryCount;
- uint64_t cacheHits = broadcastAccFunction<uint64_t>(pleaseGetCacheHits);
- uint64_t cacheMisses = broadcastAccFunction<uint64_t>(pleaseGetCacheMisses);
+ uint64_t cacheHits = s_RC->cacheHits;
+ uint64_t cacheMisses = s_RC->cacheMisses;
+ uint64_t cacheSize = s_RC->size();
if(g_stats.qcounter && (cacheHits + cacheMisses) && SyncRes::s_queries && SyncRes::s_outqueries) {
g_log<<Logger::Notice<<"stats: "<<g_stats.qcounter<<" questions, "<<
- broadcastAccFunction<uint64_t>(pleaseGetCacheSize)<< " cache entries, "<<
+ cacheSize << " cache entries, "<<
broadcastAccFunction<uint64_t>(pleaseGetNegCacheSize)<<" negative entries, "<<
(int)((cacheHits*100.0)/(cacheHits+cacheMisses))<<"% cache hits"<<endl;
static void houseKeeping(void *)
{
- static thread_local time_t last_rootupdate, last_secpoll, last_trustAnchorUpdate{0};
- static thread_local timeval last_prune;
+ static thread_local time_t last_rootupdate, last_secpoll, last_trustAnchorUpdate{0}, last_RC_prune;
+ static thread_local struct timeval last_prune;
+
static thread_local int cleanCounter=0;
static thread_local bool s_running; // houseKeeping can get suspended in secpoll, and be restarted, which makes us do duplicate work
auto luaconfsLocal = g_luaconfs.getLocal();
past.tv_sec -= 5;
if (last_prune < past) {
t_packetCache->doPruneTo(g_maxPacketCacheEntries / g_numWorkerThreads);
-
SyncRes::pruneNegCache(g_maxCacheEntries / (g_numWorkerThreads * 10));
time_t limit;
Utility::gettimeofday(&last_prune, nullptr);
}
- if(now.tv_sec - last_rootupdate > 7200) {
- int res = SyncRes::getRootNS(g_now, nullptr);
- if (!res) {
- last_rootupdate=now.tv_sec;
- primeRootNSZones(g_dnssecmode != DNSSECMode::Off);
- }
- }
-
if(isHandlerThread()) {
+ if (now.tv_sec - last_RC_prune > 5) {
+ s_RC->doPrune(g_maxCacheEntries);
+ last_RC_prune = now.tv_sec;
+ }
+ // XXX !!! global
+ if(now.tv_sec - last_rootupdate > 7200) {
+ int res = SyncRes::getRootNS(g_now, nullptr);
+ if (!res) {
+ last_rootupdate=now.tv_sec;
+ primeRootNSZones(g_dnssecmode != DNSSECMode::Off);
+ }
+ }
if(now.tv_sec - last_secpoll >= 3600) {
try {
static uint64_t* pleaseDump(int fd)
{
- return new uint64_t(s_RC->doDump(fd) + dumpNegCache(SyncRes::t_sstorage.negcache, fd) + t_packetCache->doDump(fd));
+ return new uint64_t(dumpNegCache(SyncRes::t_sstorage.negcache, fd) + t_packetCache->doDump(fd));
}
static uint64_t* pleaseDumpEDNSMap(int fd)
return "Error opening dump file for writing: "+stringerror()+"\n";
uint64_t total = 0;
try {
- total = broadcastAccFunction<uint64_t>(boost::bind(pleaseDump, fd));
+ total = s_RC->doDump(fd) + broadcastAccFunction<uint64_t>(boost::bind(pleaseDump, fd));
}
catch(...){}
return broadcastAccFunction<uint64_t>(pleaseGetConcurrentQueries);
}
-uint64_t* pleaseGetCacheSize()
-{
- return new uint64_t(s_RC ? s_RC->size() : 0);
-}
-
-static uint64_t* pleaseGetCacheBytes()
-{
- return new uint64_t(s_RC ? s_RC->bytes() : 0);
-}
-
static uint64_t doGetCacheSize()
{
- return broadcastAccFunction<uint64_t>(pleaseGetCacheSize);
+ return s_RC->size();
}
static uint64_t doGetAvgLatencyUsec()
static uint64_t doGetCacheBytes()
{
- return broadcastAccFunction<uint64_t>(pleaseGetCacheBytes);
-}
-
-uint64_t* pleaseGetCacheHits()
-{
- return new uint64_t(s_RC->cacheHits);
+ return s_RC->bytes();
}
static uint64_t doGetCacheHits()
{
- return broadcastAccFunction<uint64_t>(pleaseGetCacheHits);
-}
-
-uint64_t* pleaseGetCacheMisses()
-{
- return new uint64_t(s_RC->cacheMisses);
+ return s_RC->cacheHits;
}
static uint64_t doGetCacheMisses()
{
- return broadcastAccFunction<uint64_t>(pleaseGetCacheMisses);
+ return s_RC->cacheMisses;
}
uint64_t* pleaseGetPacketCacheSize()
// XXX!
size_t count = 0;
for (auto& map : d_maps) {
- const std::lock_guard<std::mutex> lock(map.mutex);
- count += map.d_map.size();
+ count += map.d_entriesCount;
}
return count;
}
cache_t::iterator stored = map.d_map.find(key);
if (stored == map.d_map.end()) {
stored = map.d_map.insert(CacheEntry(key, auth)).first;
+ map.d_entriesCount++;
isNew = true;
}
size_t count = 0;
if (!sub) {
- for (auto& map : d_maps) {
- const std::lock_guard<std::mutex> lock(map.mutex);
- map.d_cachecachevalid = false;
- auto& idx = map.d_map.get<NameOnlyHashedTag>();
- count += idx.erase(name);
- if (qtype == 0xffff) {
- auto& ecsIdx = map.d_ecsIndex.get<OrderedTag>();
- auto ecsIndexRange = ecsIdx.equal_range(name);
- ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second);
- }
- else {
- auto& ecsIdx = map.d_ecsIndex.get<HashedTag>();
- auto ecsIndexRange = ecsIdx.equal_range(tie(name, qtype));
- ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second);
- }
+ auto& map = getMap(name);
+ const std::lock_guard<std::mutex> lock(map.mutex);
+ map.d_cachecachevalid = false;
+ auto& idx = map.d_map.get<NameOnlyHashedTag>();
+ size_t n = idx.erase(name);
+ count += n;
+ map.d_entriesCount -= n;
+ if (qtype == 0xffff) {
+ auto& ecsIdx = map.d_ecsIndex.get<OrderedTag>();
+ auto ecsIndexRange = ecsIdx.equal_range(name);
+ ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second);
+ }
+ else {
+ auto& ecsIdx = map.d_ecsIndex.get<HashedTag>();
+ auto ecsIndexRange = ecsIdx.equal_range(tie(name, qtype));
+ ecsIdx.erase(ecsIndexRange.first, ecsIndexRange.second);
}
}
else {
if (i->d_qtype == qtype || qtype == 0xffff) {
count++;
i = idx.erase(i);
+ map.d_entriesCount--;
} else {
++i;
}
ecsIndex_t d_ecsIndex;
DNSName d_cachedqname;
std::pair<MemRecursorCache::NameOnlyHashedTagIterator_t, MemRecursorCache::NameOnlyHashedTagIterator_t> d_cachecache;
- bool d_cachecachevalid{false};
std::mutex mutex;
+ bool d_cachecachevalid{false};
+ std::atomic<uint64_t> d_entriesCount{0};
};
vector<MapCombo> d_maps;
uint64_t* pleaseGetNsSpeedsSize();
uint64_t* pleaseGetFailedServersSize();
uint64_t* pleaseGetEDNSStatusesSize();
-uint64_t* pleaseGetCacheSize();
uint64_t* pleaseGetNegCacheSize();
-uint64_t* pleaseGetCacheHits();
-uint64_t* pleaseGetCacheMisses();
uint64_t* pleaseGetConcurrentQueries();
uint64_t* pleaseGetThrottleSize();
uint64_t* pleaseGetPacketCacheHits();