summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats/counters.h
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2017-06-19 12:31:04 -0400
committerAndrew Morrow <acm@mongodb.com>2017-07-07 11:46:22 -0400
commitbe4c4f1fffe6ca69fb67ee872b52b3bd4e630659 (patch)
treef108ff1be7db009f20d9608fc030864cf683b2eb /src/mongo/db/stats/counters.h
parent3ee00dd0e8f36c6223524012e925055e94b05080 (diff)
downloadmongo-be4c4f1fffe6ca69fb67ee872b52b3bd4e630659.tar.gz
SERVER-29534 Place network and op counters on independent cache lines
Diffstat (limited to 'src/mongo/db/stats/counters.h')
-rw-r--r--src/mongo/db/stats/counters.h41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/mongo/db/stats/counters.h b/src/mongo/db/stats/counters.h
index 435542beb37..1522da5b1aa 100644
--- a/src/mongo/db/stats/counters.h
+++ b/src/mongo/db/stats/counters.h
@@ -35,6 +35,7 @@
#include "mongo/util/concurrency/spin_lock.h"
#include "mongo/util/net/message.h"
#include "mongo/util/processinfo.h"
+#include "mongo/util/with_alignment.h"
namespace mongo {
@@ -80,14 +81,12 @@ public:
private:
void _checkWrap();
- // todo: there will be a lot of cache line contention on these. need to do something
- // else eventually.
- AtomicUInt32 _insert;
- AtomicUInt32 _query;
- AtomicUInt32 _update;
- AtomicUInt32 _delete;
- AtomicUInt32 _getmore;
- AtomicUInt32 _command;
+ CacheAligned<AtomicUInt32> _insert;
+ CacheAligned<AtomicUInt32> _query;
+ CacheAligned<AtomicUInt32> _update;
+ CacheAligned<AtomicUInt32> _delete;
+ CacheAligned<AtomicUInt32> _getmore;
+ CacheAligned<AtomicUInt32> _command;
};
extern OpCounters globalOpCounters;
@@ -96,19 +95,31 @@ extern OpCounters replOpCounters;
class NetworkCounter {
public:
// Increment the counters for the number of bytes read directly off the wire
- void hitPhysical(long long bytesIn, long long bytesOut);
+ void hitPhysicalIn(long long bytes);
+ void hitPhysicalOut(long long bytes);
+
// Increment the counters for the number of bytes passed out of the TransportLayer to the
// server
- void hitLogical(long long bytesIn, long long bytesOut);
+ void hitLogicalIn(long long bytes);
+ void hitLogicalOut(long long bytes);
+
void append(BSONObjBuilder& b);
private:
- AtomicInt64 _physicalBytesIn{0};
- AtomicInt64 _physicalBytesOut{0};
- AtomicInt64 _logicalBytesIn{0};
- AtomicInt64 _logicalBytesOut{0};
+ CacheAligned<AtomicInt64> _physicalBytesIn{0};
+ CacheAligned<AtomicInt64> _physicalBytesOut{0};
+
+ // These two counters are always incremented at the same time, so
+ // we place them on the same cache line.
+ struct Together {
+ AtomicInt64 logicalBytesIn{0};
+ AtomicInt64 requests{0};
+ };
+ CacheAligned<Together> _together{};
+ static_assert(sizeof(decltype(_together)) <= stdx::hardware_constructive_interference_size,
+ "cache line spill");
- AtomicInt64 _requests{0};
+ CacheAligned<AtomicInt64> _logicalBytesOut{0};
};
extern NetworkCounter networkCounter;