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

Side by Side Diff: net/http/http_basic_stream.cc

Issue 6990036: Deciding best connection to schedule requests on based on cwnd and idle time (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: fixing release build policy check Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/http/http_basic_stream.h" 5 #include "net/http/http_basic_stream.h"
6 6
7 #include "base/format_macros.h"
8 #include "base/metrics/histogram.h"
7 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
8 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
10 #include "net/http/http_request_headers.h" 12 #include "net/http/http_request_headers.h"
11 #include "net/http/http_request_info.h" 13 #include "net/http/http_request_info.h"
12 #include "net/http/http_stream_parser.h" 14 #include "net/http/http_stream_parser.h"
13 #include "net/http/http_util.h" 15 #include "net/http/http_util.h"
14 #include "net/socket/client_socket_handle.h" 16 #include "net/socket/client_socket_handle.h"
17 #include "net/socket/client_socket_pool_base.h"
15 18
16 namespace net { 19 namespace net {
17 20
18 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, 21 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection,
19 HttpStreamParser* parser, 22 HttpStreamParser* parser,
20 bool using_proxy) 23 bool using_proxy)
21 : read_buf_(new GrowableIOBuffer()), 24 : read_buf_(new GrowableIOBuffer()),
22 parser_(parser), 25 parser_(parser),
23 connection_(connection), 26 connection_(connection),
24 using_proxy_(using_proxy), 27 using_proxy_(using_proxy),
25 request_info_(NULL) { 28 request_info_(NULL) {
26 } 29 }
27 30
28 HttpBasicStream::~HttpBasicStream() {} 31 HttpBasicStream::~HttpBasicStream() {}
29 32
30 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, 33 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info,
31 const BoundNetLog& net_log, 34 const BoundNetLog& net_log,
32 CompletionCallback* callback) { 35 CompletionCallback* callback) {
33 DCHECK(!parser_.get()); 36 DCHECK(!parser_.get());
34 request_info_ = request_info; 37 request_info_ = request_info;
35 parser_.reset(new HttpStreamParser(connection_.get(), request_info, 38 parser_.reset(new HttpStreamParser(connection_.get(), request_info,
36 read_buf_, net_log)); 39 read_buf_, net_log));
40 bytes_read_offset_ = connection_->socket()->NumBytesRead();
37 return OK; 41 return OK;
38 } 42 }
39 43
40 44
41 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, 45 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
42 UploadDataStream* request_body, 46 UploadDataStream* request_body,
43 HttpResponseInfo* response, 47 HttpResponseInfo* response,
44 CompletionCallback* callback) { 48 CompletionCallback* callback) {
45 DCHECK(parser_.get()); 49 DCHECK(parser_.get());
46 DCHECK(request_info_); 50 DCHECK(request_info_);
47 const std::string path = using_proxy_ ? 51 const std::string path = using_proxy_ ?
48 HttpUtil::SpecForRequest(request_info_->url) : 52 HttpUtil::SpecForRequest(request_info_->url) :
49 HttpUtil::PathForRequest(request_info_->url); 53 HttpUtil::PathForRequest(request_info_->url);
50 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", 54 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n",
51 request_info_->method.c_str(), 55 request_info_->method.c_str(),
52 path.c_str()); 56 path.c_str());
57 response_ = response;
53 return parser_->SendRequest(request_line_, headers, request_body, response, 58 return parser_->SendRequest(request_line_, headers, request_body, response,
54 callback); 59 callback);
55 } 60 }
56 61
57 uint64 HttpBasicStream::GetUploadProgress() const { 62 uint64 HttpBasicStream::GetUploadProgress() const {
58 return parser_->GetUploadProgress(); 63 return parser_->GetUploadProgress();
59 } 64 }
60 65
61 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { 66 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) {
62 return parser_->ReadResponseHeaders(callback); 67 return parser_->ReadResponseHeaders(callback);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 117
113 void HttpBasicStream::GetSSLCertRequestInfo( 118 void HttpBasicStream::GetSSLCertRequestInfo(
114 SSLCertRequestInfo* cert_request_info) { 119 SSLCertRequestInfo* cert_request_info) {
115 parser_->GetSSLCertRequestInfo(cert_request_info); 120 parser_->GetSSLCertRequestInfo(cert_request_info);
116 } 121 }
117 122
118 bool HttpBasicStream::IsSpdyHttpStream() const { 123 bool HttpBasicStream::IsSpdyHttpStream() const {
119 return false; 124 return false;
120 } 125 }
121 126
127 void HttpBasicStream::LogNumRttVsBytesMetrics() const {
128 int socket_reuse_policy = GetSocketReusePolicy();
129 DCHECK_GE(socket_reuse_policy, 0);
130 DCHECK_LE(socket_reuse_policy, 2);
131 if (socket_reuse_policy > 2 || socket_reuse_policy < 0) {
132 LOG(ERROR) << "Invalid socket reuse policy";
133 return;
134 }
135
136 int64 total_bytes_read = connection_->socket()->NumBytesRead();
137 int64 bytes_received = total_bytes_read - bytes_read_offset_;
138 int64 num_kb = bytes_received / 1024;
139 double rtt = connection_->socket()->GetConnectTimeMicros();
140 rtt /= 1000.0;
141
142 if (num_kb < 1024 && rtt > 0) { // Ignore responses > 1MB
143 base::TimeDelta duration = base::Time::Now() -
144 response_->request_time;
145 double num_rtt = static_cast<double>(duration.InMilliseconds()) / rtt;
146 int64 num_rtt_scaled = (4 * num_rtt);
147
148 static const char* const kGroups[] = {
149 "warmest_socket", "warm_socket", "last_accessed_socket"
150 };
151 int bucket = (num_kb / 5) * 5;
152 const std::string histogram(StringPrintf("Net.Num_RTT_vs_KB_%s_%dKB",
153 kGroups[socket_reuse_policy],
154 bucket));
155 base::Histogram* counter = base::Histogram::FactoryGet(
156 histogram, 0, 1000, 2, base::Histogram::kUmaTargetedHistogramFlag);
157 DCHECK_EQ(histogram, counter->histogram_name());
158 counter->Add(num_rtt_scaled);
159
160 if (VLOG_IS_ON(2)) {
willchan no longer on Chromium 2011/06/16 09:52:44 Why aren't you just doing VLOG(2) <<
Gagan 2011/06/16 11:49:29 I thought this would be more efficient since it di
161 LOG(INFO) << StringPrintf("%s\nrtt = %f\tnum_rtt = %f\t"
162 "num_kb = %" PRId64 "\t"
163 "total bytes = %" PRId64 "\t"
164 "histogram = %s",
165 request_line_.data(),
166 rtt, num_rtt, num_kb, total_bytes_read,
167 histogram.data());
168 }
169 }
170 }
171
122 } // namespace net 172 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698