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

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2266663002: NQE: Change GetEffectiveConnectionType to return last ECT (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ryan's comments Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 last_connection_change_(tick_clock_->NowTicks()), 366 last_connection_change_(tick_clock_->NowTicks()),
367 current_network_id_(nqe::internal::NetworkID( 367 current_network_id_(nqe::internal::NetworkID(
368 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 368 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
369 std::string())), 369 std::string())),
370 downstream_throughput_kbps_observations_(weight_multiplier_per_second_), 370 downstream_throughput_kbps_observations_(weight_multiplier_per_second_),
371 rtt_observations_(weight_multiplier_per_second_), 371 rtt_observations_(weight_multiplier_per_second_),
372 effective_connection_type_at_last_main_frame_( 372 effective_connection_type_at_last_main_frame_(
373 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 373 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
374 external_estimate_provider_(std::move(external_estimates_provider)), 374 external_estimate_provider_(std::move(external_estimates_provider)),
375 effective_connection_type_recomputation_interval_( 375 effective_connection_type_recomputation_interval_(
376 base::TimeDelta::FromSeconds(15)), 376 base::TimeDelta::FromSeconds(10)),
377 rtt_observations_size_at_last_ect_computation_(0), 377 rtt_observations_size_at_last_ect_computation_(0),
378 throughput_observations_size_at_last_ect_computation_(0), 378 throughput_observations_size_at_last_ect_computation_(0),
379 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 379 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
380 min_signal_strength_since_connection_change_(INT32_MAX), 380 min_signal_strength_since_connection_change_(INT32_MAX),
381 max_signal_strength_since_connection_change_(INT32_MIN), 381 max_signal_strength_since_connection_change_(INT32_MIN),
382 correlation_uma_logging_probability_( 382 correlation_uma_logging_probability_(
383 GetDoubleValueForVariationParamWithDefaultValue( 383 GetDoubleValueForVariationParamWithDefaultValue(
384 variation_params, 384 variation_params,
385 "correlation_logging_probability", 385 "correlation_logging_probability",
386 0.0)), 386 0.0)),
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 if (!GetTransportRTTEstimate(&estimated_transport_rtt)) 620 if (!GetTransportRTTEstimate(&estimated_transport_rtt))
621 estimated_transport_rtt = nqe::internal::InvalidRTT(); 621 estimated_transport_rtt = nqe::internal::InvalidRTT();
622 622
623 int32_t downstream_throughput_kbps; 623 int32_t downstream_throughput_kbps;
624 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps)) 624 if (!GetDownlinkThroughputKbpsEstimate(&downstream_throughput_kbps))
625 downstream_throughput_kbps = nqe::internal::kInvalidThroughput; 625 downstream_throughput_kbps = nqe::internal::kInvalidThroughput;
626 626
627 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality( 627 estimated_quality_at_last_main_frame_ = nqe::internal::NetworkQuality(
628 estimated_http_rtt, estimated_transport_rtt, 628 estimated_http_rtt, estimated_transport_rtt,
629 downstream_throughput_kbps); 629 downstream_throughput_kbps);
630
631 RecomputeEffectiveConnectionType();
630 effective_connection_type_at_last_main_frame_ = 632 effective_connection_type_at_last_main_frame_ =
631 GetEffectiveConnectionType(); 633 GetEffectiveConnectionType();
632 634
633 RecordMetricsOnMainFrameRequest(); 635 RecordMetricsOnMainFrameRequest();
634 MaybeQueryExternalEstimateProvider(); 636 MaybeQueryExternalEstimateProvider();
635 637
636 // Post the tasks which will run in the future and record the estimation 638 // Post the tasks which will run in the future and record the estimation
637 // accuracy based on the observations received between now and the time of 639 // accuracy based on the observations received between now and the time of
638 // task execution. Posting the task at different intervals makes it 640 // task execution. Posting the task at different intervals makes it
639 // possible to measure the accuracy by comparing the estimate with the 641 // possible to measure the accuracy by comparing the estimate with the
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 base::Histogram::FactoryGet( 1153 base::Histogram::FactoryGet(
1152 std::string("NQE.MainFrame.EffectiveConnectionType.") + 1154 std::string("NQE.MainFrame.EffectiveConnectionType.") +
1153 GetNameForConnectionType(current_network_id_.type), 1155 GetNameForConnectionType(current_network_id_.type),
1154 0, EFFECTIVE_CONNECTION_TYPE_LAST, 1156 0, EFFECTIVE_CONNECTION_TYPE_LAST,
1155 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */, 1157 EFFECTIVE_CONNECTION_TYPE_LAST /* Number of buckets */,
1156 base::HistogramBase::kUmaTargetedHistogramFlag); 1158 base::HistogramBase::kUmaTargetedHistogramFlag);
1157 1159
1158 effective_connection_type_histogram->Add(effective_connection_type); 1160 effective_connection_type_histogram->Add(effective_connection_type);
1159 } 1161 }
1160 1162
1163 void NetworkQualityEstimator::RecomputeEffectiveConnectionType() {
1164 DCHECK(thread_checker_.CalledOnValidThread());
1165
1166 const base::TimeTicks now = tick_clock_->NowTicks();
1167
1168 const EffectiveConnectionType past_type = effective_connection_type_;
1169 last_effective_connection_type_computation_ = now;
1170
1171 effective_connection_type_ =
1172 GetRecentEffectiveConnectionType(base::TimeTicks());
1173
1174 if (past_type != effective_connection_type_)
1175 NotifyObserversOfEffectiveConnectionTypeChanged();
1176
1177 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size();
1178 throughput_observations_size_at_last_ect_computation_ =
1179 downstream_throughput_kbps_observations_.Size();
1180 }
1181
1161 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType() 1182 EffectiveConnectionType NetworkQualityEstimator::GetEffectiveConnectionType()
1162 const { 1183 const {
1163 DCHECK(thread_checker_.CalledOnValidThread()); 1184 DCHECK(thread_checker_.CalledOnValidThread());
1164 return GetRecentEffectiveConnectionType(base::TimeTicks()); 1185 return effective_connection_type_;
1165 } 1186 }
1166 1187
1167 EffectiveConnectionType 1188 EffectiveConnectionType
1168 NetworkQualityEstimator::GetRecentEffectiveConnectionType( 1189 NetworkQualityEstimator::GetRecentEffectiveConnectionType(
1169 const base::TimeTicks& start_time) const { 1190 const base::TimeTicks& start_time) const {
1170 DCHECK(thread_checker_.CalledOnValidThread()); 1191 DCHECK(thread_checker_.CalledOnValidThread());
1171 1192
1172 if (effective_connection_type_algorithm_ == 1193 if (effective_connection_type_algorithm_ ==
1173 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) { 1194 EffectiveConnectionTypeAlgorithm::HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT) {
1174 return GetRecentEffectiveConnectionTypeUsingMetrics( 1195 return GetRecentEffectiveConnectionTypeUsingMetrics(
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 // computation. Strict inequalities are used to ensure that effective 1639 // computation. Strict inequalities are used to ensure that effective
1619 // connection type is recomputed on connection change events even if the clock 1640 // connection type is recomputed on connection change events even if the clock
1620 // has not updated. 1641 // has not updated.
1621 if (now - last_effective_connection_type_computation_ < 1642 if (now - last_effective_connection_type_computation_ <
1622 effective_connection_type_recomputation_interval_ && 1643 effective_connection_type_recomputation_interval_ &&
1623 last_connection_change_ < last_effective_connection_type_computation_ && 1644 last_connection_change_ < last_effective_connection_type_computation_ &&
1624 // Recompute the effective connection type if the previously computed 1645 // Recompute the effective connection type if the previously computed
1625 // effective connection type was unknown. 1646 // effective connection type was unknown.
1626 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN && 1647 effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN &&
1627 // Recompute the effective connection type if the number of samples 1648 // Recompute the effective connection type if the number of samples
1628 // available now are more than twice in count than the number of 1649 // available now are 50% more in count than the number of samples that
bengr 2016/08/25 22:51:24 remove "in count"
tbansal1 2016/09/07 18:33:26 Done.
1629 // samples that were available when the effective connection type was 1650 // were available when the effective connection type was last computed.
1630 // last computed. 1651 rtt_observations_size_at_last_ect_computation_ * 1.5 >=
bengr 2016/08/25 22:51:24 Does this mean that there's an exponential backoff
tbansal1 2016/09/07 18:33:26 There is exponential backoff. Additionally, ECT is
1631 rtt_observations_size_at_last_ect_computation_ * 2 >=
1632 rtt_observations_.Size() && 1652 rtt_observations_.Size() &&
1633 throughput_observations_size_at_last_ect_computation_ * 2 >= 1653 throughput_observations_size_at_last_ect_computation_ * 1.5 >=
1634 downstream_throughput_kbps_observations_.Size()) { 1654 downstream_throughput_kbps_observations_.Size()) {
1635 return; 1655 return;
1636 } 1656 }
1637 1657
1638 const EffectiveConnectionType past_type = effective_connection_type_; 1658 RecomputeEffectiveConnectionType();
bengr 2016/08/25 22:51:24 Can you just call this "ComputeEffectiveConnection
tbansal1 2016/09/07 18:33:26 Done.
1639 last_effective_connection_type_computation_ = now;
1640 effective_connection_type_ = GetEffectiveConnectionType();
1641
1642 if (past_type != effective_connection_type_)
1643 NotifyObserversOfEffectiveConnectionTypeChanged();
1644
1645 rtt_observations_size_at_last_ect_computation_ = rtt_observations_.Size();
1646 throughput_observations_size_at_last_ect_computation_ =
1647 downstream_throughput_kbps_observations_.Size();
1648 } 1659 }
1649 1660
1650 void NetworkQualityEstimator:: 1661 void NetworkQualityEstimator::
1651 NotifyObserversOfEffectiveConnectionTypeChanged() { 1662 NotifyObserversOfEffectiveConnectionTypeChanged() {
1652 DCHECK(thread_checker_.CalledOnValidThread()); 1663 DCHECK(thread_checker_.CalledOnValidThread());
1653 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_); 1664 DCHECK_NE(EFFECTIVE_CONNECTION_TYPE_LAST, effective_connection_type_);
1654 1665
1655 // TODO(tbansal): Add hysteresis in the notification. 1666 // TODO(tbansal): Add hysteresis in the notification.
1656 FOR_EACH_OBSERVER( 1667 FOR_EACH_OBSERVER(
1657 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_, 1668 EffectiveConnectionTypeObserver, effective_connection_type_observer_list_,
1658 OnEffectiveConnectionTypeChanged(effective_connection_type_)); 1669 OnEffectiveConnectionTypeChanged(effective_connection_type_));
1659 1670
1660 // Add the estimates of the current network to the cache store. 1671 // Add the estimates of the current network to the cache store.
1661 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) { 1672 if (effective_connection_type_ != EFFECTIVE_CONNECTION_TYPE_UNKNOWN) {
1662 network_quality_store_.Add( 1673 network_quality_store_.Add(
1663 current_network_id_, 1674 current_network_id_,
1664 nqe::internal::CachedNetworkQuality( 1675 nqe::internal::CachedNetworkQuality(
1665 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_, 1676 tick_clock_->NowTicks(), estimated_quality_at_last_main_frame_,
1666 effective_connection_type_)); 1677 effective_connection_type_));
1667 } 1678 }
1668 } 1679 }
1669 1680
1670 } // namespace net 1681 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698