ibessonov commented on a change in pull request #6814: IGNITE-12108 TCP 
Communication Metrics ported to a new framework.
URL: https://github.com/apache/ignite/pull/6814#discussion_r353627851
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationMetricsListener.java
 ##########
 @@ -17,74 +17,162 @@
 
 package org.apache.ignite.spi.communication.tcp;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 import java.util.UUID;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.LongAdder;
-
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
 import org.apache.ignite.internal.managers.communication.GridIoMessage;
-import org.apache.ignite.internal.util.nio.GridNioMetricsListener;
-import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.processors.metric.GridMetricManager;
+import org.apache.ignite.internal.processors.metric.MetricRegistry;
+import org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric;
+import org.apache.ignite.internal.processors.metric.impl.MetricUtils;
 import org.apache.ignite.plugin.extensions.communication.Message;
 
+import static 
org.apache.ignite.internal.util.nio.GridNioServer.RECEIVED_BYTES_METRIC_DESC;
+import static 
org.apache.ignite.internal.util.nio.GridNioServer.RECEIVED_BYTES_METRIC_NAME;
+import static 
org.apache.ignite.internal.util.nio.GridNioServer.SENT_BYTES_METRIC_DESC;
+import static 
org.apache.ignite.internal.util.nio.GridNioServer.SENT_BYTES_METRIC_NAME;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.COMMUNICATION_METRICS_GROUP_NAME;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_NODE_ID_METRIC_DESC;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_NODE_ID_METRIC_NAME;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_TYPE_METRIC_DESC;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_METRIC_DESC;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_METRIC_NAME;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_NODE_ID_METRIC_DESC;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_NODE_ID_METRIC_NAME;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_TYPE_METRIC_DESC;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_METRIC_DESC;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_METRIC_NAME;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.receivedMessagesByTypeMetricName;
+import static 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.sentMessagesByTypeMetricName;
+
 /**
  * Statistics for {@link 
org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi}.
  */
-public class TcpCommunicationMetricsListener implements GridNioMetricsListener{
-    /** Counter factory. */
-    private static final Callable<LongHolder> HOLDER_FACTORY = new 
Callable<LongHolder>() {
-        @Override public LongHolder call() {
-            return new LongHolder();
-        }
-    };
+class TcpCommunicationMetricsListener {
+    /** Metrics manager. */
+    private final GridMetricManager mmgr;
 
-    /** Received bytes count. */
-    private final LongAdder rcvdBytesCnt = new LongAdder();
+    /** Metrics registry. */
+    private final MetricRegistry mreg;
 
-    /** Sent bytes count.*/
-    private final LongAdder sentBytesCnt = new LongAdder();
+    /** */
+    private final Function<Short, AtomicLongMetric> 
sentMsgsCntByTypeMetricFactory;
 
-    /** All registered metrics. */
-    private final Set<ThreadMetrics> allMetrics = 
Collections.newSetFromMap(new ConcurrentHashMap<>());
+    /** */
+    private final Function<Short, AtomicLongMetric> 
rcvdMsgsCntByTypeMetricFactory;
 
-    /** Thread-local metrics. */
-    private final ThreadLocal<ThreadMetrics> threadMetrics = new 
ThreadLocal<ThreadMetrics>() {
-        @Override protected ThreadMetrics initialValue() {
-            ThreadMetrics metrics = new ThreadMetrics();
+    /** */
+    private final Function<Object, AtomicLongMetric> 
sentMsgsCntByConsistentIdMetricFactory;
 
-            allMetrics.add(metrics);
+    /** */
+    private final Function<Object, AtomicLongMetric> 
rcvdMsgsCntByConsistentIdMetricFactory;
 
-            return metrics;
-        }
-    };
+    /** Sent bytes count metric.*/
+    private final AtomicLongMetric sentBytesMetric;
+
+    /** Received bytes count metric. */
+    private final AtomicLongMetric rcvdBytesMetric;
+
+    /** Sent messages count metric. */
+    private final AtomicLongMetric sentMsgsMetric;
+
+    /** Received messages count metric. */
+    private final AtomicLongMetric rcvdMsgsMetric;
+
+    /** Sent messages count metrics grouped by message type. */
+    ConcurrentHashMap<Short, AtomicLongMetric> sentMsgsMetricsByType = new 
ConcurrentHashMap<>();
+
+    /** Received messages count metrics grouped by message type. */
+    ConcurrentHashMap<Short, AtomicLongMetric> rcvdMsgsMetricsByType = new 
ConcurrentHashMap<>();
+
+    /**
+     * Sent messages count metrics grouped by message node id.
+     * @deprecated for JMX support only.
+     */
+    @Deprecated
+    ConcurrentHashMap<UUID, AtomicLong> sentMsgsMetricsByNodeId = new 
ConcurrentHashMap<>();
+
+    /**
+     * Received messages metrics count grouped by message node id.
+     * @deprecated for JMX support only.
+     */
+    @Deprecated
+    ConcurrentHashMap<UUID, AtomicLong> rcvdMsgsMetricsByNodeId = new 
ConcurrentHashMap<>();
+
+    /** Sent messages count metrics grouped by message node consistent id. */
+    ConcurrentHashMap<Object, AtomicLongMetric> sentMsgsMetricsByConsistentId 
= new ConcurrentHashMap<>();
 
 Review comment:
   I changed that because in old implementation we stored basically the same 
map in each thread separately. That's the obvious answer.
   
   The other thing is that old implementation had concurrency issues that no 
one cared about. Like broken values visibility щк potential 
ConcurrentModificationExceptions. I wanted new implementation to be correct.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to