From de0e1f5e2f5cc737e643a29719b7df8582c62619 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Thu, 3 Dec 2015 14:31:41 -0500 Subject: [PATCH] Avoid trace logging allocations in TransportBroadcastByNodeAction This commit wraps the trace logging statements in TransportBroadcastByNodeAction in trace enabled checks to avoid unnecessarily allocating objects. The most egregious offenders were the two trace logging statements in BroadcastByNodeTransportRequestHandler#onShardOperation. Aside from the usual object allocations that occur when invoking ESLogger#trace (the allocated object array for the varargs Object... parameter), these two logging statements were invoking ShardRouting#shortSummary generating a bunch of char arrays and Strings (from the StringBuilder, and so a bunch of array copies as well). In a scenario where there are a lot of shards and this method is being invoked frequently (e.g., constantly hitting the _stats endpoint), these two unprotected trace logging statements were generating a lot of unnecessary allocations. --- .../node/TransportBroadcastByNodeAction.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java b/core/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java index bc78f13433f..8bcba8ad544 100644 --- a/core/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/broadcast/node/TransportBroadcastByNodeAction.java @@ -223,7 +223,9 @@ public abstract class TransportBroadcastByNodeAction(); @@ -300,7 +302,9 @@ public abstract class TransportBroadcastByNodeAction shards = request.getShards(); final int totalShards = shards.size(); - logger.trace("[{}] executing operation on [{}] shards", actionName, totalShards); + if (logger.isTraceEnabled()) { + logger.trace("[{}] executing operation on [{}] shards", actionName, totalShards); + } final Object[] shardResultOrExceptions = new Object[totalShards]; int shardIndex = -1; @@ -375,10 +381,14 @@ public abstract class TransportBroadcastByNodeAction