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

Side by Side Diff: net/dns/dns_session.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « net/dns/dns_session.h ('k') | net/dns/dns_transaction.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 21 matching lines...) Expand all
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. 41 // Seed histogram with 2 samples at |rtt_estimate| timeout.
42 rtt_histogram->Accumulate(rtt_estimate.InMilliseconds(), 2); 42 rtt_histogram->Accumulate(
43 static_cast<base::HistogramBase::Sample>(rtt_estimate.InMilliseconds()),
44 2);
43 } 45 }
44 46
45 // Count of consecutive failures after last success. 47 // Count of consecutive failures after last success.
46 int last_failure_count; 48 int last_failure_count;
47 49
48 // Last time when server returned failure or timeout. 50 // Last time when server returned failure or timeout.
49 base::Time last_failure; 51 base::Time last_failure;
50 // Last time when server returned success. 52 // Last time when server returned success.
51 base::Time last_success; 53 base::Time last_success;
52 54
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 for (size_t i = 0; i < config_.nameservers.size(); ++i) { 95 for (size_t i = 0; i < config_.nameservers.size(); ++i) {
94 server_stats_.push_back(new ServerStats(config_.timeout, 96 server_stats_.push_back(new ServerStats(config_.timeout,
95 rtt_buckets_.Pointer())); 97 rtt_buckets_.Pointer()));
96 } 98 }
97 } 99 }
98 100
99 DnsSession::~DnsSession() { 101 DnsSession::~DnsSession() {
100 RecordServerStats(); 102 RecordServerStats();
101 } 103 }
102 104
103 int DnsSession::NextQueryId() const { return rand_callback_.Run(); } 105 uint16 DnsSession::NextQueryId() const {
106 return static_cast<uint16>(rand_callback_.Run());
107 }
104 108
105 unsigned DnsSession::NextFirstServerIndex() { 109 unsigned DnsSession::NextFirstServerIndex() {
106 unsigned index = NextGoodServerIndex(server_index_); 110 unsigned index = NextGoodServerIndex(server_index_);
107 if (config_.rotate) 111 if (config_.rotate)
108 server_index_ = (server_index_ + 1) % config_.nameservers.size(); 112 server_index_ = (server_index_ + 1) % config_.nameservers.size();
109 return index; 113 return index;
110 } 114 }
111 115
112 unsigned DnsSession::NextGoodServerIndex(unsigned server_index) { 116 unsigned DnsSession::NextGoodServerIndex(unsigned server_index) {
113 unsigned index = server_index; 117 unsigned index = server_index;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // Using parameters: alpha = 1/8, delta = 1/4, beta = 4 179 // Using parameters: alpha = 1/8, delta = 1/4, beta = 4
176 base::TimeDelta& estimate = server_stats_[server_index]->rtt_estimate; 180 base::TimeDelta& estimate = server_stats_[server_index]->rtt_estimate;
177 base::TimeDelta& deviation = server_stats_[server_index]->rtt_deviation; 181 base::TimeDelta& deviation = server_stats_[server_index]->rtt_deviation;
178 base::TimeDelta current_error = rtt - estimate; 182 base::TimeDelta current_error = rtt - estimate;
179 estimate += current_error / 8; // * alpha 183 estimate += current_error / 8; // * alpha
180 base::TimeDelta abs_error = base::TimeDelta::FromInternalValue( 184 base::TimeDelta abs_error = base::TimeDelta::FromInternalValue(
181 std::abs(current_error.ToInternalValue())); 185 std::abs(current_error.ToInternalValue()));
182 deviation += (abs_error - deviation) / 4; // * delta 186 deviation += (abs_error - deviation) / 4; // * delta
183 187
184 // Histogram-based method. 188 // Histogram-based method.
185 server_stats_[server_index]->rtt_histogram 189 server_stats_[server_index]->rtt_histogram->Accumulate(
186 ->Accumulate(rtt.InMilliseconds(), 1); 190 static_cast<base::HistogramBase::Sample>(rtt.InMilliseconds()), 1);
187 } 191 }
188 192
189 void DnsSession::RecordLostPacket(unsigned server_index, int attempt) { 193 void DnsSession::RecordLostPacket(unsigned server_index, int attempt) {
190 base::TimeDelta timeout_jacobson = 194 base::TimeDelta timeout_jacobson =
191 NextTimeoutFromJacobson(server_index, attempt); 195 NextTimeoutFromJacobson(server_index, attempt);
192 base::TimeDelta timeout_histogram = 196 base::TimeDelta timeout_histogram =
193 NextTimeoutFromHistogram(server_index, attempt); 197 NextTimeoutFromHistogram(server_index, attempt);
194 UMA_HISTOGRAM_TIMES("AsyncDNS.TimeoutSpentJacobson", timeout_jacobson); 198 UMA_HISTOGRAM_TIMES("AsyncDNS.TimeoutSpentJacobson", timeout_jacobson);
195 UMA_HISTOGRAM_TIMES("AsyncDNS.TimeoutSpentHistogram", timeout_histogram); 199 UMA_HISTOGRAM_TIMES("AsyncDNS.TimeoutSpentHistogram", timeout_histogram);
196 } 200 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs)); 293 timeout = std::max(timeout, base::TimeDelta::FromMilliseconds(kMinTimeoutMs));
290 294
291 // The timeout still doubles every full round. 295 // The timeout still doubles every full round.
292 unsigned num_backoffs = attempt / config_.nameservers.size(); 296 unsigned num_backoffs = attempt / config_.nameservers.size();
293 297
294 return std::min(timeout * (1 << num_backoffs), 298 return std::min(timeout * (1 << num_backoffs),
295 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs)); 299 base::TimeDelta::FromMilliseconds(kMaxTimeoutMs));
296 } 300 }
297 301
298 } // namespace net 302 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_session.h ('k') | net/dns/dns_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698