Chromium Code Reviews| Index: net/dns/dns_session.cc |
| diff --git a/net/dns/dns_session.cc b/net/dns/dns_session.cc |
| index 67d5779e4d237355d4cc0d6e48d7628479b9bef2..01da93e2b1b47e4c876e8107b26906defa81b633 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. |
| @@ -89,8 +91,9 @@ DnsSession::DnsSession(const DnsConfig& config, |
| UMA_HISTOGRAM_CUSTOM_COUNTS( |
| "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 10); |
| for (size_t i = 0; i < config_.nameservers.size(); ++i) { |
| - server_stats_.push_back(new ServerStats(config_.timeout, |
| - rtt_buckets_.Pointer())); |
| + // Histogram-based method. |
|
szym
2013/07/25 22:47:24
This comment can be misleading. Suggest undoing th
mef
2013/07/26 11:27:07
Done.
|
| + server_stats_.push_back( |
| + new ServerStats(config_.timeout, rtt_buckets_.Pointer())); |
| } |
| } |
| @@ -209,18 +212,11 @@ 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) |
|
szym
2013/07/25 22:47:24
should it be >=?
mef
2013/07/26 11:27:07
Done.
|
| + return config_.timeout; |
| + // Use Histogram to calculate next timeout. |
|
szym
2013/07/25 22:47:24
nit: superfluous comment
mef
2013/07/26 11:27:07
Done.
|
| + return NextTimeoutFromHistogram(server_index, attempt); |
| } |
| // Allocate a socket, already connected to the server address. |