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

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

Issue 1164713004: Store network quality samples so we can compute percentiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added RingBuffer class Created 5 years, 6 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 #ifndef NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 5 #ifndef NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
6 #define NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 6 #define NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque>
11
10 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "net/base/network_change_notifier.h" 16 #include "net/base/network_change_notifier.h"
15 17
16 namespace net { 18 namespace net {
17 19
18 struct NetworkQuality; 20 struct NetworkQuality;
19 21
20 // NetworkQualityEstimator provides network quality estimates (quality of the 22 // NetworkQualityEstimator provides network quality estimates (quality of the
21 // full paths to all origins that have been connected to). 23 // full paths to all origins that have been connected to).
22 // The estimates are based on the observed organic traffic. 24 // The estimates are based on the observed organic traffic.
23 // A NetworkQualityEstimator instance is attached to URLRequestContexts and 25 // A NetworkQualityEstimator instance is attached to URLRequestContexts and
24 // observes the traffic of URLRequests spawned from the URLRequestContexts. 26 // observes the traffic of URLRequests spawned from the URLRequestContexts.
25 // A single instance of NQE can be attached to multiple URLRequestContexts, 27 // A single instance of NQE can be attached to multiple URLRequestContexts,
26 // thereby increasing the single NQE instance's accuracy by providing more 28 // thereby increasing the single NQE instance's accuracy by providing more
27 // observed traffic characteristics. 29 // observed traffic characteristics.
28 class NET_EXPORT_PRIVATE NetworkQualityEstimator 30 class NET_EXPORT_PRIVATE NetworkQualityEstimator
29 : public NetworkChangeNotifier::ConnectionTypeObserver { 31 : public NetworkChangeNotifier::ConnectionTypeObserver {
30 public: 32 public:
31 // Creates a new NetworkQualityEstimator. 33 // Creates a new NetworkQualityEstimator.
32 NetworkQualityEstimator(); 34 NetworkQualityEstimator();
33 35
34 ~NetworkQualityEstimator() override; 36 ~NetworkQualityEstimator() override;
35 37
36 // Returns an estimate of the current network quality. 38 // Returns the peak estimates (fastest RTT and peak throughput) of the
37 NetworkQuality GetEstimate() const; 39 // current network.
40 NetworkQuality GetPeakEstimate() const;
38 41
39 // Notifies NetworkQualityEstimator that a response has been received. 42 // Notifies NetworkQualityEstimator that a response has been received.
40 // |prefilter_bytes_read| is the count of the bytes received prior to 43 // |cummulative_prefilter_bytes_read| is the count of the bytes received prior
41 // applying filters (e.g. decompression, SDCH) from request creation time 44 // to applying filters (e.g. decompression, SDCH) from request creation time
42 // until now. 45 // until now.
46 // |prefiltered_bytes_read| is the count of the bytes received prior
47 // to applying filters in the most recent read.
43 void NotifyDataReceived(const URLRequest& request, 48 void NotifyDataReceived(const URLRequest& request,
44 int64_t prefilter_bytes_read); 49 int64_t cummulative_prefilter_bytes_read,
50 int64_t prefiltered_bytes_read);
45 51
46 private: 52 private:
47 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 53 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
48 TestPeakKbpsFastestRTTUpdates); 54 TestPeakKbpsFastestRTTUpdates);
49 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator); 55 FRIEND_TEST_ALL_PREFIXES(URLRequestTestHTTP, NetworkQualityEstimator);
50 56
57 // Sample is used to store RTT and Kbps samples in buffers. A sample has a
58 // value and a timestamp (when the sample was taken).
59 class Sample {
60 public:
61 explicit Sample(int value);
mmenke 2015/06/03 18:31:40 Suggest taking the time here, to make things a but
tbansal1 2015/06/05 01:50:08 Done.
62
63 virtual ~Sample();
mmenke 2015/06/03 18:31:39 --virtual
tbansal1 2015/06/05 01:50:08 Done.
64
65 // Value of the sample.
66 const int value_;
mmenke 2015/06/03 18:31:39 Classes aren't allowed to have public member varia
tbansal1 2015/06/05 01:50:08 Done.
67
68 // Time when the sample was taken.
69 const base::TimeTicks timestamp_;
70 };
71
72 // Ring Buffer is used to store samples sorted by time.
73 class RingBuffer {
mmenke 2015/06/03 18:31:39 Think it's more important to name classes after wh
tbansal1 2015/06/05 01:50:08 Done.
bengr 2015/06/05 20:44:13 I like SampleBuffer better. Also, can we use the w
tbansal1 2015/06/08 20:27:51 Done.
74 public:
75 RingBuffer();
76
77 virtual ~RingBuffer();
mmenke 2015/06/03 18:31:39 --virtual
tbansal1 2015/06/05 01:50:08 Done.
78
79 void AddSample(int value);
80
81 private:
82 // Maximum number of samples to hold in the RingBuffer.
83 const uint32_t kMaximumSamples = 300;
mmenke 2015/06/03 18:31:40 static?
tbansal1 2015/06/05 01:50:08 Done.
84
85 // Buffer that holds samples sorted by time.
86 // Oldest sample is at the front of the queue.
87 std::deque<Sample> samples_;
88 };
89
51 // Tiny transfer sizes may give inaccurate throughput results. 90 // Tiny transfer sizes may give inaccurate throughput results.
52 // Minimum size of the transfer over which the throughput is computed. 91 // Minimum size of the transfer over which the throughput is computed.
53 static const int kMinTransferSizeInBytes = 10000; 92 static const int kMinTransferSizeInBytes = 10000;
54 93
55 // Minimum duration (in microseconds) of the transfer over which the 94 // Minimum duration (in microseconds) of the transfer over which the
56 // throughput is computed. 95 // throughput is computed.
57 static const int kMinRequestDurationMicroseconds = 1000; 96 static const int kMinRequestDurationMicroseconds = 1000;
58 97
59 // Construct a NetworkQualityEstimator instance allowing for test 98 // Construct a NetworkQualityEstimator instance allowing for test
60 // configuration. 99 // configuration.
(...skipping 25 matching lines...) Expand all
86 // Fastest round-trip-time (RTT) since last connectivity change. RTT measured 125 // Fastest round-trip-time (RTT) since last connectivity change. RTT measured
87 // from URLRequest creation until first byte received. 126 // from URLRequest creation until first byte received.
88 base::TimeDelta fastest_RTT_since_last_connection_change_; 127 base::TimeDelta fastest_RTT_since_last_connection_change_;
89 128
90 // Rough measurement of downlink peak Kbps witnessed since last connectivity 129 // Rough measurement of downlink peak Kbps witnessed since last connectivity
91 // change. The accuracy is decreased by ignoring these factors: 130 // change. The accuracy is decreased by ignoring these factors:
92 // 1) Multiple URLRequests can occur concurrently. 131 // 1) Multiple URLRequests can occur concurrently.
93 // 2) The transfer time includes at least one RTT while no bytes are read. 132 // 2) The transfer time includes at least one RTT while no bytes are read.
94 uint64_t peak_kbps_since_last_connection_change_; 133 uint64_t peak_kbps_since_last_connection_change_;
95 134
135 // Buffer that holds Kbps samples.
136 RingBuffer kbps_;
mmenke 2015/06/03 18:31:39 Maybe kbps_samples_, and same for the next one?
tbansal1 2015/06/05 01:50:08 Done.
137
138 // Buffer that holds RTT (in milliseconds) samples.
139 RingBuffer rtt_msec_;
140
96 base::ThreadChecker thread_checker_; 141 base::ThreadChecker thread_checker_;
97 142
98 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 143 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
99 }; 144 };
100 145
101 } // namespace net 146 } // namespace net
102 147
103 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_ 148 #endif // NET_BASE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698