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

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 flag name 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/metrics/histogram.h"
7 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
8 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
10 #include "net/http/http_request_headers.h" 11 #include "net/http/http_request_headers.h"
11 #include "net/http/http_request_info.h" 12 #include "net/http/http_request_info.h"
12 #include "net/http/http_stream_parser.h" 13 #include "net/http/http_stream_parser.h"
13 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
14 #include "net/socket/client_socket_handle.h" 15 #include "net/socket/client_socket_handle.h"
15 16
17 namespace {
18 std::string g_warm_connection_field_trial_group;
willchan no longer on Chromium 2011/06/09 15:08:54 This is not allowed by the style guide, see http:/
Gagan 2011/06/09 19:49:26 I was following http://codesearch.google.com/#OAMl
willchan no longer on Chromium 2011/06/10 15:05:55 You misunderstand. It doesn't matter if it's a fil
Gagan 2011/06/10 17:44:17 Ah sorry, missed it completely. Changed to global
19 }
20
16 namespace net { 21 namespace net {
17 22
18 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, 23 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection,
19 HttpStreamParser* parser, 24 HttpStreamParser* parser,
20 bool using_proxy) 25 bool using_proxy)
21 : read_buf_(new GrowableIOBuffer()), 26 : read_buf_(new GrowableIOBuffer()),
22 parser_(parser), 27 parser_(parser),
23 connection_(connection), 28 connection_(connection),
24 using_proxy_(using_proxy), 29 using_proxy_(using_proxy),
25 request_info_(NULL) { 30 request_info_(NULL) {
26 } 31 }
27 32
28 HttpBasicStream::~HttpBasicStream() {} 33 HttpBasicStream::~HttpBasicStream() {}
29 34
30 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, 35 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info,
31 const BoundNetLog& net_log, 36 const BoundNetLog& net_log,
32 CompletionCallback* callback) { 37 CompletionCallback* callback) {
33 DCHECK(!parser_.get()); 38 DCHECK(!parser_.get());
34 request_info_ = request_info; 39 request_info_ = request_info;
35 parser_.reset(new HttpStreamParser(connection_.get(), request_info, 40 parser_.reset(new HttpStreamParser(connection_.get(), request_info,
36 read_buf_, net_log)); 41 read_buf_, net_log));
42 bytes_read_offset_ = connection_->socket()->NumBytesRead();
37 return OK; 43 return OK;
38 } 44 }
39 45
40 46
41 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, 47 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
42 UploadDataStream* request_body, 48 UploadDataStream* request_body,
43 HttpResponseInfo* response, 49 HttpResponseInfo* response,
44 CompletionCallback* callback) { 50 CompletionCallback* callback) {
45 DCHECK(parser_.get()); 51 DCHECK(parser_.get());
46 DCHECK(request_info_); 52 DCHECK(request_info_);
47 const std::string path = using_proxy_ ? 53 const std::string path = using_proxy_ ?
48 HttpUtil::SpecForRequest(request_info_->url) : 54 HttpUtil::SpecForRequest(request_info_->url) :
49 HttpUtil::PathForRequest(request_info_->url); 55 HttpUtil::PathForRequest(request_info_->url);
50 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", 56 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n",
51 request_info_->method.c_str(), 57 request_info_->method.c_str(),
52 path.c_str()); 58 path.c_str());
59 response_ = response;
53 return parser_->SendRequest(request_line_, headers, request_body, response, 60 return parser_->SendRequest(request_line_, headers, request_body, response,
54 callback); 61 callback);
55 } 62 }
56 63
57 uint64 HttpBasicStream::GetUploadProgress() const { 64 uint64 HttpBasicStream::GetUploadProgress() const {
58 return parser_->GetUploadProgress(); 65 return parser_->GetUploadProgress();
59 } 66 }
60 67
61 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { 68 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) {
62 return parser_->ReadResponseHeaders(callback); 69 return parser_->ReadResponseHeaders(callback);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 119
113 void HttpBasicStream::GetSSLCertRequestInfo( 120 void HttpBasicStream::GetSSLCertRequestInfo(
114 SSLCertRequestInfo* cert_request_info) { 121 SSLCertRequestInfo* cert_request_info) {
115 parser_->GetSSLCertRequestInfo(cert_request_info); 122 parser_->GetSSLCertRequestInfo(cert_request_info);
116 } 123 }
117 124
118 bool HttpBasicStream::IsSpdyHttpStream() const { 125 bool HttpBasicStream::IsSpdyHttpStream() const {
119 return false; 126 return false;
120 } 127 }
121 128
129 void HttpBasicStream::LogNumRttVsBytesMetrics() const {
130 int64 total_bytes_read = connection_->socket()->NumBytesRead();
131 int64 bytes_received = total_bytes_read - bytes_read_offset_;
132 int64 num_kb = bytes_received / 1024;
133 double rtt = connection_->socket()->GetRTTInMs();
134
135 if (num_kb < 1024 && rtt > 0) { // Ignore responses > 1MB
136 base::TimeDelta duration = base::Time::Now() -
137 response_->request_time;
138 double num_rtt = static_cast<double>(duration.InMilliseconds()) / rtt;
139 int64 num_rtt_scaled = (4 * num_rtt);
140 int val = 1024 * num_rtt_scaled + num_kb; // Supports ~500 RTT of 1418 B.
Mike Belshe 2011/06/09 16:08:52 Can you add comments about why you're doing this m
Gagan 2011/06/09 19:49:26 num_rtt is a double, so scaling it by 4 to basical
141
142 std::string histogram = "Net.RTT_vs_KB_";
143 histogram += g_warm_connection_field_trial_group;
144 HISTOGRAM_CUSTOM_COUNTS(histogram, val, 4096, 3048000, 1000);
Mike Belshe 2011/06/09 16:08:52 bug: This histogram code is incorrect, note that
Gagan 2011/06/09 19:49:26 the counter is static, but its value is the return
145 LOG(ERROR) << request_line_
146 << "\nrtt = " << rtt << "\tnum_rtt = " << num_rtt
147 << "\tnum_kb = " << num_kb << "\tval = " << val
148 << "\ttotal bytes = " << total_bytes_read;
149 }
150 }
151
152 // static
153 void HttpBasicStream::set_warm_connection_field_trial_group(
154 const std::string& group) {
155 g_warm_connection_field_trial_group = group;
156 }
157
122 } // namespace net 158 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698