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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/dns/dns_session_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/dns_session.h" 5 #include "net/dns/dns_session.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 20 matching lines...) Expand all
31 const size_t kRTTBucketCount = 100; 31 const size_t kRTTBucketCount = 100;
32 // Target percentile in the RTT histogram used for retransmission timeout. 32 // Target percentile in the RTT histogram used for retransmission timeout.
33 const unsigned kRTOPercentile = 99; 33 const unsigned kRTOPercentile = 99;
34 } // namespace 34 } // namespace
35 35
36 // Runtime statistics of DNS server. 36 // Runtime statistics of DNS server.
37 struct DnsSession::ServerStats { 37 struct DnsSession::ServerStats {
38 ServerStats(base::TimeDelta rtt_estimate_param, RttBuckets* buckets) 38 ServerStats(base::TimeDelta rtt_estimate_param, RttBuckets* buckets)
39 : last_failure_count(0), rtt_estimate(rtt_estimate_param) { 39 : last_failure_count(0), rtt_estimate(rtt_estimate_param) {
40 rtt_histogram.reset(new base::SampleVector(buckets)); 40 rtt_histogram.reset(new base::SampleVector(buckets));
41 // Seed histogram with 2 samples at |rtt_estimate| timeout.
42 rtt_histogram->Accumulate(rtt_estimate.InMilliseconds(), 2);
41 } 43 }
42 44
43 // Count of consecutive failures after last success. 45 // Count of consecutive failures after last success.
44 int last_failure_count; 46 int last_failure_count;
45 47
46 // Last time when server returned failure or timeout. 48 // Last time when server returned failure or timeout.
47 base::Time last_failure; 49 base::Time last_failure;
48 // Last time when server returned success. 50 // Last time when server returned success.
49 base::Time last_success; 51 base::Time last_success;
50 52
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } else { 204 } else {
203 UMA_HISTOGRAM_COUNTS("AsyncDNS.ServerFailuresAfterSuccess", 205 UMA_HISTOGRAM_COUNTS("AsyncDNS.ServerFailuresAfterSuccess",
204 server_stats_[index]->last_failure_count); 206 server_stats_[index]->last_failure_count);
205 } 207 }
206 } 208 }
207 } 209 }
208 } 210 }
209 211
210 212
211 base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) { 213 base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) {
212 DCHECK_LT(server_index, server_stats_.size()); 214 // Respect config timeout if it exceeds |kMaxTimeoutMs|.
213 215 if (config_.timeout.InMilliseconds() >= kMaxTimeoutMs)
214 base::TimeDelta timeout = config_.timeout; 216 return config_.timeout;
215 // If this server has not responded successfully, then don't wait too long. 217 return NextTimeoutFromHistogram(server_index, attempt);
216 if (server_stats_[server_index]->last_success.is_null())
217 return timeout;
218
219 // The timeout doubles every full round (each nameserver once).
220 unsigned num_backoffs = attempt / config_.nameservers.size();
221
222 return std::min(timeout * (1 << num_backoffs),
223 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
224 } 218 }
225 219
226 // Allocate a socket, already connected to the server address. 220 // Allocate a socket, already connected to the server address.
227 scoped_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket( 221 scoped_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket(
228 unsigned server_index, const NetLog::Source& source) { 222 unsigned server_index, const NetLog::Source& source) {
229 scoped_ptr<DatagramClientSocket> socket; 223 scoped_ptr<DatagramClientSocket> socket;
230 224
231 socket = socket_pool_->AllocateSocket(server_index); 225 socket = socket_pool_->AllocateSocket(server_index);
232 if (!socket.get()) 226 if (!socket.get())
233 return scoped_ptr<SocketLease>(); 227 return scoped_ptr<SocketLease>();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); 289 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs));
296 290
297 // The timeout still doubles every full round. 291 // The timeout still doubles every full round.
298 unsigned num_backoffs = attempt / config_.nameservers.size(); 292 unsigned num_backoffs = attempt / config_.nameservers.size();
299 293
300 return std::min(timeout * (1 << num_backoffs), 294 return std::min(timeout * (1 << num_backoffs),
301 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); 295 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
302 } 296 }
303 297
304 } // namespace net 298 } // namespace net
OLDNEW
« 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