| Index: net/socket/client_socket_pool_base.cc
|
| ===================================================================
|
| --- net/socket/client_socket_pool_base.cc (revision 86260)
|
| +++ net/socket/client_socket_pool_base.cc (working copy)
|
| @@ -4,11 +4,18 @@
|
|
|
| #include "net/socket/client_socket_pool_base.h"
|
|
|
| +#include <algorithm>
|
| +#include <math.h>
|
| +#include <utility>
|
| +
|
| +#include "base/command_line.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-inl.h"
|
| +#include "base/string_number_conversions.h"
|
| #include "base/string_util.h"
|
| #include "base/time.h"
|
| #include "base/values.h"
|
| @@ -32,6 +39,9 @@
|
| // after a certain timeout has passed without receiving an ACK.
|
| bool g_connect_backup_jobs_enabled = true;
|
|
|
| +// Alpha.
|
| +double g_bytes_read_vs_last_accessed_alpha = 1000000;
|
| +
|
| } // namespace
|
|
|
| namespace net {
|
| @@ -363,7 +373,13 @@
|
| 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_benefit = -100000000;
|
| + std::pair<int, int64> best_pair;
|
|
|
| + std::string debug_log(request->handle()->group_name());
|
| + std::string candidates;
|
| + double rtt_ms = 0;
|
| +
|
| // Iterate through the idle sockets forwards (oldest to newest)
|
| // * Delete any disconnected ones.
|
| // * If we find a used idle socket, assign to |idle_socket|. At the end,
|
| @@ -379,11 +395,34 @@
|
|
|
| if (it->socket->WasEverUsed()) {
|
| // We found one we can reuse!
|
| - idle_socket_it = it;
|
| + int bytes_read = it->socket->NumBytesRead();
|
| + double B = (double) bytes_read / 1024.0;
|
| +
|
| + int64 idle_time = (base::TimeTicks::Now() - it->start_time)
|
| + .InMicroseconds();
|
| + double idle_time_mins = ((double) idle_time) / (60000000.0);
|
| + double T = pow(g_bytes_read_vs_last_accessed_alpha, idle_time_mins);
|
| +
|
| + debug_log = StringPrintf("%s\n%f\t%f\t%f",
|
| + debug_log.data(), B, idle_time_mins, T);
|
| + double benefit = B - T;
|
| +
|
| + // Equality to prefer recently used connection.
|
| + if (benefit >= max_benefit) {
|
| + idle_socket_it = it;
|
| + max_benefit = benefit;
|
| + best_pair = std::make_pair(bytes_read, idle_time);
|
| + rtt_ms = it->socket->GetRTTMs();
|
| + }
|
| }
|
|
|
| ++it;
|
| }
|
| + debug_log = StringPrintf("%s\nChose socket <%d %lld>\nRtt = %f",
|
| + debug_log.data(),
|
| + best_pair.first, best_pair.second,
|
| + rtt_ms);
|
| + LOG(ERROR) << "\n\n----------------------------------------" << debug_log;
|
|
|
| // If we haven't found an idle socket, that means there are no used idle
|
| // sockets. Pick the oldest (first) idle socket (FIFO).
|
| @@ -649,6 +688,15 @@
|
| return old_value;
|
| }
|
|
|
| +// static
|
| +double ClientSocketPoolBaseHelper::set_bytes_read_vs_last_accessed_alpha(
|
| + double alpha) {
|
| + LOG(ERROR) << "Setting g_bytes_read_vs_last_accessed_alpha = " << alpha;
|
| + double old_value = g_bytes_read_vs_last_accessed_alpha;
|
| + g_bytes_read_vs_last_accessed_alpha = alpha;
|
| + return old_value;
|
| +}
|
| +
|
| void ClientSocketPoolBaseHelper::EnableConnectBackupJobs() {
|
| connect_backup_jobs_enabled_ = g_connect_backup_jobs_enabled;
|
| }
|
|
|