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

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: Created 7 years, 4 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') | net/dns/dns_session_unittest.cc » ('J')
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 NetLog* net_log) 84 NetLog* net_log)
83 : config_(config), 85 : config_(config),
84 socket_pool_(socket_pool.Pass()), 86 socket_pool_(socket_pool.Pass()),
85 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), 87 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)),
86 net_log_(net_log), 88 net_log_(net_log),
87 server_index_(0) { 89 server_index_(0) {
88 socket_pool_->Initialize(&config_.nameservers, net_log); 90 socket_pool_->Initialize(&config_.nameservers, net_log);
89 UMA_HISTOGRAM_CUSTOM_COUNTS( 91 UMA_HISTOGRAM_CUSTOM_COUNTS(
90 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 10); 92 "AsyncDNS.ServerCount", config_.nameservers.size(), 0, 10, 10);
91 for (size_t i = 0; i < config_.nameservers.size(); ++i) { 93 for (size_t i = 0; i < config_.nameservers.size(); ++i) {
92 server_stats_.push_back(new ServerStats(config_.timeout, 94 // 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.
93 rtt_buckets_.Pointer())); 95 server_stats_.push_back(
96 new ServerStats(config_.timeout, rtt_buckets_.Pointer()));
94 } 97 }
95 } 98 }
96 99
97 DnsSession::~DnsSession() { 100 DnsSession::~DnsSession() {
98 RecordServerStats(); 101 RecordServerStats();
99 } 102 }
100 103
101 int DnsSession::NextQueryId() const { return rand_callback_.Run(); } 104 int DnsSession::NextQueryId() const { return rand_callback_.Run(); }
102 105
103 unsigned DnsSession::NextFirstServerIndex() { 106 unsigned DnsSession::NextFirstServerIndex() {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } else { 205 } else {
203 UMA_HISTOGRAM_COUNTS("AsyncDNS.ServerFailuresAfterSuccess", 206 UMA_HISTOGRAM_COUNTS("AsyncDNS.ServerFailuresAfterSuccess",
204 server_stats_[index]->last_failure_count); 207 server_stats_[index]->last_failure_count);
205 } 208 }
206 } 209 }
207 } 210 }
208 } 211 }
209 212
210 213
211 base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) { 214 base::TimeDelta DnsSession::NextTimeout(unsigned server_index, int attempt) {
212 DCHECK_LT(server_index, server_stats_.size()); 215 // Respect config timeout if it exceeds |kMaxTimeoutMs|.
213 216 if (config_.timeout.InMilliseconds() > kMaxTimeoutMs)
szym 2013/07/25 22:47:24 should it be >=?
mef 2013/07/26 11:27:07 Done.
214 base::TimeDelta timeout = config_.timeout; 217 return config_.timeout;
215 // If this server has not responded successfully, then don't wait too long. 218 // Use Histogram to calculate next timeout.
szym 2013/07/25 22:47:24 nit: superfluous comment
mef 2013/07/26 11:27:07 Done.
216 if (server_stats_[server_index]->last_success.is_null()) 219 return NextTimeoutFromHistogram(server_index, attempt);
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 } 220 }
225 221
226 // Allocate a socket, already connected to the server address. 222 // Allocate a socket, already connected to the server address.
227 scoped_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket( 223 scoped_ptr<DnsSession::SocketLease> DnsSession::AllocateSocket(
228 unsigned server_index, const NetLog::Source& source) { 224 unsigned server_index, const NetLog::Source& source) {
229 scoped_ptr<DatagramClientSocket> socket; 225 scoped_ptr<DatagramClientSocket> socket;
230 226
231 socket = socket_pool_->AllocateSocket(server_index); 227 socket = socket_pool_->AllocateSocket(server_index);
232 if (!socket.get()) 228 if (!socket.get())
233 return scoped_ptr<SocketLease>(); 229 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)); 291 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs));
296 292
297 // The timeout still doubles every full round. 293 // The timeout still doubles every full round.
298 unsigned num_backoffs = attempt / config_.nameservers.size(); 294 unsigned num_backoffs = attempt / config_.nameservers.size();
299 295
300 return std::min(timeout * (1 << num_backoffs), 296 return std::min(timeout * (1 << num_backoffs),
301 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); 297 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
302 } 298 }
303 299
304 } // namespace net 300 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/dns_session_unittest.cc » ('j') | net/dns/dns_session_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698