summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-14 05:56:26 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-14 05:56:26 +0000
commit640b44fa8d4b550db0614c087766632034c177bf (patch)
tree4f7b46d8f828bfa97f3c7257ec56543b20caed88
parente3d34873ab955eb0acc8f820d4c4c97a110ed9e2 (diff)
downloadchromium_src-640b44fa8d4b550db0614c087766632034c177bf.zip
chromium_src-640b44fa8d4b550db0614c087766632034c177bf.tar.gz
chromium_src-640b44fa8d4b550db0614c087766632034c177bf.tar.bz2
Replaced sync thread nudge queue with a single pending nudge.
This partially fixes a high QPS issue we're seeing with notifications. BUG=55279 TEST=Manually Review URL: http://codereview.chromium.org/3410002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59336 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync/engine/syncer_thread.cc32
-rw-r--r--chrome/browser/sync/engine/syncer_thread.h24
2 files changed, 30 insertions, 26 deletions
diff --git a/chrome/browser/sync/engine/syncer_thread.cc b/chrome/browser/sync/engine/syncer_thread.cc
index a3f9da8..92322b4 100644
--- a/chrome/browser/sync/engine/syncer_thread.cc
+++ b/chrome/browser/sync/engine/syncer_thread.cc
@@ -294,10 +294,10 @@ void SyncerThread::ThreadMainLoop() {
WaitInterval::THROTTLED;
// If we are throttled, we must wait. Otherwise, wait until either the next
// nudge (if one exists) or the poll interval.
- const TimeTicks end_wait = throttled ? next_poll :
- !vault_.nudge_queue_.empty() &&
- vault_.nudge_queue_.top().first < next_poll ?
- vault_.nudge_queue_.top().first : next_poll;
+ TimeTicks end_wait = next_poll;
+ if (!throttled && !vault_.pending_nudge_time_.is_null()) {
+ end_wait = std::min(end_wait, vault_.pending_nudge_time_);
+ }
LOG(INFO) << "end_wait is " << end_wait.ToInternalValue();
LOG(INFO) << "next_poll is " << next_poll.ToInternalValue();
@@ -527,13 +527,17 @@ bool SyncerThread::UpdateNudgeSource(bool was_throttled,
}
// Update the nudge source if a new nudge has come through during the
// previous sync cycle.
- while (!vault_.nudge_queue_.empty() &&
- TimeTicks::Now() >= vault_.nudge_queue_.top().first) {
+ if (!vault_.pending_nudge_time_.is_null()) {
if (!was_throttled && !nudged) {
- nudge_source = vault_.nudge_queue_.top().second;
+ nudge_source = vault_.pending_nudge_source_;
nudged = true;
}
- vault_.nudge_queue_.pop();
+ LOG(INFO) << "Clearing pending nudge from "
+ << vault_.pending_nudge_source_
+ << " at tick "
+ << vault_.pending_nudge_time_.ToInternalValue();
+ vault_.pending_nudge_source_ = kUnknown;
+ vault_.pending_nudge_time_ = base::TimeTicks();
}
SetUpdatesSource(nudged, nudge_source, initial_sync);
return nudged;
@@ -700,8 +704,16 @@ void SyncerThread::NudgeSyncImpl(int milliseconds_from_now,
const TimeTicks nudge_time = TimeTicks::Now() +
TimeDelta::FromMilliseconds(milliseconds_from_now);
- NudgeObject nudge_object(nudge_time, source);
- vault_.nudge_queue_.push(nudge_object);
+ if (nudge_time <= vault_.pending_nudge_time_) {
+ LOG(INFO) << "Nudge for source " << source
+ << " dropped due to existing later pending nudge";
+ return;
+ }
+
+ LOG(INFO) << "Replacing pending nudge for source "
+ << source << " at " << nudge_time.ToInternalValue();
+ vault_.pending_nudge_source_ = source;
+ vault_.pending_nudge_time_ = nudge_time;
vault_field_changed_.Broadcast();
}
diff --git a/chrome/browser/sync/engine/syncer_thread.h b/chrome/browser/sync/engine/syncer_thread.h
index 687f8b7..3bf96c3 100644
--- a/chrome/browser/sync/engine/syncer_thread.h
+++ b/chrome/browser/sync/engine/syncer_thread.h
@@ -10,7 +10,6 @@
#pragma once
#include <list>
-#include <queue>
#include <vector>
#include "base/basictypes.h"
@@ -169,17 +168,6 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
// Handle of the running thread.
base::Thread thread_;
- typedef std::pair<base::TimeTicks, NudgeSource> NudgeObject;
-
- struct IsTimeTicksGreater {
- inline bool operator() (const NudgeObject& lhs, const NudgeObject& rhs) {
- return lhs.first > rhs.first;
- }
- };
-
- typedef std::priority_queue<NudgeObject, std::vector<NudgeObject>,
- IsTimeTicksGreater> NudgeQueue;
-
// Fields that are modified / accessed by multiple threads go in this struct
// for clarity and explicitness.
struct ProtectedFields {
@@ -197,9 +185,12 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
// State of the server connection.
bool connected_;
- // A queue of all scheduled nudges. One insertion for every call to
- // NudgeQueue().
- NudgeQueue nudge_queue_;
+ // kUnknown if there is no pending nudge. (Theoretically, there
+ // could be a pending nudge of type kUnknown, so it's better to
+ // check pending_nudge_time_.)
+ NudgeSource pending_nudge_source_;
+ // null iff there is no pending nudge.
+ base::TimeTicks pending_nudge_time_;
// The wait interval for to the current iteration of our main loop. This is
// only written to by the syncer thread, and since the only reader from a
@@ -213,7 +204,8 @@ class SyncerThread : public base::RefCountedThreadSafe<SyncerThread>,
pause_requested_(false),
paused_(false),
syncer_(NULL),
- connected_(false) {}
+ connected_(false),
+ pending_nudge_source_(kUnknown) {}
} vault_;
// Gets signaled whenever a thread outside of the syncer thread changes a