network_quality_estimator_params.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_PARAMS_H_
  5. #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_PARAMS_H_
  6. #include <map>
  7. #include <string>
  8. #include "base/sequence_checker.h"
  9. #include "base/time/time.h"
  10. #include "net/base/net_export.h"
  11. #include "net/base/network_change_notifier.h"
  12. #include "net/nqe/effective_connection_type.h"
  13. #include "net/nqe/network_quality.h"
  14. #include "third_party/abseil-cpp/absl/types/optional.h"
  15. namespace net {
  16. // Forces NQE to return a specific effective connection type. Set using the
  17. // |params| provided to the NetworkQualityEstimatorParams constructor.
  18. NET_EXPORT extern const char kForceEffectiveConnectionType[];
  19. NET_EXPORT extern const char kEffectiveConnectionTypeSlow2GOnCellular[];
  20. // HTTP RTT thresholds for different effective connection types.
  21. NET_EXPORT extern const base::TimeDelta
  22. kHttpRttEffectiveConnectionTypeThresholds[EFFECTIVE_CONNECTION_TYPE_LAST];
  23. // NetworkQualityEstimatorParams computes the configuration parameters for
  24. // the network quality estimator.
  25. class NET_EXPORT NetworkQualityEstimatorParams {
  26. public:
  27. // |params| is the map containing all field trial parameters related to
  28. // NetworkQualityEstimator field trial.
  29. explicit NetworkQualityEstimatorParams(
  30. const std::map<std::string, std::string>& params);
  31. NetworkQualityEstimatorParams(const NetworkQualityEstimatorParams&) = delete;
  32. NetworkQualityEstimatorParams& operator=(
  33. const NetworkQualityEstimatorParams&) = delete;
  34. ~NetworkQualityEstimatorParams();
  35. // Returns the default observation for connection |type|. The default
  36. // observations are different for different connection types (e.g., 2G, 3G,
  37. // 4G, WiFi). The default observations may be used to determine the network
  38. // quality in absence of any other information.
  39. const nqe::internal::NetworkQuality& DefaultObservation(
  40. NetworkChangeNotifier::ConnectionType type) const;
  41. // Returns the typical network quality for connection |type|.
  42. const nqe::internal::NetworkQuality& TypicalNetworkQuality(
  43. EffectiveConnectionType type) const;
  44. // Returns the threshold for effective connection type |type|.
  45. const nqe::internal::NetworkQuality& ConnectionThreshold(
  46. EffectiveConnectionType type) const;
  47. // Returns the minimum number of requests in-flight to consider the network
  48. // fully utilized. A throughput observation is taken only when the network is
  49. // considered as fully utilized.
  50. size_t throughput_min_requests_in_flight() const;
  51. // Tiny transfer sizes may give inaccurate throughput results.
  52. // Minimum size of the transfer over which the throughput is computed.
  53. int64_t GetThroughputMinTransferSizeBits() const;
  54. // Returns the weight multiplier per second, which represents the factor by
  55. // which the weight of an observation reduces every second.
  56. double weight_multiplier_per_second() const {
  57. return weight_multiplier_per_second_;
  58. }
  59. // Returns an unset value if the effective connection type has not been forced
  60. // via the |params| provided to this class. Otherwise, returns a value set to
  61. // the effective connection type that has been forced. Forced ECT can be
  62. // forced based on |connection_type| (e.g. Slow-2G on cellular, and default on
  63. // other connection type).
  64. absl::optional<EffectiveConnectionType> GetForcedEffectiveConnectionType(
  65. NetworkChangeNotifier::ConnectionType connection_type);
  66. void SetForcedEffectiveConnectionType(
  67. EffectiveConnectionType forced_effective_connection_type) {
  68. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  69. forced_effective_connection_type_ = forced_effective_connection_type;
  70. }
  71. // Returns true if reading from the persistent cache is enabled.
  72. bool persistent_cache_reading_enabled() const {
  73. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  74. return persistent_cache_reading_enabled_;
  75. }
  76. void set_persistent_cache_reading_enabled(
  77. bool persistent_cache_reading_enabled) {
  78. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  79. persistent_cache_reading_enabled_ = persistent_cache_reading_enabled;
  80. }
  81. // Returns the the minimum interval betweeen consecutive notifications to a
  82. // single socket watcher.
  83. base::TimeDelta min_socket_watcher_notification_interval() const {
  84. return min_socket_watcher_notification_interval_;
  85. }
  86. // Number of bytes received during a throughput observation window of duration
  87. // 1 HTTP RTT should be at least the value returned by this method times
  88. // the typical size of a congestion window. If not, the throughput observation
  89. // window is heuristically determined as hanging.
  90. double throughput_hanging_requests_cwnd_size_multiplier() const {
  91. return throughput_hanging_requests_cwnd_size_multiplier_;
  92. }
  93. // Returns the multiplier by which the transport RTT should be multipled when
  94. // computing the HTTP RTT. The multiplied value of the transport RTT serves
  95. // as a lower bound to the HTTP RTT estimate. e.g., if the multiplied
  96. // transport RTT is 100 msec., then HTTP RTT estimate can't be lower than
  97. // 100 msec. Returns a negative value if the param is not set.
  98. double lower_bound_http_rtt_transport_rtt_multiplier() const {
  99. return lower_bound_http_rtt_transport_rtt_multiplier_;
  100. }
  101. // Returns the multiplier by which the end to end RTT estimate should be
  102. // multiplied when computing the HTTP RTT. The multiplied value of the
  103. // end to end RTT serves as an upper bound to the HTTP RTT estimate. e.g., if
  104. // the multiplied end to end RTT is 100 msec., then HTTP RTT estimate can't be
  105. // more than |upper_bound_http_rtt_endtoend_rtt_multiplier| times 100 msec.
  106. // Returns a negative value if the param is not set.
  107. double upper_bound_http_rtt_endtoend_rtt_multiplier() const {
  108. return upper_bound_http_rtt_endtoend_rtt_multiplier_;
  109. }
  110. // For the purpose of estimating the HTTP RTT, a request is marked as hanging
  111. // only if its RTT is at least this times the transport RTT estimate.
  112. int hanging_request_http_rtt_upper_bound_transport_rtt_multiplier() const {
  113. return hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_;
  114. }
  115. // For the purpose of estimating the HTTP RTT, a request is marked as hanging
  116. // only if its RTT is at least this times the HTTP RTT estimate.
  117. int hanging_request_http_rtt_upper_bound_http_rtt_multiplier() const {
  118. return hanging_request_http_rtt_upper_bound_http_rtt_multiplier_;
  119. }
  120. // For the purpose of estimating the HTTP RTT, a request is marked as hanging
  121. // only if its RTT is at least as much the value returned by this method.
  122. base::TimeDelta hanging_request_upper_bound_min_http_rtt() const {
  123. return hanging_request_upper_bound_min_http_rtt_;
  124. }
  125. // Returns the number of transport RTT observations that should be available
  126. // before the transport RTT estimate can be used to clamp the HTTP RTT
  127. // estimate. Set to 5 by default which ensures that when the transport RTT
  128. // is available only from the connection type, it is not used for computing
  129. // the HTTP RTT estimate.
  130. size_t http_rtt_transport_rtt_min_count() const {
  131. return http_rtt_transport_rtt_min_count_;
  132. }
  133. // Returns the minimum interval between successive computations of the
  134. // increase in transport RTT.
  135. base::TimeDelta increase_in_transport_rtt_logging_interval() const {
  136. return increase_in_transport_rtt_logging_interval_;
  137. }
  138. // The maximum age of RTT observations for them to be considered recent for
  139. // the computation of the increase in RTT.
  140. base::TimeDelta recent_time_threshold() const {
  141. return recent_time_threshold_;
  142. }
  143. // The maximum age of observations for them to be considered useful for
  144. // calculating the minimum transport RTT from the historical data.
  145. base::TimeDelta historical_time_threshold() const {
  146. return historical_time_threshold_;
  147. }
  148. // Determines if the responses smaller than |kMinTransferSizeInBytes|
  149. // or shorter than |kMinTransferSizeInBytes| can be used in estimating the
  150. // network quality. Set to true only for tests.
  151. bool use_small_responses() const;
  152. // Returns the typical HTTP RTT that maps to the given
  153. // |effective_connection_type|. May return invalid value if
  154. // |effective_connection_type| is less than Slow2G or faster than 4G,
  155. static base::TimeDelta GetDefaultTypicalHttpRtt(
  156. EffectiveConnectionType effective_connection_type);
  157. // Returns the typical downslink throughput (in kbps) that maps to the given
  158. // |effective_connection_type|. May return invalid value if
  159. // |effective_connection_type| is less than Slow2G or faster than 4G,
  160. static int32_t GetDefaultTypicalDownlinkKbps(
  161. EffectiveConnectionType effective_connection_type);
  162. // |use_small_responses| should only be true when testing.
  163. // Allows the responses smaller than |kMinTransferSizeInBits| to be used for
  164. // network quality estimation.
  165. void SetUseSmallResponsesForTesting(bool use_small_responses);
  166. // If an in-flight request does not receive any data for a duration longer
  167. // than the value of this multiplier times the current HTTP RTT estimate, then
  168. // the request should be considered as hanging. If this multiplier has a
  169. // negative or a zero value, then none of the request should be considered as
  170. // hanging.
  171. int hanging_request_duration_http_rtt_multiplier() const {
  172. return hanging_request_duration_http_rtt_multiplier_;
  173. }
  174. // An in-flight request may be marked as hanging only if it does not receive
  175. // any data for at least this duration.
  176. base::TimeDelta hanging_request_min_duration() const {
  177. return hanging_request_min_duration_;
  178. }
  179. // Returns true if default values provided by the platform should be used for
  180. // estimation. Set to false only for testing.
  181. bool add_default_platform_observations() const {
  182. return add_default_platform_observations_;
  183. }
  184. // Number of observations received after which the effective connection type
  185. // should be recomputed.
  186. size_t count_new_observations_received_compute_ect() const { return 50; }
  187. // Maximum number of observations that can be held in a single
  188. // ObservationBuffer.
  189. size_t observation_buffer_size() const { return 300; }
  190. // Minimun interval between consecutive notifications from socket
  191. // watchers who live on the same thread as the network quality estimator.
  192. base::TimeDelta socket_watchers_min_notification_interval() const {
  193. return socket_watchers_min_notification_interval_;
  194. }
  195. // Returns true if end-to-end RTT estimates can be used for computing network
  196. // quality estimate.
  197. bool use_end_to_end_rtt() const { return use_end_to_end_rtt_; }
  198. // Returns a multiplier which is used to clamp Kbps on slow connections. For
  199. // a given ECT, the upper bound on Kbps is computed based on this returned
  200. // multiplier and the typical Kbps for the given ECT. If
  201. // upper_bound_typical_kbps_multiplier() is -1, then clamping should be
  202. // disabled.
  203. double upper_bound_typical_kbps_multiplier() const {
  204. return upper_bound_typical_kbps_multiplier_;
  205. }
  206. // Returns true if RTTs should be adjusted based on RTT counts.
  207. // If there are not enough transport RTT samples, end-to-end RTT samples and
  208. // the cached estimates are unavailble/too stale, then the computed value of
  209. // HTTP RTT can't be trusted due to hanging GETs. In that case, NQE returns
  210. // the typical HTTP RTT for a fast connection if
  211. // adjust_rtt_based_on_rtt_counts() returns true.
  212. bool adjust_rtt_based_on_rtt_counts() const {
  213. return adjust_rtt_based_on_rtt_counts_;
  214. }
  215. // Sets the forced effective connection type as |type|.
  216. void SetForcedEffectiveConnectionTypeForTesting(EffectiveConnectionType type);
  217. private:
  218. // Map containing all field trial parameters related to
  219. // NetworkQualityEstimator field trial.
  220. const std::map<std::string, std::string> params_;
  221. const size_t throughput_min_requests_in_flight_;
  222. const int throughput_min_transfer_size_kilobytes_;
  223. const double throughput_hanging_requests_cwnd_size_multiplier_;
  224. const double weight_multiplier_per_second_;
  225. absl::optional<EffectiveConnectionType> forced_effective_connection_type_;
  226. const bool forced_effective_connection_type_on_cellular_only_;
  227. bool persistent_cache_reading_enabled_;
  228. const base::TimeDelta min_socket_watcher_notification_interval_;
  229. const double lower_bound_http_rtt_transport_rtt_multiplier_ = 1.0;
  230. const double upper_bound_http_rtt_endtoend_rtt_multiplier_;
  231. const int hanging_request_http_rtt_upper_bound_transport_rtt_multiplier_;
  232. const int hanging_request_http_rtt_upper_bound_http_rtt_multiplier_;
  233. const base::TimeDelta hanging_request_upper_bound_min_http_rtt_ =
  234. base::Milliseconds(500);
  235. const size_t http_rtt_transport_rtt_min_count_;
  236. const base::TimeDelta increase_in_transport_rtt_logging_interval_;
  237. const base::TimeDelta recent_time_threshold_;
  238. const base::TimeDelta historical_time_threshold_;
  239. const int hanging_request_duration_http_rtt_multiplier_;
  240. const base::TimeDelta hanging_request_min_duration_ =
  241. base::Milliseconds(3000);
  242. const bool add_default_platform_observations_;
  243. const base::TimeDelta socket_watchers_min_notification_interval_;
  244. const bool use_end_to_end_rtt_ = true;
  245. const double upper_bound_typical_kbps_multiplier_;
  246. const bool adjust_rtt_based_on_rtt_counts_;
  247. bool use_small_responses_ = false;
  248. // Default network quality observations obtained from |params_|.
  249. nqe::internal::NetworkQuality
  250. default_observations_[NetworkChangeNotifier::CONNECTION_LAST + 1];
  251. // Typical network quality for different effective connection types obtained
  252. // from |params_|.
  253. nqe::internal::NetworkQuality typical_network_quality_
  254. [EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_LAST];
  255. // Thresholds for different effective connection types obtained from
  256. // |params_|. These thresholds encode how different connection types behave
  257. // in general.
  258. nqe::internal::NetworkQuality connection_thresholds_
  259. [EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_LAST];
  260. SEQUENCE_CHECKER(sequence_checker_);
  261. };
  262. } // namespace net
  263. #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_PARAMS_H_