You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2023/08/02 04:17:14 UTC

[iotdb] 01/02: Add concurrent_write_iot_regions_num metric

This is an automated email from the ASF dual-hosted git repository.

tanxinyu pushed a commit to branch ca_performance
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit f3dbca70834190e50d616e8556e71ca916c8a87c
Author: OneSizeFitQuorum <ta...@apache.org>
AuthorDate: Wed Aug 2 12:15:09 2023 +0800

    Add concurrent_write_iot_regions_num metric
    
    Signed-off-by: OneSizeFitQuorum <ta...@apache.org>
---
 .../java/org/apache/iotdb/consensus/iot/IoTConsensus.java |  2 --
 .../iotdb/consensus/iot/IoTConsensusServerImpl.java       |  5 +++--
 .../service/metric/PerformanceOverviewMetrics.java        | 15 ++++++++++++++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
index 047d557ad55..105fecfbd9a 100644
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
+++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensus.java
@@ -67,9 +67,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 public class IoTConsensus implements IConsensus {
-
   private final Logger logger = LoggerFactory.getLogger(IoTConsensus.class);
-
   private final TEndPoint thisNode;
   private final int thisNodeId;
   private final File storageDir;
diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
index 0b76a690dba..a0ddb9cc406 100644
--- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
+++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/iot/IoTConsensusServerImpl.java
@@ -88,7 +88,6 @@ import java.util.concurrent.locks.ReentrantLock;
 import java.util.regex.Pattern;
 
 public class IoTConsensusServerImpl {
-
   private static final String CONFIGURATION_FILE_NAME = "configuration.dat";
   private static final String CONFIGURATION_TMP_FILE_NAME = "configuration.dat.tmp";
   public static final String SNAPSHOT_DIR_NAME = "snapshot";
@@ -168,8 +167,9 @@ public class IoTConsensusServerImpl {
    */
   public TSStatus write(IConsensusRequest request) {
     long consensusWriteStartTime = System.nanoTime();
-    stateMachineLock.lock();
     try {
+      stateMachineLock.lock();
+      PERFORMANCE_OVERVIEW_METRICS.CONCURRENT_WRITE_IOT_REGIONS_COUNTER.increment();
       long getStateMachineLockTime = System.nanoTime();
       // statistic the time of acquiring stateMachine lock
       ioTConsensusServerMetrics.recordGetStateMachineLockTime(
@@ -245,6 +245,7 @@ public class IoTConsensusServerImpl {
           System.nanoTime() - consensusWriteStartTime);
       return result;
     } finally {
+      PERFORMANCE_OVERVIEW_METRICS.CONCURRENT_WRITE_IOT_REGIONS_COUNTER.decrement();
       stateMachineLock.unlock();
     }
   }
diff --git a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/PerformanceOverviewMetrics.java b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/PerformanceOverviewMetrics.java
index 1efbe626335..905b5375d58 100644
--- a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/PerformanceOverviewMetrics.java
+++ b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/service/metric/PerformanceOverviewMetrics.java
@@ -31,8 +31,10 @@ import org.apache.iotdb.metrics.utils.MetricType;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.atomic.LongAdder;
 
 public class PerformanceOverviewMetrics implements IMetricSet {
+
   private static final Map<String, MetricInfo> metricInfoMap = new HashMap<>();
 
   private PerformanceOverviewMetrics() {
@@ -194,16 +196,22 @@ public class PerformanceOverviewMetrics implements IMetricSet {
   private static final String PERFORMANCE_OVERVIEW_STORAGE_DETAIL =
       Metric.PERFORMANCE_OVERVIEW_STORAGE_DETAIL.toString();
   private static final String ENGINE = "engine";
+  private static final String CONCURRENT_WRITE_IOT_REGIONS_NUM = "concurrent_write_iot_regions_num";
 
   static {
     metricInfoMap.put(
         ENGINE,
         new MetricInfo(
             MetricType.TIMER, PERFORMANCE_OVERVIEW_STORAGE_DETAIL, Tag.STAGE.toString(), ENGINE));
+    metricInfoMap.put(
+        CONCURRENT_WRITE_IOT_REGIONS_NUM,
+        new MetricInfo(MetricType.AUTO_GAUGE, CONCURRENT_WRITE_IOT_REGIONS_NUM));
   }
 
   private Timer engineTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
 
+  public final LongAdder CONCURRENT_WRITE_IOT_REGIONS_COUNTER = new LongAdder();
+
   public void recordEngineCost(long costTimeInNanos) {
     engineTimer.updateNanos(costTimeInNanos);
   }
@@ -347,7 +355,12 @@ public class PerformanceOverviewMetrics implements IMetricSet {
             MetricLevel.CORE,
             Tag.STAGE.toString(),
             PerformanceOverviewMetrics.ENGINE);
-    // bind storageengine metrics
+    metricService.createAutoGauge(
+        CONCURRENT_WRITE_IOT_REGIONS_NUM,
+        MetricLevel.CORE,
+        this.CONCURRENT_WRITE_IOT_REGIONS_COUNTER,
+        LongAdder::doubleValue);
+    // bind storage engine metrics
     lockTimer =
         metricService.getOrCreateTimer(
             PERFORMANCE_OVERVIEW_ENGINE_DETAIL, MetricLevel.CORE, Tag.STAGE.toString(), LOCK);