Skip to content

Commit

Permalink
Convert more atomics to stat_t and eliminate AtomicCounter form the r…
Browse files Browse the repository at this point in the history
…ecursor

(except in cases that are shared by with auth).

I changed two AtomicCounters to atomic<int32>; their range is limited and
they are not updated very frequently.
  • Loading branch information
omoerbeek committed Oct 13, 2021
1 parent bd46871 commit 7db617e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pdns/histogram.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#pragma once

#include <algorithm>
#include <atomic>
#include <limits>
#include <stdexcept>
#include <string>
#include <vector>

#include "stat_t.hh"

namespace pdns
{

Expand All @@ -50,7 +51,7 @@ struct AtomicBucket

const std::string d_name;
const uint64_t d_boundary{0};
mutable std::atomic<uint64_t> d_count{0};
mutable stat_t d_count{0};
};

template <class B, class SumType>
Expand Down Expand Up @@ -178,6 +179,6 @@ private:

using Histogram = BaseHistogram<Bucket, uint64_t>;

using AtomicHistogram = BaseHistogram<AtomicBucket, std::atomic<uint64_t>>;
using AtomicHistogram = BaseHistogram<AtomicBucket, pdns::stat_t>;

} // namespace pdns
4 changes: 2 additions & 2 deletions pdns/pdns_recursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ enum class PaddingMode { Always, PaddedQueries };

static listenSocketsAddresses_t g_listenSocketsAddresses; // is shared across all threads right now
static set<int> g_fromtosockets; // listen sockets that use 'sendfromto()' mechanism (without actually using sendfromto())
static AtomicCounter counter;
static std::atomic<uint32_t> counter;
static std::shared_ptr<SyncRes::domainmap_t> g_initialDomainMap; // new threads needs this to be setup
static std::shared_ptr<NetmaskGroup> g_initialAllowFrom; // new thread needs to be setup with this
static NetmaskGroup g_XPFAcl;
Expand Down Expand Up @@ -854,7 +854,7 @@ TCPConnection::~TCPConnection()
--s_currentConnections;
}

AtomicCounter TCPConnection::s_currentConnections;
std::atomic<uint32_t> TCPConnection::s_currentConnections;

static void terminateTCPConnection(int fd)
{
Expand Down
3 changes: 2 additions & 1 deletion pdns/responsestats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <array>
#include "histogram.hh"
#include "stat_t.hh"

#include "dnspacket.hh"

Expand All @@ -42,7 +43,7 @@ public:
private:
struct Counter
{
mutable std::atomic<uint64_t> value;
mutable pdns::stat_t value;
};

std::array<Counter, 65536> d_qtypecounters;
Expand Down
6 changes: 3 additions & 3 deletions pdns/syncres.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1034,8 +1034,8 @@ struct RecursorStats
pdns::AtomicHistogram cumulativeAnswers;
pdns::AtomicHistogram cumulativeAuth4Answers;
pdns::AtomicHistogram cumulativeAuth6Answers;
std::atomic<double> avgLatencyUsec;
std::atomic<double> avgLatencyOursUsec;
pdns::stat_t_trait<double> avgLatencyUsec;
pdns::stat_t_trait<double> avgLatencyOursUsec;
pdns::stat_t qcounter; // not increased for unauth packets
pdns::stat_t ipv6qcounter;
pdns::stat_t tcpqcounter;
Expand Down Expand Up @@ -1121,7 +1121,7 @@ public:
static unsigned int getCurrentConnections() { return s_currentConnections; }
private:
const int d_fd;
static AtomicCounter s_currentConnections; //!< total number of current TCP connections
static std::atomic<uint32_t> s_currentConnections; //!< total number of current TCP connections
};

class ImmediateServFailException
Expand Down

0 comments on commit 7db617e

Please sign in to comment.