g_maxNSEC3Iterations = ::arg().asNum("nsec3-max-iterations");
g_maxCacheEntries = ::arg().asNum("max-cache-entries");
- g_maxPacketCacheEntries = ::arg().asNum("max-packetcache-entries");
luaConfigDelayedThreads delayedLuaThreads;
try {
if (g_packetCache) {
static PeriodicTask packetCacheTask{"packetCacheTask", 5};
packetCacheTask.runIfDue(now, []() {
- g_packetCache->setMaxSize(g_maxPacketCacheEntries); // g_maxPacketCacheEntries might have changed by rec_control
g_packetCache->doPruneTo(g_maxPacketCacheEntries);
});
}
g_recCache = std::make_unique<MemRecursorCache>(::arg().asNum("record-cache-shards"));
g_negCache = std::make_unique<NegCache>(::arg().asNum("record-cache-shards") / 8);
if (!::arg().mustDo("disable-packetcache")) {
- // Only enable packet cache for thread processing queries from the outside world
- g_packetCache = std::make_unique<RecursorPacketCache>(g_maxPacketCacheEntries /*, shards */);
+ g_maxPacketCacheEntries = ::arg().asNum("max-packetcache-entries");
+ g_packetCache = std::make_unique<RecursorPacketCache>(g_maxPacketCacheEntries, ::arg().asNum("record-cache-shards")); // XXX
}
ret = serviceMain(argc, argv, startupLog);
}
try {
g_maxPacketCacheEntries = pdns::checked_stoi<uint32_t>(*begin);
+ g_packetCache->setMaxSize(g_maxPacketCacheEntries);
return "New max packetcache entries: " + std::to_string(g_maxPacketCacheEntries) + "\n";
}
catch (const std::exception& e) {
unsigned int RecursorPacketCache::s_refresh_ttlperc{0};
+void RecursorPacketCache::setShardSizes(size_t shardSize)
+{
+ for (auto& shard : d_maps) {
+ auto lock = shard.lock();
+ lock->d_shardSize = shardSize;
+ }
+}
+
uint64_t RecursorPacketCache::size() const
{
uint64_t count = 0;
shard->d_map.insert(entry);
map.d_entriesCount++;
- if (shard->d_map.size() > d_maxSize / d_maps.size()) {
+ if (shard->d_map.size() > shard->d_shardSize) {
auto& seq_idx = shard->d_map.get<SequencedTag>();
seq_idx.erase(seq_idx.begin());
map.d_entriesCount--;
size_t shardNum = 0;
size_t min = std::numeric_limits<size_t>::max();
size_t max = 0;
+ uint64_t maxSize = 0;
for (auto& shard : d_maps) {
auto lock = shard.lock();
const auto& sidx = lock->d_map.get<SequencedTag>();
const auto shardSize = lock->d_map.size();
- fprintf(filePtr.get(), "; packetcache shard %zu; size %zu\n", shardNum, shardSize);
+ fprintf(filePtr.get(), "; packetcache shard %zu; size %zu/%zu\n", shardNum, shardSize, lock->d_shardSize);
min = std::min(min, shardSize);
max = std::max(max, shardSize);
+ maxSize += lock->d_shardSize;
shardNum++;
for (const auto& entry : sidx) {
count++;
}
}
}
- fprintf(filePtr.get(), "; packetcache size: %" PRIu64 "/%zu shards: %zu min/max shard size: %zu/%zu\n", size(), d_maxSize, d_maps.size(), min, max);
+ fprintf(filePtr.get(), "; packetcache size: %" PRIu64 "/%" PRIu64 " shards: %zu min/max shard size: %zu/%zu\n", size(), maxSize, d_maps.size(), min, max);
return count;
}
using OptPBData = boost::optional<PBData>;
RecursorPacketCache(size_t maxsize, size_t shards = 1024) :
- d_maps(shards),
- d_maxSize(maxsize)
+ d_maps(shards)
{
- if (d_maxSize / d_maps.size() == 0) {
- d_maxSize = d_maps.size();
- }
+ setMaxSize(maxsize);
}
bool getResponsePacket(unsigned int tag, const std::string& queryPacket, time_t now,
bool getResponsePacket(unsigned int tag, const std::string& queryPacket, DNSName& qname, uint16_t* qtype, uint16_t* qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, uint32_t* qhash, OptPBData* pbdata, bool tcp);
void insertResponsePacket(unsigned int tag, uint32_t qhash, std::string&& query, const DNSName& qname, uint16_t qtype, uint16_t qclass, std::string&& responsePacket, time_t now, uint32_t ttl, const vState& valState, OptPBData&& pbdata, bool tcp);
- void doPruneTo(size_t maxSize = 250000);
+ void doPruneTo(size_t maxSize);
uint64_t doDump(int file);
uint64_t doWipePacketCache(const DNSName& name, uint16_t qtype = 0xffff, bool subtree = false);
void setMaxSize(size_t size)
{
- d_maxSize = size;
+ if (size < d_maps.size()) {
+ size = d_maps.size();
+ }
+ setShardSizes(size / d_maps.size());
}
[[nodiscard]] uint64_t size() const;
struct LockedContent
{
packetCache_t d_map;
+ size_t d_shardSize{0};
uint64_t d_hits{0};
uint64_t d_misses{0};
uint64_t d_contended_count{0};
// return d_maps.at(combine(hash, hash, tcp) % d_maps.size());
// }
- size_t d_maxSize;
-
static bool qrMatch(const packetCache_t::index<HashTag>::type::iterator& iter, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass);
bool checkResponseMatches(MapCombo::LockedContent& shard, std::pair<packetCache_t::index<HashTag>::type::iterator, packetCache_t::index<HashTag>::type::iterator> range, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, OptPBData* pbdata);
+ void setShardSizes(size_t shardSize);
+
public:
void preRemoval(MapCombo::LockedContent& map, const Entry& entry)
{