ignite-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [ignite] nizhikov commented on a change in pull request #6814: IGNITE-12108 TCP Communication Metrics ported to a new framework.
Date Wed, 11 Sep 2019 14:02:07 GMT
nizhikov 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_r323259006
 
 

 ##########
 File path: modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationMetricsListener.java
 ##########
 @@ -17,65 +17,125 @@
 
 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.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.LongAdderMetric;
 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, LongAdderMetric> sentMsgsCntByTypeMetricFactory;
 
-    /** All registered metrics. */
-    private final Set<ThreadMetrics> allMetrics = Collections.newSetFromMap(new ConcurrentHashMap<>());
+    /** */
+    private final Function<Short, LongAdderMetric> rcvdMsgsCntByTypeMetricFactory;
 
-    /** Thread-local metrics. */
-    private final ThreadLocal<ThreadMetrics> threadMetrics = new ThreadLocal<ThreadMetrics>()
{
-        @Override protected ThreadMetrics initialValue() {
-            ThreadMetrics metrics = new ThreadMetrics();
+    /** */
+    private final Function<UUID, LongAdderMetric> sentMsgsCntByNodeIdMetricFactory;
 
-            allMetrics.add(metrics);
+    /** */
+    private final Function<UUID, LongAdderMetric> rcvdMsgsCntByNodeIdMetricFactory;
 
-            return metrics;
-        }
-    };
+    /** Sent bytes count metric.*/
+    private final LongAdderMetric sentBytesMetric;
+
+    /** Received bytes count metric. */
+    private final LongAdderMetric rcvdBytesMetric;
+
+    /** Sent messages count metric. */
+    private final LongAdderMetric sentMsgsMetric;
+
+    /** Received messages count metric. */
+    private final LongAdderMetric rcvdMsgsMetric;
+
+    /** Sent messages count metrics grouped by message type. */
+    ConcurrentHashMap<Short, LongAdderMetric> sentMsgsMetricsByType = new ConcurrentHashMap<>();
+
+    /** Received messages count metrics grouped by message type. */
+    ConcurrentHashMap<Short, LongAdderMetric> rcvdMsgsMetricsByType = new ConcurrentHashMap<>();
+
+    /** Sent messages count metrics grouped by message node id. */
+    ConcurrentHashMap<UUID, LongAdderMetric> sentMsgsMetricsByNodeId = new ConcurrentHashMap<>();
+
+    /** Received messages metrics count grouped by message node id. */
+    ConcurrentHashMap<UUID, LongAdderMetric> rcvdMsgsMetricsByNodeId = new ConcurrentHashMap<>();
 
     /** Method to synchronize access to message type map. */
     private final Object msgTypMapMux = new Object();
 
     /** Message type map. */
     private volatile Map<Short, String> msgTypMap;
 
-    /** {@inheritDoc} */
-    @Override public void onBytesSent(int bytesCnt) {
-        sentBytesCnt.add(bytesCnt);
+
+    /** */
+    public TcpCommunicationMetricsListener(GridMetricManager mmgr) {
+        this.mmgr = mmgr;
+
+        mreg = mmgr.registry(COMMUNICATION_METRICS_GROUP_NAME);
+
+        sentMsgsCntByTypeMetricFactory = directType -> mreg.longAdderMetric(
+            sentMessagesByTypeMetricName(directType),
+            SENT_MESSAGES_BY_TYPE_METRIC_DESC
+        );
+        rcvdMsgsCntByTypeMetricFactory = directType -> mreg.longAdderMetric(
+            receivedMessagesByTypeMetricName(directType),
+            RECEIVED_MESSAGES_BY_TYPE_METRIC_DESC
+        );
+
+        sentMsgsCntByNodeIdMetricFactory = nodeId -> mmgr.registry(COMMUNICATION_METRICS_GROUP_NAME
+ "." + nodeId)
 
 Review comment:
   Let's use `MetricUtils#metricName` instead of `COMMUNICATION_METRICS_GROUP_NAME + "." +
nodeId`

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message