Index: net/nqe/network_quality_estimator.cc |
diff --git a/net/nqe/network_quality_estimator.cc b/net/nqe/network_quality_estimator.cc |
index 3756629a07e8153c0eb388221e3749b4df35d72e..aa0eed3e0df71ae155a5a4bd2bf76baa7faf5e7a 100644 |
--- a/net/nqe/network_quality_estimator.cc |
+++ b/net/nqe/network_quality_estimator.cc |
@@ -93,6 +93,13 @@ const char kDefaultKbpsObservationSuffix[] = ".DefaultMedianKbps"; |
const char kThresholdURLRTTMsecSuffix[] = ".ThresholdMedianHttpRTTMsec"; |
// Suffix of the name of the variation parameter that contains the threshold |
+// transport RTTs (in milliseconds) for different effective connection types. |
+// Complete name of the variation parameter would be |
+// |EffectiveConnectionType|.|kThresholdTransportRTTMsecSuffix|. |
+const char kThresholdTransportRTTMsecSuffix[] = |
+ ".ThresholdMedianTransportRTTMsec"; |
+ |
+// Suffix of the name of the variation parameter that contains the threshold |
// downlink throughput (in kbps) for different effective connection types. |
// Complete name of the variation parameter would be |
// |EffectiveConnectionType|.|kThresholdKbpsSuffix|. |
@@ -227,7 +234,10 @@ NetworkQualityEstimator::NetworkQualityEstimator( |
bool use_smaller_responses_for_tests) |
: algorithm_name_to_enum_({{"HttpRTTAndDownstreamThroughput", |
EffectiveConnectionTypeAlgorithm:: |
- HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}}), |
+ HTTP_RTT_AND_DOWNSTREAM_THROUGHOUT}, |
+ {"TransportRTTOrDownstreamThroughput", |
Not at Google. Contact bengr
2016/07/06 19:04:07
This is brittle because it allows adding an entry
tbansal1
2016/07/06 23:17:32
That error would be caught by DCHECK below. See li
Not at Google. Contact bengr
2016/07/07 00:03:04
Macro does not have this issue. You will get a com
tbansal1
2016/07/07 16:47:32
Agreed. Right now this error is captured using NQE
Not at Google. Contact bengr
2016/07/07 17:19:17
It is easy to map strings to enums. You just use a
tbansal1
2016/07/07 18:01:32
"if" condtional does not catch duplicates in value
Not at Google. Contact bengr
2016/07/07 19:10:49
We don't rely on the switch to catch duplicates. T
tbansal1
2016/07/07 22:47:26
Added TODO. For now the duplicates are catched usi
|
+ EffectiveConnectionTypeAlgorithm:: |
+ TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT}}), |
use_localhost_requests_(use_local_host_requests_for_tests), |
use_small_responses_(use_smaller_responses_for_tests), |
weight_multiplier_per_second_( |
@@ -386,6 +396,26 @@ void NetworkQualityEstimator::ObtainEffectiveConnectionTypeModelParams( |
rtt <= connection_thresholds_[i - 1].http_rtt()); |
} |
+ variations_value = kMinimumRTTVariationParameterMsec - 1; |
Not at Google. Contact bengr
2016/07/07 00:03:04
This block is extremely similar to the block above
tbansal1
2016/07/07 16:47:32
I am not sure of a better way to combine them.
|
+ if (GetValueForVariationParam( |
+ variation_params, |
+ connection_type_name + kThresholdTransportRTTMsecSuffix, |
+ &variations_value) && |
+ variations_value >= kMinimumRTTVariationParameterMsec) { |
+ base::TimeDelta transport_rtt( |
+ base::TimeDelta::FromMilliseconds(variations_value)); |
+ connection_thresholds_[i] = nqe::internal::NetworkQuality( |
Not at Google. Contact bengr
2016/07/07 00:03:04
Any reason to create new instance of NetworkQualit
tbansal1
2016/07/07 16:47:32
Done.
|
+ connection_thresholds_[i].http_rtt(), transport_rtt, |
+ connection_thresholds_[i].downstream_throughput_kbps()); |
+ |
+ // Verify that the transport RTT values are in decreasing order as the |
+ // network quality improves. |
+ DCHECK(i == 0 || |
+ connection_thresholds_[i - 1].transport_rtt() == |
+ nqe::internal::InvalidRTT() || |
+ transport_rtt <= connection_thresholds_[i - 1].transport_rtt()); |
+ } |
+ |
variations_value = kMinimumThroughputVariationParameterKbps - 1; |
if (GetValueForVariationParam(variation_params, |
connection_type_name + kThresholdKbpsSuffix, |
@@ -892,6 +922,12 @@ NetworkQualityEstimator::GetRecentEffectiveConnectionType( |
return GetRecentEffectiveConnectionTypeHttpRTTAndDownstreamThroughput( |
start_time); |
} |
+ if (effective_connection_type_algorithm_ == |
+ EffectiveConnectionTypeAlgorithm:: |
+ TRANSPORT_RTT_OR_DOWNSTREAM_THROUGHOUT) { |
+ return GetRecentEffectiveConnectionTypeTransportRTTOrDownstreamThroughput( |
+ start_time); |
+ } |
// Add additional algorithms here. |
NOTREACHED(); |
return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
@@ -928,11 +964,11 @@ NetworkQualityEstimator::EffectiveConnectionType NetworkQualityEstimator:: |
EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); |
if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) |
continue; |
- bool estimated_http_rtt_is_higher_than_threshold = |
+ const bool estimated_http_rtt_is_higher_than_threshold = |
http_rtt != nqe::internal::InvalidRTT() && |
connection_thresholds_[i].http_rtt() != nqe::internal::InvalidRTT() && |
http_rtt >= connection_thresholds_[i].http_rtt(); |
- bool estimated_throughput_is_lower_than_threshold = |
+ const bool estimated_throughput_is_lower_than_threshold = |
kbps != nqe::internal::kInvalidThroughput && |
connection_thresholds_[i].downstream_throughput_kbps() != |
nqe::internal::kInvalidThroughput && |
@@ -951,6 +987,62 @@ NetworkQualityEstimator::EffectiveConnectionType NetworkQualityEstimator:: |
1); |
} |
+NetworkQualityEstimator::EffectiveConnectionType NetworkQualityEstimator:: |
+ GetRecentEffectiveConnectionTypeTransportRTTOrDownstreamThroughput( |
+ const base::TimeTicks& start_time) const { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
+ // If the device is currently offline, then return |
Not at Google. Contact bengr
2016/07/06 19:04:07
FWIW code is very readable, so this comment seems
tbansal1
2016/07/06 23:17:32
Done.
|
+ // EFFECTIVE_CONNECTION_TYPE_OFFLINE. |
+ if (GetCurrentNetworkID().type == NetworkChangeNotifier::CONNECTION_NONE) |
+ return EFFECTIVE_CONNECTION_TYPE_OFFLINE; |
+ |
+ base::TimeDelta transport_rtt = nqe::internal::InvalidRTT(); |
+ if (!GetRecentTransportRTTMedian(start_time, &transport_rtt)) |
+ transport_rtt = nqe::internal::InvalidRTT(); |
Not at Google. Contact bengr
2016/07/06 19:04:07
Can we have GetRecentTransportRTTMedian(..) set tr
tbansal1
2016/07/06 23:17:32
Yeah, I need to fix that. It is easier now since G
Not at Google. Contact bengr
2016/07/07 00:03:04
Add TODO?
tbansal1
2016/07/07 16:47:32
Done in .h file.
|
+ |
+ int32_t kbps = nqe::internal::kInvalidThroughput; |
+ if (!GetRecentMedianDownlinkThroughputKbps(start_time, &kbps)) |
+ kbps = nqe::internal::kInvalidThroughput; |
Not at Google. Contact bengr
2016/07/06 19:04:07
Similar to above comment: Can GetRecentMedianDownl
tbansal1
2016/07/06 23:17:32
same as above.
Not at Google. Contact bengr
2016/07/07 00:03:04
Acknowledged.
|
+ |
+ if (transport_rtt == nqe::internal::InvalidRTT() && |
+ kbps == nqe::internal::kInvalidThroughput) { |
+ // Quality of the current network is unknown. |
+ return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; |
+ } |
+ |
+ // Search from the slowest connection type to the fastest to find the |
+ // EffectiveConnectionType that best matches the current connection's |
+ // performance. The match is done by comparing RTT and throughput. |
+ for (size_t i = 0; i < EFFECTIVE_CONNECTION_TYPE_LAST; ++i) { |
+ EffectiveConnectionType type = static_cast<EffectiveConnectionType>(i); |
+ if (i == EFFECTIVE_CONNECTION_TYPE_UNKNOWN) |
+ continue; |
+ const bool estimated_transport_rtt_is_higher_than_threshold = |
+ transport_rtt != nqe::internal::InvalidRTT() && |
+ connection_thresholds_[i].transport_rtt() != |
+ nqe::internal::InvalidRTT() && |
+ transport_rtt >= connection_thresholds_[i].transport_rtt(); |
+ const bool estimated_throughput_is_lower_than_threshold = |
+ kbps != nqe::internal::kInvalidThroughput && |
+ connection_thresholds_[i].downstream_throughput_kbps() != |
+ nqe::internal::kInvalidThroughput && |
+ kbps <= connection_thresholds_[i].downstream_throughput_kbps(); |
+ |
+ // Return |type| as the effective connection type if the current network's |
+ // transport RTT is worse than the threshold RTT for |type|, or if the |
+ // current network's throughput is lower than the threshold throughput for |
+ // |type|. |
+ if (estimated_transport_rtt_is_higher_than_threshold || |
+ estimated_throughput_is_lower_than_threshold) { |
+ return type; |
+ } |
+ } |
+ // Return the fastest connection type. |
+ return static_cast<EffectiveConnectionType>(EFFECTIVE_CONNECTION_TYPE_LAST - |
+ 1); |
+} |
+ |
void NetworkQualityEstimator::AddEffectiveConnectionTypeObserver( |
EffectiveConnectionTypeObserver* observer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |