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

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

Issue 2710973003: Record RTT prediction accuracy when using average algorithms (Closed)
Patch Set: Add unweighted average Created 3 years, 10 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
« no previous file with comments | « no previous file | net/nqe/network_quality_estimator.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 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 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 5 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 13
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/observer_list.h" 19 #include "base/observer_list.h"
20 #include "base/optional.h"
20 #include "base/threading/thread_checker.h" 21 #include "base/threading/thread_checker.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "net/base/net_export.h" 23 #include "net/base/net_export.h"
23 #include "net/base/network_change_notifier.h" 24 #include "net/base/network_change_notifier.h"
24 #include "net/nqe/cached_network_quality.h" 25 #include "net/nqe/cached_network_quality.h"
25 #include "net/nqe/effective_connection_type.h" 26 #include "net/nqe/effective_connection_type.h"
26 #include "net/nqe/event_creator.h" 27 #include "net/nqe/event_creator.h"
27 #include "net/nqe/external_estimate_provider.h" 28 #include "net/nqe/external_estimate_provider.h"
28 #include "net/nqe/network_id.h" 29 #include "net/nqe/network_id.h"
29 #include "net/nqe/network_quality.h" 30 #include "net/nqe/network_quality.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // A protected constructor for testing that allows setting the value of 314 // A protected constructor for testing that allows setting the value of
314 // |add_default_platform_observations_|. 315 // |add_default_platform_observations_|.
315 NetworkQualityEstimator( 316 NetworkQualityEstimator(
316 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider, 317 std::unique_ptr<ExternalEstimateProvider> external_estimates_provider,
317 const std::map<std::string, std::string>& variation_params, 318 const std::map<std::string, std::string>& variation_params,
318 bool use_local_host_requests_for_tests, 319 bool use_local_host_requests_for_tests,
319 bool use_smaller_responses_for_tests, 320 bool use_smaller_responses_for_tests,
320 bool add_default_platform_observations, 321 bool add_default_platform_observations,
321 const NetLogWithSource& net_log); 322 const NetLogWithSource& net_log);
322 323
324 // Different experimental statistic algorithms that can be used for computing
325 // the predictions.
326 enum Statistic {
327 STATISTIC_WEIGHTED_AVERAGE = 0,
328 STATISTIC_UNWEIGHTED_AVERAGE = 1,
329 // Last statistic. Not to be used.
330 STATISTIC_LAST = 2
331 };
332
323 // NetworkChangeNotifier::ConnectionTypeObserver implementation: 333 // NetworkChangeNotifier::ConnectionTypeObserver implementation:
324 void OnConnectionTypeChanged( 334 void OnConnectionTypeChanged(
325 NetworkChangeNotifier::ConnectionType type) override; 335 NetworkChangeNotifier::ConnectionType type) override;
326 336
327 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. 337 // ExternalEstimateProvider::UpdatedEstimateObserver implementation.
328 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, 338 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt,
329 int32_t downstream_throughput_kbps, 339 int32_t downstream_throughput_kbps,
330 int32_t upstream_throughput_kbps) override; 340 int32_t upstream_throughput_kbps) override;
331 341
332 // Returns true if median RTT at the HTTP layer is available and sets |rtt| 342 // Returns true if median RTT at the HTTP layer is available and sets |rtt|
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 const base::TimeTicks& start_time, 388 const base::TimeTicks& start_time,
379 base::TimeDelta* http_rtt, 389 base::TimeDelta* http_rtt,
380 base::TimeDelta* transport_rtt, 390 base::TimeDelta* transport_rtt,
381 int32_t* downstream_throughput_kbps) const; 391 int32_t* downstream_throughput_kbps) const;
382 392
383 // Notifies |this| of a new transport layer RTT. Called by socket watchers. 393 // Notifies |this| of a new transport layer RTT. Called by socket watchers.
384 // Protected for testing. 394 // Protected for testing.
385 void OnUpdatedRTTAvailable(SocketPerformanceWatcherFactory::Protocol protocol, 395 void OnUpdatedRTTAvailable(SocketPerformanceWatcherFactory::Protocol protocol,
386 const base::TimeDelta& rtt); 396 const base::TimeDelta& rtt);
387 397
398 // Returns an estimate of network quality at the specified |percentile|.
399 // |disallowed_observation_sources| is the list of observation sources that
400 // should be excluded when computing the percentile.
401 // Only the observations later than |start_time| are taken into account.
402 // |percentile| must be between 0 and 100 (both inclusive) with higher
403 // percentiles indicating less performant networks. For example, if
404 // |percentile| is 90, then the network is expected to be faster than the
405 // returned estimate with 0.9 probability. Similarly, network is expected to
406 // be slower than the returned estimate with 0.1 probability. |statistic|
407 // is the statistic that should be used for computing the estimate. If unset,
408 // the default statistic is used. Virtualized for testing.
409 virtual base::TimeDelta GetRTTEstimateInternal(
410 const std::vector<NetworkQualityObservationSource>&
411 disallowed_observation_sources,
412 base::TimeTicks start_time,
413 const base::Optional<Statistic>& statistic,
414 int percentile) const;
415 int32_t GetDownlinkThroughputKbpsEstimateInternal(
416 const base::TimeTicks& start_time,
417 int percentile) const;
418
388 private: 419 private:
389 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 420 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
390 AdaptiveRecomputationEffectiveConnectionType); 421 AdaptiveRecomputationEffectiveConnectionType);
391 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); 422 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
392 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); 423 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
393 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 424 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
394 DefaultObservationsOverridden); 425 DefaultObservationsOverridden);
395 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 426 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
396 ObtainAlgorithmToUseFromParams); 427 ObtainAlgorithmToUseFromParams);
397 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); 428 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // the field trial parameters. For each effective connection type, a model 507 // the field trial parameters. For each effective connection type, a model
477 // (currently composed of a RTT threshold and a downlink throughput threshold) 508 // (currently composed of a RTT threshold and a downlink throughput threshold)
478 // is provided by the field trial. 509 // is provided by the field trial.
479 void ObtainOperatingParams( 510 void ObtainOperatingParams(
480 const std::map<std::string, std::string>& variation_params); 511 const std::map<std::string, std::string>& variation_params);
481 512
482 // Adds the default median RTT and downstream throughput estimate for the 513 // Adds the default median RTT and downstream throughput estimate for the
483 // current connection type to the observation buffer. 514 // current connection type to the observation buffer.
484 void AddDefaultEstimates(); 515 void AddDefaultEstimates();
485 516
486 // Returns an estimate of network quality at the specified |percentile|.
487 // |disallowed_observation_sources| is the list of observation sources that
488 // should be excluded when computing the percentile.
489 // Only the observations later than |start_time| are taken into account.
490 // |percentile| must be between 0 and 100 (both inclusive) with higher
491 // percentiles indicating less performant networks. For example, if
492 // |percentile| is 90, then the network is expected to be faster than the
493 // returned estimate with 0.9 probability. Similarly, network is expected to
494 // be slower than the returned estimate with 0.1 probability.
495 base::TimeDelta GetRTTEstimateInternal(
496 const std::vector<NetworkQualityObservationSource>&
497 disallowed_observation_sources,
498 const base::TimeTicks& start_time,
499 int percentile) const;
500 int32_t GetDownlinkThroughputKbpsEstimateInternal(
501 const base::TimeTicks& start_time,
502 int percentile) const;
503
504 // Returns the current network ID checking by calling the platform APIs. 517 // Returns the current network ID checking by calling the platform APIs.
505 // Virtualized for testing. 518 // Virtualized for testing.
506 virtual nqe::internal::NetworkID GetCurrentNetworkID() const; 519 virtual nqe::internal::NetworkID GetCurrentNetworkID() const;
507 520
508 // Notifies RTT observers of |observation|. May also trigger recomputation 521 // Notifies RTT observers of |observation|. May also trigger recomputation
509 // of effective connection type. 522 // of effective connection type.
510 void NotifyObserversOfRTT(const RttObservation& observation); 523 void NotifyObserversOfRTT(const RttObservation& observation);
511 524
512 // Notifies throughput observers of |observation|. May also trigger 525 // Notifies throughput observers of |observation|. May also trigger
513 // recomputation of effective connection type. 526 // recomputation of effective connection type.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // if there is a change in its value. 612 // if there is a change in its value.
600 void ComputeEffectiveConnectionType(); 613 void ComputeEffectiveConnectionType();
601 614
602 // May update the network quality of the current network if |network_id| 615 // May update the network quality of the current network if |network_id|
603 // matches the ID of the current network. |cached_network_quality| is the 616 // matches the ID of the current network. |cached_network_quality| is the
604 // cached network quality of the network with id |network_id|. 617 // cached network quality of the network with id |network_id|.
605 void MaybeUpdateNetworkQualityFromCache( 618 void MaybeUpdateNetworkQualityFromCache(
606 const nqe::internal::NetworkID& network_id, 619 const nqe::internal::NetworkID& network_id,
607 const nqe::internal::CachedNetworkQuality& cached_network_quality); 620 const nqe::internal::CachedNetworkQuality& cached_network_quality);
608 621
622 const char* GetNameForStatistic(int i) const;
623
609 // Determines if the requests to local host can be used in estimating the 624 // Determines if the requests to local host can be used in estimating the
610 // network quality. Set to true only for tests. 625 // network quality. Set to true only for tests.
611 bool use_localhost_requests_; 626 bool use_localhost_requests_;
612 627
613 // Determines if the responses smaller than |kMinTransferSizeInBytes| 628 // Determines if the responses smaller than |kMinTransferSizeInBytes|
614 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the 629 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the
615 // network quality. Set to true only for tests. 630 // network quality. Set to true only for tests.
616 bool use_small_responses_; 631 bool use_small_responses_;
617 632
618 // When set to true, the device offline check is disabled when computing the 633 // When set to true, the device offline check is disabled when computing the
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 [EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_LAST]; 697 [EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_LAST];
683 698
684 // Time when the transaction for the last main frame request was started. 699 // Time when the transaction for the last main frame request was started.
685 base::TimeTicks last_main_frame_request_; 700 base::TimeTicks last_main_frame_request_;
686 701
687 // Estimated network quality when the transaction for the last main frame 702 // Estimated network quality when the transaction for the last main frame
688 // request was started. 703 // request was started.
689 nqe::internal::NetworkQuality estimated_quality_at_last_main_frame_; 704 nqe::internal::NetworkQuality estimated_quality_at_last_main_frame_;
690 EffectiveConnectionType effective_connection_type_at_last_main_frame_; 705 EffectiveConnectionType effective_connection_type_at_last_main_frame_;
691 706
707 // Estimated RTT at HTTP layer when the last main frame transaction was
708 // started. Computed using different statistics.
709 base::TimeDelta http_rtt_at_last_main_frame_[STATISTIC_LAST];
710
692 // Estimated network quality obtained from external estimate provider when the 711 // Estimated network quality obtained from external estimate provider when the
693 // external estimate provider was last queried. 712 // external estimate provider was last queried.
694 nqe::internal::NetworkQuality external_estimate_provider_quality_; 713 nqe::internal::NetworkQuality external_estimate_provider_quality_;
695 714
696 // ExternalEstimateProvider that provides network quality using operating 715 // ExternalEstimateProvider that provides network quality using operating
697 // system APIs. May be NULL. 716 // system APIs. May be NULL.
698 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; 717 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_;
699 718
700 // Observer list for changes in effective connection type. 719 // Observer list for changes in effective connection type.
701 base::ObserverList<EffectiveConnectionTypeObserver> 720 base::ObserverList<EffectiveConnectionTypeObserver>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 disallowed_observation_sources_for_transport_; 802 disallowed_observation_sources_for_transport_;
784 803
785 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; 804 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_;
786 805
787 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 806 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
788 }; 807 };
789 808
790 } // namespace net 809 } // namespace net
791 810
792 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 811 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « no previous file | net/nqe/network_quality_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698