Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: net/dns/dns_session.cc

Issue 20482002: Use Histogram algorithm to calculate DNS timeout. Honor DnsConfig timeout if it exceeds 5s. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved unit test comments. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/dns/dns_session_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_session.cc
diff --git a/net/dns/dns_session.cc b/net/dns/dns_session.cc
index 67d5779e4d237355d4cc0d6e48d7628479b9bef2..ea8b6a142746bcc391b60e7ba20952e45e1636f6 100644
--- a/net/dns/dns_session.cc
+++ b/net/dns/dns_session.cc
@@ -38,6 +38,8 @@ struct DnsSession::ServerStats {
ServerStats(base::TimeDelta rtt_estimate_param, RttBuckets* buckets)
: last_failure_count(0), rtt_estimate(rtt_estimate_param) {
rtt_histogram.reset(new base::SampleVector(buckets));
+ // Seed histogram with 2 samples at |rtt_estimate| timeout.
+ rtt_histogram->Accumulate(rtt_estimate.InMilliseconds(), 2);
}
// Count of consecutive failures after last success.
@@ -209,18 +211,10 @@ void DnsSession::RecordServerStats() {
base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) {
- DCHECK_LT(server_index, server_stats_.size());
-
- base::TimeDelta timeout = config_.timeout;
- // If this server has not responded successfully, then don't wait too long.
- if (server_stats_[server_index]->last_success.is_null())
- return timeout;
-
- // The timeout doubles every full round (each nameserver once).
- unsigned num_backoffs = attempt / config_.nameservers.size();
-
- return std::min(timeout * (1 << num_backoffs),
- base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
+ // Respect config timeout if it exceeds |kMaxTimeoutMs|.
+ if (config_.timeout.InMilliseconds() >= kMaxTimeoutMs)
+ return config_.timeout;
+ return NextTimeoutFromHistogram(server_index, attempt);
}
// Allocate a socket, already connected to the server address.
« no previous file with comments | « no previous file | net/dns/dns_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698