Skip to content

Commit

Permalink
net: Add some metrics on reuse of idle sockets.
Browse files Browse the repository at this point in the history
We're investigating keeping fewer of them around, and/or timing them out
more aggressively to decrease memory usage.

BUG=621197

Review-Url: https://codereview.chromium.org/2086903003
Cr-Commit-Position: refs/heads/master@{#401370}
  • Loading branch information
mmenke authored and Commit bot committed Jun 22, 2016
1 parent e503ca8 commit a9d6c7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion net/socket/client_socket_pool_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/format_macros.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
Expand Down Expand Up @@ -975,11 +976,21 @@ void ClientSocketPoolBaseHelper::HandOutSocket(
handle->set_pool_id(pool_generation_number_);
handle->set_connect_timing(connect_timing);

if (handle->is_reused()) {
if (reuse_type == ClientSocketHandle::REUSED_IDLE) {
net_log.AddEvent(
NetLog::TYPE_SOCKET_POOL_REUSED_AN_EXISTING_SOCKET,
NetLog::IntCallback("idle_ms",
static_cast<int>(idle_time.InMilliseconds())));

UMA_HISTOGRAM_COUNTS_1000("Net.Socket.IdleSocketReuseTime",
idle_time.InSeconds());
}

if (reuse_type != ClientSocketHandle::UNUSED) {
// The socket being handed out is no longer considered idle, but was
// considered idle until just before this method was called.
UMA_HISTOGRAM_CUSTOM_COUNTS("Net.Socket.NumIdleSockets",
idle_socket_count() + 1, 1, 256, 50);
}

net_log.AddEvent(
Expand Down
13 changes: 13 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30087,6 +30087,19 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>

<histogram name="Net.Socket.IdleSocketReuseTime" units="seconds">
<owner>mmenke@chromium.org</owner>
<summary>
Seconds a socket was idle before it was reused. Emitted upon reuse. Does not
record the times sockets were idle before first use.
</summary>
</histogram>

<histogram name="Net.Socket.NumIdleSockets">
<owner>mmenke@chromium.org</owner>
<summary>Number of idle sockets when one of them was reused.</summary>
</histogram>

<histogram name="Net.SocketIdleTimeBeforeNextUse_ReusedSocket">
<obsolete>
Deprecated as of 03/2015.
Expand Down

0 comments on commit a9d6c7d

Please sign in to comment.