summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/dns_master.cc
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 01:34:20 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 01:34:20 +0000
commita20bc0936892ff263c48f3afebcac93af64c2348 (patch)
tree0e858c535f1dce3aa57ab4cdef84097b6f40b717 /chrome/browser/net/dns_master.cc
parent7cb25c28530dcd7739c1441588ad1deade53b5ee (diff)
downloadchromium_src-a20bc0936892ff263c48f3afebcac93af64c2348.zip
chromium_src-a20bc0936892ff263c48f3afebcac93af64c2348.tar.gz
chromium_src-a20bc0936892ff263c48f3afebcac93af64c2348.tar.bz2
Reverting 17638.
This relands http://src.chromium.org/viewvc/chrome?view=rev&revision=17605 which was reverted in 17638. It also disables MassiveConcurrentLookupTest, which was a stress test, and is partially obsolete since the class now responds to congestion produced by NOT resolving all names. BUG=13356 TBR=willchan Review URL: http://codereview.chromium.org/119196 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17697 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/dns_master.cc')
-rw-r--r--chrome/browser/net/dns_master.cc83
1 files changed, 71 insertions, 12 deletions
diff --git a/chrome/browser/net/dns_master.cc b/chrome/browser/net/dns_master.cc
index bbb450a..74fb9e5 100644
--- a/chrome/browser/net/dns_master.cc
+++ b/chrome/browser/net/dns_master.cc
@@ -360,23 +360,24 @@ DnsHostInfo* DnsMaster::PreLockedResolve(
}
info->SetQueuedState(motivation);
- name_buffer_.push(hostname);
-
+ work_queue_.Push(hostname, motivation);
PreLockedScheduleLookups();
-
return info;
}
void DnsMaster::PreLockedScheduleLookups() {
- while (!name_buffer_.empty() &&
+ while (!work_queue_.IsEmpty() &&
pending_lookups_.size() < max_concurrent_lookups_) {
- const std::string hostname(name_buffer_.front());
- name_buffer_.pop();
-
+ const std::string hostname(work_queue_.Pop());
DnsHostInfo* info = &results_[hostname];
DCHECK(info->HasHostname(hostname));
info->SetAssignedState();
+ if (PreLockedCongestionControlPerformed(info)) {
+ DCHECK(work_queue_.IsEmpty());
+ return;
+ }
+
LookupRequest* request = new LookupRequest(this, hostname);
if (request->Start()) {
pending_lookups_.insert(request);
@@ -389,14 +390,33 @@ void DnsMaster::PreLockedScheduleLookups() {
}
}
+bool DnsMaster::PreLockedCongestionControlPerformed(DnsHostInfo* info) {
+ // Note: queue_duration is ONLY valid after we go to assigned state.
+ // TODO(jar): Tune selection of arbitrary 1 second constant. Add plumbing so
+ // that this can be set as part of an A/B experiment.
+ if (info->queue_duration() < base::TimeDelta::FromSeconds(1))
+ return false;
+ // We need to discard all entries in our queue, as we're keeping them waiting
+ // too long. By doing this, we'll have a chance to quickly service urgent
+ // resolutions, and not have a bogged down system.
+ while (true) {
+ info->RemoveFromQueue();
+ if (work_queue_.IsEmpty())
+ break;
+ info = &results_[work_queue_.Pop()];
+ info->SetAssignedState();
+ }
+ return true;
+}
+
void DnsMaster::OnLookupFinished(LookupRequest* request,
const std::string& hostname, bool found) {
AutoLock auto_lock(lock_); // For map access (changing info values).
DnsHostInfo* info = &results_[hostname];
DCHECK(info->HasHostname(hostname));
- if (info->is_marked_to_delete())
+ if (info->is_marked_to_delete()) {
results_.erase(hostname);
- else {
+ } else {
if (found)
info->SetFoundState();
else
@@ -418,10 +438,9 @@ void DnsMaster::DiscardAllResults() {
// Try to delete anything in our work queue.
- while (!name_buffer_.empty()) {
+ while (!work_queue_.IsEmpty()) {
// Emulate processing cycle as though host was not found.
- std::string hostname = name_buffer_.front();
- name_buffer_.pop();
+ std::string hostname = work_queue_.Pop();
DnsHostInfo* info = &results_[hostname];
DCHECK(info->HasHostname(hostname));
info->SetAssignedState();
@@ -497,4 +516,44 @@ void DnsMaster::DeserializeReferrers(const ListValue& referral_list) {
}
}
+
+//------------------------------------------------------------------------------
+
+DnsMaster::HostNameQueue::HostNameQueue() {
+}
+
+DnsMaster::HostNameQueue::~HostNameQueue() {
+}
+
+void DnsMaster::HostNameQueue::Push(const std::string& hostname,
+ DnsHostInfo::ResolutionMotivation motivation) {
+ switch (motivation) {
+ case DnsHostInfo::STATIC_REFERAL_MOTIVATED:
+ case DnsHostInfo::LEARNED_REFERAL_MOTIVATED:
+ case DnsHostInfo::MOUSE_OVER_MOTIVATED:
+ rush_queue_.push(hostname);
+ break;
+
+ default:
+ background_queue_.push(hostname);
+ break;
+ }
+}
+
+bool DnsMaster::HostNameQueue::IsEmpty() const {
+ return rush_queue_.empty() && background_queue_.empty();
+}
+
+std::string DnsMaster::HostNameQueue::Pop() {
+ DCHECK(!IsEmpty());
+ if (!rush_queue_.empty()) {
+ std::string hostname(rush_queue_.front());
+ rush_queue_.pop();
+ return hostname;
+ }
+ std::string hostname(background_queue_.front());
+ background_queue_.pop();
+ return hostname;
+}
+
} // namespace chrome_browser_net