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

Unified Diff: net/socket/client_socket_pool_base.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: addressing comments 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 side-by-side diff with in-line comments
Download patch
Index: net/socket/client_socket_pool_base.cc
===================================================================
--- net/socket/client_socket_pool_base.cc (revision 88789)
+++ net/socket/client_socket_pool_base.cc (working copy)
@@ -4,11 +4,16 @@
#include "net/socket/client_socket_pool_base.h"
+#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,10 +37,28 @@
// after a certain timeout has passed without receiving an ACK.
bool g_connect_backup_jobs_enabled = true;
+// Decay coef.
+double g_socket_reuse_policy_penalty_coef = -1;
willchan no longer on Chromium 2011/06/14 12:01:22 Why is this called a coefficient? It looks like an
Gagan 2011/06/14 18:25:02 Done.
+
} // namespace
namespace net {
+// static
+double SetSocketReusePolicy(int policy) {
+ using internal::ClientSocketPoolBaseHelper;
+ double old_value = g_socket_reuse_policy_penalty_coef;
+ g_socket_reuse_policy_penalty_coef =
+ policy == ClientSocketPoolBaseHelper::USE_WARMEST_SOCKET ? 0 :
willchan no longer on Chromium 2011/06/14 12:01:22 Chaining a ternary operator is not very readable.
Gagan 2011/06/14 18:25:02 Done.
+ (policy == ClientSocketPoolBaseHelper::USE_WARM_SOCKET ? 0.25 : -1);
+ DLOG(INFO) << "Setting g_socket_reuse_policy_penalty_coef = "
+ << g_socket_reuse_policy_penalty_coef;
+ // TODO(gagan): Remove this.
+ LOG(ERROR) << "Setting g_socket_reuse_policy_penalty_coef = "
+ << g_socket_reuse_policy_penalty_coef;
+ return old_value;
+}
+
ConnectJob::ConnectJob(const std::string& group_name,
base::TimeDelta timeout_duration,
Delegate* delegate,
@@ -363,7 +386,12 @@
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;
+ std::pair<int, int64> best_pair, current_pair;
+ std::string debug_log(request->handle()->group_name());
+ 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 +407,37 @@
if (it->socket->WasEverUsed()) {
// We found one we can reuse!
- idle_socket_it = it;
+ 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_coef >= 0) {
+ score = num_kb / pow(idle_time_sec,
+ g_socket_reuse_policy_penalty_coef);
+
+ debug_log = StringPrintf("%s\n%f\t%d\t%f", debug_log.data(),
+ num_kb, idle_time_sec, score);
+ }
+
+ // Equality to prefer recently used connection.
+ if (score >= max_score) {
+ idle_socket_it = it;
+ max_score = score;
+ best_pair = std::make_pair(bytes_read, idle_time_sec);
+ rtt_ms = it->socket->GetConnectTimeMicros();
+ }
}
++it;
}
+ debug_log = StringPrintf("%s\nChose socket <%d %ld>\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).

Powered by Google App Engine
This is Rietveld 408576698