Skip to content

Commit a09cd0b

Browse files
daverigbytrondn
authored andcommitted
MB-29515: Replace SpinLock with std::mutex
This replaces SpinLock with std::mutex for all uses apart from Ephemeral's SequenceList[1]. Testing of this shows a ~5% improvement in throughput under daily perf. [1] Still need to test the effect of this change on Ephemeral, to see if it's a suitable change to make. Change-Id: I04d3b78bc34e2f880690b1b3e341decf8668ad09 Reviewed-on: http://review.couchbase.org/93694 Tested-by: Build Bot <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent 2c0d03e commit a09cd0b

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

engines/ep/src/connmap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ void ConnMap::addVBConnByVBId(std::shared_ptr<ConnHandler> conn, int16_t vbid) {
230230
}
231231

232232
size_t lock_num = vbid % vbConnLockNum;
233-
std::lock_guard<SpinLock> lh(vbConnLocks[lock_num]);
233+
std::lock_guard<std::mutex> lh(vbConnLocks[lock_num]);
234234
vbConns[vbid].push_back(conn);
235235
}
236236

@@ -247,6 +247,6 @@ void ConnMap::removeVBConnByVBId_UNLOCKED(const void* connCookie,
247247

248248
void ConnMap::removeVBConnByVBId(const void* connCookie, int16_t vbid) {
249249
size_t lock_num = vbid % vbConnLockNum;
250-
std::lock_guard<SpinLock> lh(vbConnLocks[lock_num]);
250+
std::lock_guard<std::mutex> lh(vbConnLocks[lock_num]);
251251
removeVBConnByVBId_UNLOCKED(connCookie, vbid);
252252
}

engines/ep/src/connmap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class ConnMap {
104104
std::unordered_map<const void*, std::shared_ptr<ConnHandler>>;
105105
CookieToConnectionMap map_;
106106

107-
std::vector<SpinLock> vbConnLocks;
107+
std::vector<std::mutex> vbConnLocks;
108108
std::vector<std::list<std::shared_ptr<ConnHandler>>> vbConns;
109109

110110
/* Handle to the engine who owns us */

engines/ep/src/dcp/dcpconnmap.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void DcpConnMap::closeStreamsDueToRollback(uint16_t vbucket) {
223223
bool DcpConnMap::handleSlowStream(uint16_t vbid,
224224
const std::string &name) {
225225
size_t lock_num = vbid % vbConnLockNum;
226-
std::lock_guard<SpinLock> lh(vbConnLocks[lock_num]);
226+
std::lock_guard<std::mutex> lh(vbConnLocks[lock_num]);
227227
std::list<std::shared_ptr<ConnHandler>>& vb_conns = vbConns[vbid];
228228

229229
for (auto itr = vb_conns.begin(); itr != vb_conns.end(); ++itr) {
@@ -368,7 +368,7 @@ void DcpConnMap::manageConnections() {
368368
void DcpConnMap::removeVBConnections(DcpProducer& prod) {
369369
for (const auto vbid : prod.getVBVector()) {
370370
size_t lock_num = vbid % vbConnLockNum;
371-
std::lock_guard<SpinLock> lh(vbConnLocks[lock_num]);
371+
std::lock_guard<std::mutex> lh(vbConnLocks[lock_num]);
372372
std::list<std::shared_ptr<ConnHandler>>& vb_conns = vbConns[vbid];
373373
for (auto itr = vb_conns.begin(); itr != vb_conns.end(); ++itr) {
374374
if (prod.getCookie() == (*itr)->getCookie()) {
@@ -381,7 +381,7 @@ void DcpConnMap::removeVBConnections(DcpProducer& prod) {
381381

382382
void DcpConnMap::notifyVBConnections(uint16_t vbid, uint64_t bySeqno) {
383383
size_t lock_num = vbid % vbConnLockNum;
384-
std::lock_guard<SpinLock> lh(vbConnLocks[lock_num]);
384+
std::lock_guard<std::mutex> lh(vbConnLocks[lock_num]);
385385

386386
std::list<std::shared_ptr<ConnHandler>>& conns = vbConns[vbid];
387387
for (auto it = conns.begin(); it != conns.end(); ++it) {

engines/ep/src/dcp/flow-control.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ENGINE_ERROR_CODE FlowControl::handleFlowCtl(
5252
if (enabled) {
5353
ENGINE_ERROR_CODE ret;
5454
uint32_t ackable_bytes = freedBytes.load();
55-
std::unique_lock<SpinLock> lh(bufferSizeLock);
55+
std::unique_lock<std::mutex> lh(bufferSizeLock);
5656
if (pendingControl) {
5757
pendingControl = false;
5858
std::string buf_size(std::to_string(bufferSize));
@@ -109,21 +109,20 @@ void FlowControl::incrFreedBytes(uint32_t bytes)
109109

110110
uint32_t FlowControl::getFlowControlBufSize(void)
111111
{
112-
std::lock_guard<SpinLock> lh(bufferSizeLock);
113112
return bufferSize;
114113
}
115114

116115
void FlowControl::setFlowControlBufSize(uint32_t newSize)
117116
{
118-
std::lock_guard<SpinLock> lh(bufferSizeLock);
117+
std::lock_guard<std::mutex> lh(bufferSizeLock);
119118
if (newSize != bufferSize) {
120119
bufferSize = newSize;
121120
pendingControl = true;
122121
}
123122
}
124123

125124
bool FlowControl::isBufferSufficientlyDrained() {
126-
std::lock_guard<SpinLock> lh(bufferSizeLock);
125+
std::lock_guard<std::mutex> lh(bufferSizeLock);
127126
return isBufferSufficientlyDrained_UNLOCKED(freedBytes.load());
128127
}
129128

engines/ep/src/dcp/flow-control.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class FlowControl {
7575
Couchbase::RelaxedAtomic<uint32_t> bufferSize;
7676

7777
/* Lock while updating buffersize and pendingControl */
78-
SpinLock bufferSizeLock;
78+
std::mutex bufferSizeLock;
7979

8080
/* To keep track of when last buffer ack was sent */
8181
rel_time_t lastBufferAck;

0 commit comments

Comments
 (0)