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/02/12 04:13:21 UTC
[iotdb] branch master updated: [IOTDB-5491] Add IoTConsumus memory control metric items (#9022)
This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new bca08f0f26 [IOTDB-5491] Add IoTConsumus memory control metric items (#9022)
bca08f0f26 is described below
commit bca08f0f26651ae59ceb280674e2f8e0f49506f6
Author: Xiangpeng Hu <65...@users.noreply.github.com>
AuthorDate: Sat Feb 11 20:13:15 2023 -0800
[IOTDB-5491] Add IoTConsumus memory control metric items (#9022)
---
.../logdispatcher/IoTConsensusMemoryManager.java | 24 +++++++++++++++++++++-
.../IoTConsensusMemoryManagerMetrics.java | 18 ++++++++++++++++
.../consensus/iot/logdispatcher/LogDispatcher.java | 10 ++++-----
.../consensus/iot/logdispatcher/SyncStatus.java | 4 ++--
docs/UserGuide/Monitor-Alert/Metric-Tool.md | 2 ++
docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md | 2 ++
6 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManager.java b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManager.java
index dde4753b2a..f8c2b8e696 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManager.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManager.java
@@ -30,6 +30,8 @@ import java.util.concurrent.atomic.AtomicLong;
public class IoTConsensusMemoryManager {
private static final Logger logger = LoggerFactory.getLogger(IoTConsensusMemoryManager.class);
private final AtomicLong memorySizeInByte = new AtomicLong(0);
+ private final AtomicLong queueMemorySizeInByte = new AtomicLong(0);
+ private final AtomicLong syncMemorySizeInByte = new AtomicLong(0);
private Long maxMemorySizeInByte = Runtime.getRuntime().maxMemory() / 10;
private Long maxMemorySizeForQueueInByte = Runtime.getRuntime().maxMemory() / 100 * 6;
@@ -61,11 +63,23 @@ public class IoTConsensusMemoryManager {
return memorySize + size;
}
});
+ if (result.get()) {
+ if (fromQueue) {
+ queueMemorySizeInByte.addAndGet(size);
+ } else {
+ syncMemorySizeInByte.addAndGet(size);
+ }
+ }
return result.get();
}
- public void free(long size) {
+ public void free(long size, boolean fromQueue) {
long currentUsedMemory = memorySizeInByte.addAndGet(-size);
+ if (fromQueue) {
+ queueMemorySizeInByte.addAndGet(-size);
+ } else {
+ syncMemorySizeInByte.addAndGet(-size);
+ }
logger.debug(
"{} free {} bytes, total memory size: {} bytes.",
Thread.currentThread().getName(),
@@ -82,6 +96,14 @@ public class IoTConsensusMemoryManager {
return memorySizeInByte.get();
}
+ long getQueueMemorySizeInByte() {
+ return queueMemorySizeInByte.get();
+ }
+
+ long getSyncMemorySizeInByte() {
+ return syncMemorySizeInByte.get();
+ }
+
private static final IoTConsensusMemoryManager INSTANCE = new IoTConsensusMemoryManager();
public static IoTConsensusMemoryManager getInstance() {
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManagerMetrics.java b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManagerMetrics.java
index e5cccdae42..28945c4350 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManagerMetrics.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/IoTConsensusMemoryManagerMetrics.java
@@ -42,11 +42,29 @@ public class IoTConsensusMemoryManagerMetrics implements IMetricSet {
IoTConsensusMemoryManager::getMemorySizeInByte,
Tag.NAME.toString(),
"IoTConsensus");
+ metricService.createAutoGauge(
+ Metric.MEM.toString(),
+ MetricLevel.IMPORTANT,
+ iotConsensusMemoryManager,
+ IoTConsensusMemoryManager::getQueueMemorySizeInByte,
+ Tag.NAME.toString(),
+ "IoTConsensusQueue");
+ metricService.createAutoGauge(
+ Metric.MEM.toString(),
+ MetricLevel.IMPORTANT,
+ iotConsensusMemoryManager,
+ IoTConsensusMemoryManager::getSyncMemorySizeInByte,
+ Tag.NAME.toString(),
+ "IoTConsensusSync");
}
@Override
public void unbindFrom(AbstractMetricService metricService) {
metricService.remove(
MetricType.AUTO_GAUGE, Metric.MEM.toString(), Tag.NAME.toString(), "IoTConsensus");
+ metricService.remove(
+ MetricType.AUTO_GAUGE, Metric.MEM.toString(), Tag.NAME.toString(), "IoTConsensusQueue");
+ metricService.remove(
+ MetricType.AUTO_GAUGE, Metric.MEM.toString(), Tag.NAME.toString(), "IoTConsensusSync");
}
}
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java
index cfc480a8cb..4bd1e5a129 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/LogDispatcher.java
@@ -256,19 +256,19 @@ public class LogDispatcher {
success = pendingEntries.offer(indexedConsensusRequest);
} catch (Throwable t) {
// If exception occurs during request offer, the reserved memory should be released
- iotConsensusMemoryManager.free(indexedConsensusRequest.getSerializedSize());
+ iotConsensusMemoryManager.free(indexedConsensusRequest.getSerializedSize(), true);
throw t;
}
if (!success) {
// If offer failed, the reserved memory should be released
- iotConsensusMemoryManager.free(indexedConsensusRequest.getSerializedSize());
+ iotConsensusMemoryManager.free(indexedConsensusRequest.getSerializedSize(), true);
}
return success;
}
/** try to remove a request from queue with memory control. */
private void releaseReservedMemory(IndexedConsensusRequest indexedConsensusRequest) {
- iotConsensusMemoryManager.free(indexedConsensusRequest.getSerializedSize());
+ iotConsensusMemoryManager.free(indexedConsensusRequest.getSerializedSize(), true);
}
public void stop() {
@@ -278,12 +278,12 @@ public class LogDispatcher {
requestSize += indexedConsensusRequest.getSerializedSize();
}
pendingEntries.clear();
- iotConsensusMemoryManager.free(requestSize);
+ iotConsensusMemoryManager.free(requestSize, true);
requestSize = 0;
for (IndexedConsensusRequest indexedConsensusRequest : bufferedEntries) {
requestSize += indexedConsensusRequest.getSerializedSize();
}
- iotConsensusMemoryManager.free(requestSize);
+ iotConsensusMemoryManager.free(requestSize, true);
syncStatus.free();
MetricService.getInstance().removeMetricSet(metrics);
}
diff --git a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java
index 3f0c1477d0..4c3c008783 100644
--- a/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java
+++ b/consensus/src/main/java/org/apache/iotdb/consensus/iot/logdispatcher/SyncStatus.java
@@ -64,7 +64,7 @@ public class SyncStatus {
while (current.isSynced()) {
controller.updateAndGet(current.getEndIndex());
iterator.remove();
- iotConsensusMemoryManager.free(current.getSerializedSize());
+ iotConsensusMemoryManager.free(current.getSerializedSize(), false);
if (iterator.hasNext()) {
current = iterator.next();
} else {
@@ -83,7 +83,7 @@ public class SyncStatus {
size += pendingBatch.getSerializedSize();
}
pendingBatches.clear();
- iotConsensusMemoryManager.free(size);
+ iotConsensusMemoryManager.free(size, false);
}
/** Gets the first index that is not currently synchronized. */
diff --git a/docs/UserGuide/Monitor-Alert/Metric-Tool.md b/docs/UserGuide/Monitor-Alert/Metric-Tool.md
index f800f84e08..dfc68deb52 100644
--- a/docs/UserGuide/Monitor-Alert/Metric-Tool.md
+++ b/docs/UserGuide/Monitor-Alert/Metric-Tool.md
@@ -218,6 +218,8 @@ carefully evaluated. The current Core-level metrics are as follows:
| mem | name="database_{{name}}" | AutoGauge | The memory usage of DataRegion in DataNode, Unit: byte |
| mem | name="chunkMetaData_{{name}}" | AutoGauge | The memory usage of chunkMetaData when writting TsFile, Unit: byte |
| mem | name="IoTConsensus" | AutoGauge | The memory usage of IoTConsensus, Unit: byte |
+| mem | name="IoTConsensusQueue" | AutoGauge | The memory usage of IoTConsensus Queue, Unit: byte |
+| mem | name="IoTConsensusSync" | AutoGauge | The memory usage of IoTConsensus SyncStatus, Unit: byte |
| mem | name="schema_region_total_usage" | AutoGauge | The memory usage of all SchemaRegion, Unit: byte |
| mem | name="schema_region_total_remaining" | AutoGauge | The memory remaining for all SchemaRegion, Unit: byte |
diff --git a/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md b/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md
index 03190d0d7f..0c131a9af7 100644
--- a/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md
+++ b/docs/zh/UserGuide/Monitor-Alert/Metric-Tool.md
@@ -198,6 +198,8 @@ Core 级别的监控指标在系统运行中默认开启,每一个 Core 级别
| mem | name="database_{{name}}" | AutoGauge | DataNode内对应DataRegion的内存占用,单位为byte |
| mem | name="chunkMetaData_{{name}}" | AutoGauge | 写入TsFile时的ChunkMetaData的内存占用,单位为byte |
| mem | name="IoTConsensus" | AutoGauge | IoT共识协议的内存占用,单位为byte |
+| mem | name="IoTConsensusQueue" | AutoGauge | IoT共识协议用于队列的内存占用,单位为byte |
+| mem | name="IoTConsensusSync" | AutoGauge | IoT共识协议用于同步的内存占用,单位为byte |
| mem | name="schema_region_total_usage" | AutoGauge | 所有SchemaRegion的总内存占用,单位为byte |
| mem | name="schema_region_total_remaining" | AutoGauge | 所有SchemaRegion的总内存剩余,单位为byte |