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

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

Issue 2710973003: Record RTT prediction accuracy when using average algorithms (Closed)
Patch Set: 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/metrics/histogram_samples.h" 20 #include "base/metrics/histogram_samples.h"
21 #include "base/optional.h"
21 #include "base/run_loop.h" 22 #include "base/run_loop.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/test/histogram_tester.h" 24 #include "base/test/histogram_tester.h"
24 #include "base/test/simple_test_tick_clock.h" 25 #include "base/test/simple_test_tick_clock.h"
25 #include "base/threading/platform_thread.h" 26 #include "base/threading/platform_thread.h"
26 #include "base/time/time.h" 27 #include "base/time/time.h"
27 #include "build/build_config.h" 28 #include "build/build_config.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/base/network_change_notifier.h" 30 #include "net/base/network_change_notifier.h"
30 #include "net/http/http_response_headers.h" 31 #include "net/http/http_response_headers.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1); 294 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1);
294 295
295 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0); 296 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0);
296 297
297 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 298 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
298 EXPECT_FALSE( 299 EXPECT_FALSE(
299 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 300 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
300 301
301 // Verify that metrics are logged correctly on main-frame requests. 302 // Verify that metrics are logged correctly on main-frame requests.
302 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50", 1); 303 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50", 1);
304 histogram_tester.ExpectTotalCount("NQE.WeightedAverage.MainFrame.RTT", 1);
303 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown", 305 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown",
304 1); 306 1);
305 histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50", 307 histogram_tester.ExpectTotalCount("NQE.MainFrame.TransportRTT.Percentile50",
306 0); 308 0);
307 histogram_tester.ExpectTotalCount( 309 histogram_tester.ExpectTotalCount(
308 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0); 310 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0);
309 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50", 1); 311 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50", 1);
310 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown", 312 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown",
311 1); 313 1);
312 314
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 int32_t kbps; 541 int32_t kbps;
540 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 542 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
541 EXPECT_FALSE( 543 EXPECT_FALSE(
542 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 544 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
543 545
544 TestDelegate test_delegate; 546 TestDelegate test_delegate;
545 TestURLRequestContext context(true); 547 TestURLRequestContext context(true);
546 context.set_network_quality_estimator(&estimator); 548 context.set_network_quality_estimator(&estimator);
547 context.Init(); 549 context.Init();
548 550
549 // Push more observations than the maximum buffer size. 551 const size_t kMaxObservations = 10;
550 const size_t kMaxObservations = 1000;
551 for (size_t i = 0; i < kMaxObservations; ++i) { 552 for (size_t i = 0; i < kMaxObservations; ++i) {
552 std::unique_ptr<URLRequest> request(context.CreateRequest( 553 std::unique_ptr<URLRequest> request(context.CreateRequest(
553 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 554 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
554 request->Start(); 555 request->Start();
555 base::RunLoop().Run(); 556 base::RunLoop().Run();
556 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 557 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
557 EXPECT_TRUE( 558 EXPECT_TRUE(
558 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 559 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
559 } 560 }
560 561
(...skipping 11 matching lines...) Expand all
572 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) { 573 TEST(NetworkQualityEstimatorTest, ComputedPercentiles) {
573 TestNetworkQualityEstimator estimator; 574 TestNetworkQualityEstimator estimator;
574 575
575 std::vector<NetworkQualityObservationSource> disallowed_observation_sources; 576 std::vector<NetworkQualityObservationSource> disallowed_observation_sources;
576 disallowed_observation_sources.push_back( 577 disallowed_observation_sources.push_back(
577 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP); 578 NETWORK_QUALITY_OBSERVATION_SOURCE_TCP);
578 disallowed_observation_sources.push_back( 579 disallowed_observation_sources.push_back(
579 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); 580 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC);
580 581
581 EXPECT_EQ(nqe::internal::InvalidRTT(), 582 EXPECT_EQ(nqe::internal::InvalidRTT(),
582 estimator.GetRTTEstimateInternal(disallowed_observation_sources, 583 estimator.GetRTTEstimateInternal(
583 base::TimeTicks(), 100)); 584 disallowed_observation_sources, base::TimeTicks(),
585 base::Optional<NetworkQualityEstimator::Statistic>(), 100));
584 EXPECT_EQ(nqe::internal::kInvalidThroughput, 586 EXPECT_EQ(nqe::internal::kInvalidThroughput,
585 estimator.GetDownlinkThroughputKbpsEstimateInternal( 587 estimator.GetDownlinkThroughputKbpsEstimateInternal(
586 base::TimeTicks(), 100)); 588 base::TimeTicks(), 100));
587 589
588 TestDelegate test_delegate; 590 TestDelegate test_delegate;
589 TestURLRequestContext context(true); 591 TestURLRequestContext context(true);
590 context.set_network_quality_estimator(&estimator); 592 context.set_network_quality_estimator(&estimator);
591 context.Init(); 593 context.Init();
592 594
593 // Number of observations are more than the maximum buffer size. 595 for (size_t i = 0; i < 10U; ++i) {
594 for (size_t i = 0; i < 1000U; ++i) {
595 std::unique_ptr<URLRequest> request(context.CreateRequest( 596 std::unique_ptr<URLRequest> request(context.CreateRequest(
596 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 597 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
597 request->Start(); 598 request->Start();
598 base::RunLoop().Run(); 599 base::RunLoop().Run();
599 } 600 }
600 601
601 // Verify the percentiles through simple tests. 602 // Verify the percentiles through simple tests.
602 for (int i = 0; i <= 100; ++i) { 603 for (int i = 0; i <= 100; ++i) {
603 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal( 604 EXPECT_GT(estimator.GetDownlinkThroughputKbpsEstimateInternal(
604 base::TimeTicks(), i), 605 base::TimeTicks(), i),
605 0); 606 0);
606 EXPECT_LT(estimator.GetRTTEstimateInternal(disallowed_observation_sources, 607 EXPECT_LT(estimator.GetRTTEstimateInternal(
607 base::TimeTicks(), i), 608 disallowed_observation_sources, base::TimeTicks(),
609 base::Optional<NetworkQualityEstimator::Statistic>(), i),
608 base::TimeDelta::Max()); 610 base::TimeDelta::Max());
609 611
610 if (i != 0) { 612 if (i != 0) {
611 // Throughput percentiles are in decreasing order. 613 // Throughput percentiles are in decreasing order.
612 EXPECT_LE(estimator.GetDownlinkThroughputKbpsEstimateInternal( 614 EXPECT_LE(estimator.GetDownlinkThroughputKbpsEstimateInternal(
613 base::TimeTicks(), i), 615 base::TimeTicks(), i),
614 estimator.GetDownlinkThroughputKbpsEstimateInternal( 616 estimator.GetDownlinkThroughputKbpsEstimateInternal(
615 base::TimeTicks(), i - 1)); 617 base::TimeTicks(), i - 1));
616 618
619 // Weighted average statistic should be computed correctly.
620 EXPECT_NE(nqe::internal::InvalidRTT(),
621 estimator.GetRTTEstimateInternal(
622 disallowed_observation_sources, base::TimeTicks(),
623 NetworkQualityEstimator::STATISTIC_WEIGHTED_AVERAGE, i));
624
625 // Weighted average statistic should disregard the value of the percentile
626 // argument.
627 EXPECT_EQ(
628 estimator.GetRTTEstimateInternal(
629 disallowed_observation_sources, base::TimeTicks(),
630 NetworkQualityEstimator::STATISTIC_WEIGHTED_AVERAGE, i),
631 estimator.GetRTTEstimateInternal(
632 disallowed_observation_sources, base::TimeTicks(),
633 NetworkQualityEstimator::STATISTIC_WEIGHTED_AVERAGE, i - 1));
634
617 // RTT percentiles are in increasing order. 635 // RTT percentiles are in increasing order.
618 EXPECT_GE(estimator.GetRTTEstimateInternal(disallowed_observation_sources, 636 EXPECT_GE(
619 base::TimeTicks(), i), 637 estimator.GetRTTEstimateInternal(
620 estimator.GetRTTEstimateInternal(disallowed_observation_sources, 638 disallowed_observation_sources, base::TimeTicks(),
621 base::TimeTicks(), i - 1)); 639 base::Optional<NetworkQualityEstimator::Statistic>(), i),
640 estimator.GetRTTEstimateInternal(
641 disallowed_observation_sources, base::TimeTicks(),
642 base::Optional<NetworkQualityEstimator::Statistic>(), i - 1));
622 } 643 }
623 } 644 }
624 } 645 }
625 646
626 // Verifies that the observers receive the notifications when default estimates 647 // Verifies that the observers receive the notifications when default estimates
627 // are added to the observations. 648 // are added to the observations.
628 TEST(NetworkQualityEstimatorTest, DefaultObservations) { 649 TEST(NetworkQualityEstimatorTest, DefaultObservations) {
629 base::HistogramTester histogram_tester; 650 base::HistogramTester histogram_tester;
630 651
631 TestEffectiveConnectionTypeObserver effective_connection_type_observer; 652 TestEffectiveConnectionTypeObserver effective_connection_type_observer;
(...skipping 1660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1)); 2313 tick_clock_ptr->Advance(base::TimeDelta::FromSeconds(1));
2293 2314
2294 std::vector<base::TimeDelta> accuracy_recording_intervals; 2315 std::vector<base::TimeDelta> accuracy_recording_intervals;
2295 accuracy_recording_intervals.push_back(accuracy_recording_delay); 2316 accuracy_recording_intervals.push_back(accuracy_recording_delay);
2296 estimator.SetAccuracyRecordingIntervals(accuracy_recording_intervals); 2317 estimator.SetAccuracyRecordingIntervals(accuracy_recording_intervals);
2297 2318
2298 // RTT is higher than threshold. Network is slow. 2319 // RTT is higher than threshold. Network is slow.
2299 // Network was predicted to be slow and actually was slow. 2320 // Network was predicted to be slow and actually was slow.
2300 estimator.set_start_time_null_http_rtt(test.rtt); 2321 estimator.set_start_time_null_http_rtt(test.rtt);
2301 estimator.set_recent_http_rtt(test.recent_rtt); 2322 estimator.set_recent_http_rtt(test.recent_rtt);
2323 estimator.set_rtt_estimate_internal(test.recent_rtt);
2302 estimator.set_start_time_null_transport_rtt(test.rtt); 2324 estimator.set_start_time_null_transport_rtt(test.rtt);
2303 estimator.set_recent_transport_rtt(test.recent_rtt); 2325 estimator.set_recent_transport_rtt(test.recent_rtt);
2304 estimator.set_start_time_null_downlink_throughput_kbps( 2326 estimator.set_start_time_null_downlink_throughput_kbps(
2305 test.downstream_throughput_kbps); 2327 test.downstream_throughput_kbps);
2306 estimator.set_recent_downlink_throughput_kbps( 2328 estimator.set_recent_downlink_throughput_kbps(
2307 test.recent_downstream_throughput_kbps); 2329 test.recent_downstream_throughput_kbps);
2308 2330
2309 base::HistogramTester histogram_tester; 2331 base::HistogramTester histogram_tester;
2310 2332
2311 TestDelegate test_delegate; 2333 TestDelegate test_delegate;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 histogram_tester.ExpectUniqueSample( 2409 histogram_tester.ExpectUniqueSample(
2388 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + 2410 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." +
2389 rtt_sign_suffix_with_one_sample + "." + interval_value + 2411 rtt_sign_suffix_with_one_sample + "." + interval_value +
2390 ".300_620", 2412 ".300_620",
2391 rtt_diff, 1); 2413 rtt_diff, 1);
2392 histogram_tester.ExpectTotalCount( 2414 histogram_tester.ExpectTotalCount(
2393 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." + 2415 "NQE.Accuracy.HttpRTT.EstimatedObservedDiff." +
2394 rtt_sign_suffix_with_zero_samples + "." + interval_value + 2416 rtt_sign_suffix_with_zero_samples + "." + interval_value +
2395 ".300_620", 2417 ".300_620",
2396 0); 2418 0);
2419
2420 // All samples are recorded in bucket 0 because recent HTTP RTT and
2421 // HTTP RTT are equal when weighted average algorithm is used.
2422 histogram_tester.ExpectUniqueSample(
2423 "NQE.WeightedAverage.Accuracy.HttpRTT.EstimatedObservedDiff."
2424 "Positive." +
2425 interval_value + ".300_620",
2426 0, 1);
2427
2397 histogram_tester.ExpectUniqueSample( 2428 histogram_tester.ExpectUniqueSample(
2398 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + 2429 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." +
2399 rtt_sign_suffix_with_one_sample + "." + interval_value + 2430 rtt_sign_suffix_with_one_sample + "." + interval_value +
2400 ".300_620", 2431 ".300_620",
2401 rtt_diff, 1); 2432 rtt_diff, 1);
2402 histogram_tester.ExpectTotalCount( 2433 histogram_tester.ExpectTotalCount(
2403 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." + 2434 "NQE.Accuracy.TransportRTT.EstimatedObservedDiff." +
2404 rtt_sign_suffix_with_zero_samples + "." + interval_value + 2435 rtt_sign_suffix_with_zero_samples + "." + interval_value +
2405 ".300_620", 2436 ".300_620",
2406 0); 2437 0);
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 3107
3077 // Cleanup. 3108 // Cleanup.
3078 estimator.RemoveRTTObserver(&rtt_observer); 3109 estimator.RemoveRTTObserver(&rtt_observer);
3079 estimator.RemoveThroughputObserver(&throughput_observer); 3110 estimator.RemoveThroughputObserver(&throughput_observer);
3080 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); 3111 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
3081 estimator.RemoveEffectiveConnectionTypeObserver( 3112 estimator.RemoveEffectiveConnectionTypeObserver(
3082 &effective_connection_type_observer); 3113 &effective_connection_type_observer);
3083 } 3114 }
3084 3115
3085 } // namespace net 3116 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698