Commit e86df8dc authored by mmenke@chromium.org's avatar mmenke@chromium.org

Remove experimental code to pick the "warmest" socket

(based on age and bytes received) in favor of older
algorithm to pick the most recently used socket.

Tests showed no real performance difference, so
defaulting to the older, simpler, and more intuitive
algorithm.

This is basically a revert of
https://codereview.chromium.org/7251004

TBR=sergeyu@chromium.org
BUG=222090
Review URL: https://codereview.chromium.org/12886034

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191507 0039d316-1c4b-4281-b951-d872f2087c98
parent 36e55397
......@@ -30,7 +30,6 @@
#include "chrome/common/metrics/variations/uniformity_field_trials.h"
#include "chrome/common/metrics/variations/variations_util.h"
#include "chrome/common/pref_names.h"
#include "net/socket/client_socket_pool_base.h"
#include "net/spdy/spdy_session.h"
#include "ui/base/layout.h"
......@@ -38,23 +37,9 @@
#include "net/socket/tcp_client_socket_win.h"
#endif // defined(OS_WIN)
namespace {
void SetSocketReusePolicy(int warmest_socket_trial_group,
const int socket_policy[],
int num_groups) {
const int* result = std::find(socket_policy, socket_policy + num_groups,
warmest_socket_trial_group);
DCHECK_NE(result, socket_policy + num_groups)
<< "Not a valid socket reuse policy group";
net::SetSocketReusePolicy(result - socket_policy);
}
} // namespace
ChromeBrowserFieldTrials::ChromeBrowserFieldTrials(
const CommandLine& parsed_command_line) :
parsed_command_line_(parsed_command_line) {
const CommandLine& parsed_command_line)
: parsed_command_line_(parsed_command_line) {
}
ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() {
......@@ -75,7 +60,6 @@ void ChromeBrowserFieldTrials::SetupDesktopFieldTrials(
PrefService* local_state) {
prerender::ConfigurePrefetchAndPrerender(parsed_command_line_);
SpdyFieldTrial();
WarmConnectionFieldTrial();
AutoLaunchChromeFieldTrial();
gpu_util::InitializeCompositingFieldTrial();
OmniboxFieldTrial::ActivateStaticTrials();
......@@ -125,47 +109,6 @@ void ChromeBrowserFieldTrials::SpdyFieldTrial() {
trial->AppendGroup("cwndMin10", kSpdyCwndMin10);
}
// If --socket-reuse-policy is not specified, run an A/B test for choosing the
// warmest socket.
void ChromeBrowserFieldTrials::WarmConnectionFieldTrial() {
const CommandLine& command_line = parsed_command_line_;
if (command_line.HasSwitch(switches::kSocketReusePolicy)) {
std::string socket_reuse_policy_str = command_line.GetSwitchValueASCII(
switches::kSocketReusePolicy);
int policy = -1;
base::StringToInt(socket_reuse_policy_str, &policy);
const int policy_list[] = { 0, 1, 2 };
VLOG(1) << "Setting socket_reuse_policy = " << policy;
SetSocketReusePolicy(policy, policy_list, arraysize(policy_list));
return;
}
const base::FieldTrial::Probability kWarmSocketDivisor = 100;
const base::FieldTrial::Probability kWarmSocketProbability = 33;
// Default value is USE_LAST_ACCESSED_SOCKET.
int last_accessed_socket = -1;
// After January 30, 2013 builds, it will always be in default group.
scoped_refptr<base::FieldTrial> warmest_socket_trial(
base::FieldTrialList::FactoryGetFieldTrial(
"WarmSocketImpact", kWarmSocketDivisor, "last_accessed_socket",
2013, 1, 30, &last_accessed_socket));
const int warmest_socket = warmest_socket_trial->AppendGroup(
"warmest_socket", kWarmSocketProbability);
const int warm_socket = warmest_socket_trial->AppendGroup(
"warm_socket", kWarmSocketProbability);
const int warmest_socket_trial_group = warmest_socket_trial->group();
const int policy_list[] = { warmest_socket, warm_socket,
last_accessed_socket };
SetSocketReusePolicy(warmest_socket_trial_group, policy_list,
arraysize(policy_list));
}
void ChromeBrowserFieldTrials::AutoLaunchChromeFieldTrial() {
std::string brand;
google_util::GetBrand(&brand);
......
......@@ -7,7 +7,6 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/gtest_prod_util.h"
#include "base/time.h"
class PrefService;
......@@ -22,11 +21,6 @@ class ChromeBrowserFieldTrials {
void SetupFieldTrials(PrefService* local_state);
private:
FRIEND_TEST_ALL_PREFIXES(BrowserMainTest,
WarmConnectionFieldTrial_WarmestSocket);
FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random);
FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
// Sets up common desktop-only field trials.
// Add an invocation of your field trial init function to this method, or to
// SetupFieldTrials if it is for all platforms.
......@@ -41,9 +35,6 @@ class ChromeBrowserFieldTrials {
// A/B test for spdy when --use-spdy not set.
void SpdyFieldTrial();
// A/B test for warmest socket vs. most recently used socket.
void WarmConnectionFieldTrial();
// Field trial to see what disabling DNS pre-resolution does to
// latency of page loads.
void PredictorFieldTrial();
......
......@@ -6,9 +6,7 @@
#define CHROME_BROWSER_CHROME_BROWSER_MAIN_H_
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/metrics/field_trial.h"
#include "base/tracked_objects.h"
#include "chrome/browser/chrome_browser_field_trials.h"
......@@ -199,11 +197,6 @@ class ChromeBrowserMainParts : public content::BrowserMainParts {
// network stack, as this can only be done once.
static bool disable_enforcing_cookie_policies_for_tests_;
friend class BrowserMainTest;
FRIEND_TEST_ALL_PREFIXES(BrowserMainTest,
WarmConnectionFieldTrial_WarmestSocket);
FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Random);
FRIEND_TEST_ALL_PREFIXES(BrowserMainTest, WarmConnectionFieldTrial_Invalid);
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainParts);
};
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/prefs/testing_pref_service.h"
#include "chrome/browser/chrome_browser_main.h"
#include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/main_function_params.h"
#include "net/socket/client_socket_pool_base.h"
#include "testing/gtest/include/gtest/gtest.h"
class BrowserMainTest : public testing::Test {
public:
BrowserMainTest()
: command_line_(CommandLine::NO_PROGRAM) {
ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ = true;
}
protected:
CommandLine command_line_;
};
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_WarmestSocket) {
command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "0");
scoped_ptr<content::MainFunctionParams> params(
new content::MainFunctionParams(command_line_));
scoped_ptr<content::BrowserMainParts> browser_main_parts(
content::GetContentClient()->browser()->CreateBrowserMainParts(*params));
ChromeBrowserMainParts* chrome_main_parts =
static_cast<ChromeBrowserMainParts*>(browser_main_parts.get());
EXPECT_TRUE(chrome_main_parts);
if (chrome_main_parts) {
base::FieldTrialList field_trial_list_(NULL);
chrome_main_parts->browser_field_trials_.WarmConnectionFieldTrial();
EXPECT_EQ(0, net::GetSocketReusePolicy());
}
}
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Random) {
scoped_ptr<content::MainFunctionParams> params(
new content::MainFunctionParams(command_line_));
scoped_ptr<content::BrowserMainParts> browser_main_parts(
content::GetContentClient()->browser()->CreateBrowserMainParts(*params));
ChromeBrowserMainParts* chrome_main_parts =
static_cast<ChromeBrowserMainParts*>(browser_main_parts.get());
EXPECT_TRUE(chrome_main_parts);
if (chrome_main_parts) {
const int kNumRuns = 1000;
for (int i = 0; i < kNumRuns; i++) {
base::FieldTrialList field_trial_list_(NULL);
chrome_main_parts->browser_field_trials_.WarmConnectionFieldTrial();
int val = net::GetSocketReusePolicy();
EXPECT_LE(val, 2);
EXPECT_GE(val, 0);
}
}
}
#if GTEST_HAS_DEATH_TEST
TEST_F(BrowserMainTest, WarmConnectionFieldTrial_Invalid) {
command_line_.AppendSwitchASCII(switches::kSocketReusePolicy, "100");
scoped_ptr<content::MainFunctionParams> params(
new content::MainFunctionParams(command_line_));
// This test ends up launching a new process, and that doesn't initialize the
// ContentClient interfaces.
scoped_ptr<content::BrowserMainParts> browser_main_parts;
if (content::GetContentClient()) {
browser_main_parts.reset(content::GetContentClient()->browser()->
CreateBrowserMainParts(*params));
} else {
chrome::ChromeContentBrowserClient client;
browser_main_parts.reset(client.CreateBrowserMainParts(*params));
}
ChromeBrowserMainParts* parts =
static_cast<ChromeBrowserMainParts*>(browser_main_parts.get());
EXPECT_TRUE(parts);
if (parts) {
#if defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
EXPECT_DEATH(parts->browser_field_trials_.WarmConnectionFieldTrial(),
"Not a valid socket reuse policy group");
#else
EXPECT_DEBUG_DEATH(parts->browser_field_trials_.WarmConnectionFieldTrial(),
"Not a valid socket reuse policy group");
#endif
}
}
#endif
......@@ -520,7 +520,6 @@
'browser/captive_portal/testing_utils.cc',
'browser/captive_portal/testing_utils.h',
'browser/chrome_browser_application_mac_unittest.mm',
'browser/chrome_browser_main_unittest.cc',
'browser/chrome_page_zoom_unittest.cc',
'browser/chromeos/accessibility/magnification_manager_unittest.cc',
'browser/chromeos/contacts/contact_database_unittest.cc',
......
......@@ -1271,10 +1271,6 @@ const char kSimulateOutdated[] = "simulate-outdated";
// Replaces the buffered data source for <audio> and <video> with a simplified
// resource loader that downloads the entire resource into memory.
// Socket reuse policy. The value should be of type enum
// ClientSocketReusePolicy.
const char kSocketReusePolicy[] = "socket-reuse-policy";
// Origin for which SpdyProxy authentication is supported.
const char kSpdyProxyAuthOrigin[] = "spdy-proxy-auth-origin";
......
......@@ -336,7 +336,6 @@ extern const char kSilentDumpOnDCHECK[];
extern const char kSimulateUpgrade[];
extern const char kSimulateCriticalUpdate[];
extern const char kSimulateOutdated[];
extern const char kSocketReusePolicy[];
extern const char kSpeculativeResourcePrefetching[];
extern const char kSpeculativeResourcePrefetchingDisabled[];
extern const char kSpeculativeResourcePrefetchingLearning[];
......
......@@ -73,8 +73,6 @@ class FakeSocket : public net::StreamSocket {
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual bool WasNpnNegotiated() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;
virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
......@@ -213,14 +211,6 @@ bool FakeSocket::UsingTCPFastOpen() const {
return false;
}
int64 FakeSocket::NumBytesRead() const {
return -1;
}
base::TimeDelta FakeSocket::GetConnectTimeMicros() const {
return base::TimeDelta::FromMicroseconds(-1);
}
bool FakeSocket::WasNpnNegotiated() const {
return false;
}
......
......@@ -330,14 +330,6 @@ bool FakeSSLClientSocket::UsingTCPFastOpen() const {
return transport_socket_->UsingTCPFastOpen();
}
int64 FakeSSLClientSocket::NumBytesRead() const {
return transport_socket_->NumBytesRead();
}
base::TimeDelta FakeSSLClientSocket::GetConnectTimeMicros() const {
return transport_socket_->GetConnectTimeMicros();
}
bool FakeSSLClientSocket::WasNpnNegotiated() const {
return transport_socket_->WasNpnNegotiated();
}
......
......@@ -63,8 +63,6 @@ class FakeSSLClientSocket : public net::StreamSocket {
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual bool WasNpnNegotiated() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;
virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
......
......@@ -373,20 +373,6 @@ bool ProxyResolvingClientSocket::UsingTCPFastOpen() const {
return false;
}
int64 ProxyResolvingClientSocket::NumBytesRead() const {
if (transport_.get() && transport_->socket())
return transport_->socket()->NumBytesRead();
NOTREACHED();
return -1;
}
base::TimeDelta ProxyResolvingClientSocket::GetConnectTimeMicros() const {
if (transport_.get() && transport_->socket())
return transport_->socket()->GetConnectTimeMicros();
NOTREACHED();
return base::TimeDelta::FromMicroseconds(-1);
}
bool ProxyResolvingClientSocket::WasNpnNegotiated() const {
return false;
}
......
......@@ -65,8 +65,6 @@ class ProxyResolvingClientSocket : public net::StreamSocket {
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual bool WasNpnNegotiated() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;
virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
......
......@@ -563,16 +563,6 @@ bool PseudoTcpAdapter::UsingTCPFastOpen() const {
return false;
}
int64 PseudoTcpAdapter::NumBytesRead() const {
DCHECK(CalledOnValidThread());
return -1;
}
base::TimeDelta PseudoTcpAdapter::GetConnectTimeMicros() const {
DCHECK(CalledOnValidThread());
return base::TimeDelta::FromMicroseconds(-1);
}
bool PseudoTcpAdapter::WasNpnNegotiated() const {
DCHECK(CalledOnValidThread());
return false;
......
......@@ -49,8 +49,6 @@ class PseudoTcpAdapter : public net::StreamSocket, base::NonThreadSafe {
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual bool WasNpnNegotiated() const OVERRIDE;
virtual net::NextProto GetNegotiatedProtocol() const OVERRIDE;
virtual bool GetSSLInfo(net::SSLInfo* ssl_info) OVERRIDE;
......
......@@ -4,8 +4,6 @@
#include "net/http/http_basic_stream.h"
#include "base/format_macros.h"
#include "base/metrics/histogram.h"
#include "base/stringprintf.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
......@@ -15,7 +13,6 @@
#include "net/http/http_stream_parser.h"
#include "net/http/http_util.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_base.h"
namespace net {
......@@ -26,9 +23,7 @@ HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection,
parser_(parser),
connection_(connection),
using_proxy_(using_proxy),
request_info_(NULL),
response_(NULL),
bytes_read_offset_(0) {
request_info_(NULL) {
}
HttpBasicStream::~HttpBasicStream() {}
......@@ -42,7 +37,6 @@ int HttpBasicStream::InitializeStream(
request_info_ = request_info;
parser_.reset(new HttpStreamParser(connection_.get(), request_info,
read_buf_, net_log));
bytes_read_offset_ = connection_->socket()->NumBytesRead();
return OK;
}
......@@ -58,7 +52,6 @@ int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n",
request_info_->method.c_str(),
path.c_str());
response_ = response;
return parser_->SendRequest(request_line_, headers, response, callback);
}
......@@ -128,10 +121,6 @@ bool HttpBasicStream::IsSpdyHttpStream() const {
return false;
}
void HttpBasicStream::LogNumRttVsBytesMetrics() const {
// Log rtt metrics here.
}
void HttpBasicStream::Drain(HttpNetworkSession* session) {
HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this);
drainer->Start(session);
......
......@@ -79,8 +79,6 @@ class HttpBasicStream : public HttpStream {
virtual bool IsSpdyHttpStream() const OVERRIDE;
virtual void LogNumRttVsBytesMetrics() const OVERRIDE;
virtual void Drain(HttpNetworkSession* session) OVERRIDE;
private:
......@@ -96,10 +94,6 @@ class HttpBasicStream : public HttpStream {
const HttpRequestInfo* request_info_;
const HttpResponseInfo* response_;
int64 bytes_read_offset_;
DISALLOW_COPY_AND_ASSIGN(HttpBasicStream);
};
......
......@@ -990,8 +990,6 @@ int HttpNetworkTransaction::DoReadBodyComplete(int result) {
// Clean up connection if we are done.
if (done) {
LogTransactionMetrics();
// TODO(bashi): This cast is temporary. Remove later.
static_cast<HttpStream*>(stream_.get())->LogNumRttVsBytesMetrics();
stream_->Close(!keep_alive);
// Note: we don't reset the stream here. We've closed it, but we still
// need it around so that callers can call methods such as
......
......@@ -15,7 +15,6 @@
#include "base/files/file_path.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/test/test_file_util.h"
#include "base/utf_string_conversions.h"
......
......@@ -15,7 +15,6 @@
#include "base/files/file_path.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/test/test_file_util.h"
#include "base/utf_string_conversions.h"
......
......@@ -117,10 +117,6 @@ bool HttpPipelinedStream::IsSpdyHttpStream() const {
return false;
}
void HttpPipelinedStream::LogNumRttVsBytesMetrics() const {
// TODO(simonjam): I don't want to copy & paste this from http_basic_stream.
}
void HttpPipelinedStream::Drain(HttpNetworkSession* session) {
pipeline_->Drain(this, session);
}
......
......@@ -79,8 +79,6 @@ class HttpPipelinedStream : public HttpStream {
virtual bool IsSpdyHttpStream() const OVERRIDE;
virtual void LogNumRttVsBytesMetrics() const OVERRIDE;
virtual void Drain(HttpNetworkSession* session) OVERRIDE;
// The SSLConfig used to establish this stream's pipeline.
......
......@@ -184,22 +184,6 @@ bool HttpProxyClientSocket::UsingTCPFastOpen() const {
return false;
}
int64 HttpProxyClientSocket::NumBytesRead() const {
if (transport_.get() && transport_->socket()) {
return transport_->socket()->NumBytesRead();
}
NOTREACHED();
return -1;
}
base::TimeDelta HttpProxyClientSocket::GetConnectTimeMicros() const {
if (transport_.get() && transport_->socket()) {
return transport_->socket()->GetConnectTimeMicros();
}
NOTREACHED();
return base::TimeDelta::FromMicroseconds(-1);
}
bool HttpProxyClientSocket::WasNpnNegotiated() const {
if (transport_.get() && transport_->socket()) {
return transport_->socket()->WasNpnNegotiated();
......
......@@ -70,8 +70,6 @@ class HttpProxyClientSocket : public ProxyClientSocket {
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual bool WasNpnNegotiated() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
......
......@@ -122,8 +122,6 @@ class MockHttpStream : public HttpStream {
virtual bool IsSpdyHttpStream() const OVERRIDE { return false; }
virtual void LogNumRttVsBytesMetrics() const OVERRIDE {}
virtual bool GetLoadTimingInfo(
LoadTimingInfo* load_timing_info) const OVERRIDE { return false; }
......
......@@ -36,10 +36,6 @@ class NET_EXPORT_PRIVATE HttpStream : public HttpStreamBase {
// subclass does not support renewing the stream, NULL is returned.
virtual HttpStream* RenewStreamForAuth() = 0;
// Record histogram of number of round trips taken to download the full
// response body vs bytes transferred.
virtual void LogNumRttVsBytesMetrics() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(HttpStream);
};
......
......@@ -52,7 +52,6 @@ class NET_EXPORT_PRIVATE QuicHttpStream :
virtual void GetSSLCertRequestInfo(
SSLCertRequestInfo* cert_request_info) OVERRIDE;
virtual bool IsSpdyHttpStream() const OVERRIDE;
virtual void LogNumRttVsBytesMetrics() const OVERRIDE {}
virtual void Drain(HttpNetworkSession* session) OVERRIDE;
// QuicReliableClientStream::Delegate implementation
......
......@@ -111,14 +111,6 @@ bool BufferedWriteStreamSocket::UsingTCPFastOpen() const {
return wrapped_socket_->UsingTCPFastOpen();
}
int64 BufferedWriteStreamSocket::NumBytesRead() const {
return wrapped_socket_->NumBytesRead();
}
base::TimeDelta BufferedWriteStreamSocket::GetConnectTimeMicros() const {
return wrapped_socket_->GetConnectTimeMicros();
}
bool BufferedWriteStreamSocket::WasNpnNegotiated() const {
return wrapped_socket_->WasNpnNegotiated();
}
......
......@@ -56,8 +56,6 @@ class NET_EXPORT_PRIVATE BufferedWriteStreamSocket : public StreamSocket {
virtual void SetOmniboxSpeculation() OVERRIDE;
virtual bool WasEverUsed() const OVERRIDE;
virtual bool UsingTCPFastOpen() const OVERRIDE;
virtual int64 NumBytesRead() const OVERRIDE;
virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE;
virtual bool WasNpnNegotiated() const OVERRIDE;
virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
......
......@@ -4,14 +4,12 @@
#include "net/socket/client_socket_pool_base.h"
#include <math.h>
#include "base/compiler_specific.h"
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/metrics/stats_counters.h"
#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/time.h"
#include "base/values.h"
......@@ -39,33 +37,10 @@ const int kCleanupInterval = 10; // DO NOT INCREASE THIS TIMEOUT.
// after a certain timeout has passed without receiving an ACK.
bool g_connect_backup_jobs_enabled = true;
double g_socket_reuse_policy_penalty_exponent = -1;
int g_socket_reuse_policy = -1;
} // namespace
namespace net {
int GetSocketReusePolicy() {
return g_socket_reuse_policy;
}
void SetSocketReusePolicy(int policy) {
DCHECK_GE(policy, 0);
DCHECK_LE(policy, 2);
if (policy > 2 || policy < 0) {
LOG(ERROR) << "Invalid socket reuse policy";
return;
}
double exponents[] = { 0, 0.25, -1 };
g_socket_reuse_policy_penalty_exponent = exponents[policy];
g_socket_reuse_policy = policy;
VLOG(1) << "Setting g_socket_reuse_policy_penalty_exponent = "
<< g_socket_reuse_policy_penalty_exponent;
}
ConnectJob::ConnectJob(const std::string& group_name,
base::TimeDelta timeout_duration,
Delegate* delegate,
......@@ -426,7 +401,6 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
const Request* request, Group* group) {
std::list<IdleSocket>* idle_sockets = group->mutable_idle_sockets();
std::list<IdleSocket>::iterator idle_socket_it = idle_sockets->end();
double max_score = -1;
// Iterate through the idle sockets forwards (oldest to newest)
// * Delete any disconnected ones.
......@@ -443,22 +417,7 @@ bool ClientSocketPoolBaseHelper::AssignIdleSocketToRequest(
if (it->socket->WasEverUsed()) {
// We found one we can reuse!
double score = 0;
int64 bytes_read = it->socket->NumBytesRead();
double num_kb = static_cast<double>(bytes_read) / 1024.0;
int idle_time_sec = (base::TimeTicks::Now() - it->start_time).InSeconds();
idle_time_sec = std::max(1, idle_time_sec);
if (g_socket_reuse_policy_penalty_exponent >= 0 && num_kb >= 0) {
score = num_kb / pow(idle_time_sec,
g_socket_reuse_policy_penalty_exponent);
}
// Equality to prefer recently used connection.
if (score >= max_score) {
idle_socket_it = it;
max_score = score;
}
idle_socket_it = it;
}
++it;
......
......@@ -51,13 +51,6 @@ namespace net {
class ClientSocketHandle;
// Returns the client socket reuse policy.
NET_EXPORT_PRIVATE int GetSocketReusePolicy();
// Sets the client socket reuse policy.
// NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value.
NET_EXPORT void SetSocketReusePolicy(int policy);
// ConnectJob provides an abstract interface for "connecting" a socket.
// The connection may involve host resolution, tcp connection, ssl connection,
// etc.
......@@ -161,17 +154,6 @@ class NET_EXPORT_PRIVATE ClientSocketPoolBaseHelper
NO_IDLE_SOCKETS = 0x1, // Do not return an idle socket. Create a new one.
};
enum ClientSocketReusePolicy {
// Socket with largest amount of bytes transferred.
USE_WARMEST_SOCKET = 0,
// Socket which scores highest on large bytes transferred and low idle time.
USE_WARM_SOCKET = 1,
// Socket which was most recently used.
USE_LAST_ACCESSED_SOCKET = 2,