From afe3210c8c1f9559c39674ce83771b900fe78ba7 Mon Sep 17 00:00:00 2001 From: syaojun Date: Fri, 6 Mar 2026 23:19:59 +0800 Subject: [PATCH] feat: define BYTES_PER_KB constant for consistent byte-to-kilobyte conversions in metrics classes --- .../java/org/apache/geaflow/common/metric/CycleMetrics.java | 6 ++++-- .../apache/geaflow/common/metric/ShuffleReadMetrics.java | 4 +++- .../apache/geaflow/common/metric/ShuffleWriteMetrics.java | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/CycleMetrics.java b/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/CycleMetrics.java index 25451a5fb..73a3a3493 100644 --- a/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/CycleMetrics.java +++ b/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/CycleMetrics.java @@ -23,6 +23,8 @@ public class CycleMetrics implements Serializable { + private static final int BYTES_PER_KB = 1024; + private String name; private String pipelineName; private String opName; @@ -172,9 +174,9 @@ public static CycleMetrics build(String metricName, cycleMetrics.setAvgGcTime(totalGcTime / taskNum); cycleMetrics.setSlowestTaskExecuteTime(slowestTaskExecuteTime); cycleMetrics.setInputRecords(totalInputRecords); - cycleMetrics.setInputKb(totalInputBytes / 1024); + cycleMetrics.setInputKb(totalInputBytes / BYTES_PER_KB); cycleMetrics.setOutputRecords(totalOutputRecords); - cycleMetrics.setOutputKb(totalOutputBytes / 1024); + cycleMetrics.setOutputKb(totalOutputBytes / BYTES_PER_KB); return cycleMetrics; } diff --git a/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleReadMetrics.java b/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleReadMetrics.java index c9b0fa56a..9b3059132 100644 --- a/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleReadMetrics.java +++ b/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleReadMetrics.java @@ -23,6 +23,8 @@ public class ShuffleReadMetrics implements Serializable { + private static final int BYTES_PER_KB = 1024; + private int fetchSlices; /** * total records of fetch response. @@ -123,7 +125,7 @@ public void incFetchWaitMs(long fetchWaitMs) { @Override public String toString() { - return "ReadMetrics{" + "fetchSlices=" + fetchSlices + ", fetchRecords=" + fetchRecords + ", decodeKB=" + decodeBytes / 1024 + ", fetchWaitMs=" + fetchWaitMs + return "ReadMetrics{" + "fetchSlices=" + fetchSlices + ", fetchRecords=" + fetchRecords + ", decodeKB=" + decodeBytes / BYTES_PER_KB + ", fetchWaitMs=" + fetchWaitMs + ", decodeMs=" + decodeMs + '}'; } } diff --git a/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleWriteMetrics.java b/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleWriteMetrics.java index 5cc37405c..ce0072ff7 100644 --- a/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleWriteMetrics.java +++ b/geaflow/geaflow-common/src/main/java/org/apache/geaflow/common/metric/ShuffleWriteMetrics.java @@ -23,6 +23,8 @@ public class ShuffleWriteMetrics implements Serializable { + private static final int BYTES_PER_KB = 1024; + /** * total output channels. */ @@ -216,7 +218,7 @@ public void updateMaxSpillKB(long spillKB) { @Override public String toString() { return "WriteMetrics{" + "outputRecords=" + writtenRecords + ", encodedKb=" - + encodedSize / 1024 + ", encodeMs=" + encodeMs + ", spillNum=" + spillNum + + encodedSize / BYTES_PER_KB + ", encodeMs=" + encodeMs + ", spillNum=" + spillNum + ", spillDisk=" + spillDisk + ", oomCnt=" + oomCount + ", spillMs=" + spillMs + ", maxSpillKB=" + maxSpillKB + ", " + "maxSliceKB=" + maxSliceKB + ", channels=" + numChannels + ", writtenChannels=" + writtenChannels + '}';