Skip to content

Commit

Permalink
Disabled notifications to TapConnMap by default
Browse files Browse the repository at this point in the history
During _normal_ load the server will receive data mutations causing the
system to process events all the time. Grabbing the mutex just to send
a notification will only lead to contention on the mutex.

To avoid the thread to busy-loop we're going to do a 1 sec sleep if
there isn't _any_ work to be performed.

Change-Id: Id47e0b6cc5d6678d6db1b16e0fe00811cacfa28d
Reviewed-on: http://review.couchbase.org/10320
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information
trondn authored and chiyoung committed Oct 25, 2011
1 parent aa26168 commit 21abdf2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
6 changes: 6 additions & 0 deletions configuration.json
Expand Up @@ -264,6 +264,12 @@
"descr": "Number of seconds between a noop is sent on an idle connection",
"type": "size_t"
},
"tap_conn_map_notifications": {
"default": "false",
"descr": "Should TapConnMap use notifications or not",
"dynamic": false,
"type": "bool"
},
"vb0": {
"default": "true",
"type": "bool"
Expand Down
1 change: 1 addition & 0 deletions ep_testsuite.cc
Expand Up @@ -6346,6 +6346,7 @@ engine_test_t* get_tests(void) {

MEMCACHED_PUBLIC_API
bool setup_suite(struct test_harness *th) {
putenv(const_cast<char*>("EP-ENGINE-TESTSUITE=true"));
testHarness = *th;
return true;
}
Expand Down
31 changes: 19 additions & 12 deletions tapconnmap.cc
Expand Up @@ -60,12 +60,16 @@ class TapConnMapValueChangeListener : public ValueChangedListener {
};

TapConnMap::TapConnMap(EventuallyPersistentEngine &theEngine) :
engine(theEngine), nextTapNoop(0)
engine(theEngine), nextTapNoop(0),
doNotify(getenv("EP-ENGINE-TESTSUITE") != NULL)
{
Configuration &config = engine.getConfiguration();
tapNoopInterval = config.getTapNoopInterval();
config.addValueChangedListener("tap_noop_interval",
new TapConnMapValueChangeListener(*this));
if (config.isTapConnMapNotifications()) {
doNotify = true;
}
}

void TapConnMap::disconnect(const void *cookie, int tapKeepAlive) {
Expand All @@ -89,7 +93,9 @@ void TapConnMap::disconnect(const void *cookie, int tapKeepAlive) {
map.erase(iter);

// Notify the daemon thread so that it may reap them..
notifySync.notify();
if (doNotify) {
notifySync.notify();
}
}
}

Expand All @@ -108,7 +114,7 @@ bool TapConnMap::setEvents(const std::string &name,
shouldNotify = tp->paused; // notify if paused
}

if (shouldNotify) {
if (shouldNotify && doNotify) {
notifySync.notify();
}

Expand Down Expand Up @@ -211,7 +217,7 @@ void TapConnMap::addFlushEvent() {
shouldNotify = true;
}
}
if (shouldNotify) {
if (shouldNotify && doNotify) {
notifySync.notify();
}
}
Expand Down Expand Up @@ -419,7 +425,7 @@ void TapConnMap::scheduleBackfill(const std::set<uint16_t> &backfillVBuckets) {
shouldNotify = true;
}
}
if (shouldNotify) {
if (shouldNotify && doNotify) {
notifySync.notify();
}
}
Expand All @@ -440,7 +446,9 @@ void TapConnMap::resetReplicaChain() {
// replica vbuckets, and then backfills items to the destination.
tp->scheduleBackfill(vblist);
}
notifySync.notify();
if (doNotify) {
notifySync.notify();
}
}

void TapConnMap::notifyIOThreadMain() {
Expand Down Expand Up @@ -491,11 +499,8 @@ void TapConnMap::notifyIOThreadMain() {
}

if (shouldPause) {
double diff = nextTapNoop - now;
if (diff > 0) {
notifySync.wait(diff);
}

// We're going to do a full second wait
notifySync.wait(1.0);
if (engine.shutdown) {
return;
}
Expand Down Expand Up @@ -570,7 +575,9 @@ bool TapConnMap::closeTapConnectionByName(const std::string &name) {
tp->setDisconnect(true);
tp->paused = true;
rv = true;
notifySync.notify();
if (doNotify) {
notifySync.notify();
}
}
}
return rv;
Expand Down
8 changes: 6 additions & 2 deletions tapconnmap.hh
Expand Up @@ -196,8 +196,10 @@ public:
* Notify anyone who's waiting for tap stuff.
*/
void notify() {
LockHolder lh(notifySync);
notifySync.notify();
if (doNotify) {
LockHolder lh(notifySync);
notifySync.notify();
}
}

void wait(double howlong) {
Expand Down Expand Up @@ -312,6 +314,8 @@ private:
EventuallyPersistentEngine &engine;
size_t tapNoopInterval;
size_t nextTapNoop;

bool doNotify;
};

#endif /* TAPCONNMAP_HH */

0 comments on commit 21abdf2

Please sign in to comment.