This is an automated email from the ASF dual-hosted git repository.
tkalkirill pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 2f613916bc2 IGNITE-26131 Fix avgWriteSpeed logging at checkpoint
finish (#6369)
2f613916bc2 is described below
commit 2f613916bc2a026bb5efa37f2e8e175b63e40fb7
Author: Kirill Tkalenko <[email protected]>
AuthorDate: Wed Aug 6 13:57:58 2025 +0300
IGNITE-26131 Fix avgWriteSpeed logging at checkpoint finish (#6369)
---
.../persistence/WriteSpeedFormatter.java | 61 +++++-----------
.../persistence/checkpoint/Checkpointer.java | 6 +-
.../persistence/compaction/Compactor.java | 7 +-
.../persistence/WriteSpeedFormatterTest.java | 82 ++++++++++++++++++++++
4 files changed, 106 insertions(+), 50 deletions(-)
diff --git
a/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatter.java
b/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatter.java
index cd85d56ec5d..a76e1b33aa8 100644
---
a/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatter.java
+++
b/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatter.java
@@ -17,60 +17,33 @@
package org.apache.ignite.internal.pagememory.persistence;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
+import java.util.Locale;
import org.apache.ignite.internal.util.Constants;
-/**
- * Util class that encapsulates write speed formatting. Ported from {@code
Ignite 2.x}.
- */
+/** Util class that encapsulates write speed formatting. */
public class WriteSpeedFormatter {
- private static final DecimalFormatSymbols SEPARATOR = new
DecimalFormatSymbols();
-
- static {
- SEPARATOR.setDecimalSeparator('.');
- }
-
- /** Format for speed > 10 MB/sec. */
- private static final DecimalFormat HIGH_SPEED_FORMAT = new
DecimalFormat("#", SEPARATOR);
-
- /** Format for speed in range 1-10 MB/sec. */
- private static final DecimalFormat MEDIUM_SPEED_FORMAT = new
DecimalFormat("#.##", SEPARATOR);
-
- /**
- * Format for speed < 1 MB/sec For cases when user deployed Grid to
inappropriate HW, e.g. AWS EFS, where throughput is elastic and can
- * degrade to near-zero values.
- */
- private static final DecimalFormat LOW_SPEED_FORMAT = new
DecimalFormat("#.####", SEPARATOR);
-
- /** Constructor. */
- private WriteSpeedFormatter() {
- // no-op
- }
-
/**
- * Format write speed in MB/sec.
+ * Formats write speed in MB/sec.
*
- * @param avgWriteSpeedInBytes Write speed in bytes.
+ * @param bytes Total number of bytes.
+ * @param durationInNanos Duration in nanoseconds.
* @return Formatted write speed.
*/
- public static String formatWriteSpeed(float avgWriteSpeedInBytes) {
- float speedInMbs = avgWriteSpeedInBytes / Constants.MiB;
-
- if (speedInMbs >= 10.0) {
- synchronized (HIGH_SPEED_FORMAT) {
- return HIGH_SPEED_FORMAT.format(speedInMbs);
- }
+ public static String formatWriteSpeed(long bytes, long durationInNanos) {
+ if (bytes == 0 || durationInNanos == 0) {
+ return "0";
}
- if (speedInMbs >= 0.1) {
- synchronized (MEDIUM_SPEED_FORMAT) {
- return MEDIUM_SPEED_FORMAT.format(speedInMbs);
- }
- }
+ double durationInSeconds = durationInNanos / 1_000_000_000.0;
+ double speedInBs = bytes / durationInSeconds;
+ double speedInMbs = speedInBs / Constants.MiB;
- synchronized (LOW_SPEED_FORMAT) {
- return LOW_SPEED_FORMAT.format(speedInMbs);
+ if (speedInMbs >= 10.0) {
+ return String.format(Locale.US, "%.0f", speedInMbs);
+ } else if (speedInMbs >= 0.1) {
+ return String.format(Locale.US, "%.2f", speedInMbs);
}
+
+ return String.format(Locale.US, "%.4f", speedInMbs);
}
}
diff --git
a/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java
b/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java
index d07308cc7d4..c9d17551819 100644
---
a/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java
+++
b/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/Checkpointer.java
@@ -407,8 +407,8 @@ public class Checkpointer extends IgniteWorker {
if (chp.hasDelta()) {
if (log.isInfoEnabled()) {
- float totalDurationInSeconds =
tracker.checkpointDuration(MILLISECONDS) / 1000.0f;
- float avgWriteSpeedInBytes = ((long) pageSize *
chp.dirtyPagesSize) / totalDurationInSeconds;
+ long totalWriteBytes = (long) pageSize *
chp.dirtyPagesSize;
+ long totalDurationInNanos =
tracker.checkpointDuration(NANOSECONDS);
log.info(
CHECKPOINT_FINISHED_LOG_TEMPLATE,
@@ -419,7 +419,7 @@ public class Checkpointer extends IgniteWorker {
tracker.replicatorLogSyncDuration(MILLISECONDS),
tracker.waitPageReplacementDuration(MILLISECONDS),
tracker.checkpointDuration(MILLISECONDS),
-
WriteSpeedFormatter.formatWriteSpeed(avgWriteSpeedInBytes)
+
WriteSpeedFormatter.formatWriteSpeed(totalWriteBytes, totalDurationInNanos)
);
}
}
diff --git
a/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/compaction/Compactor.java
b/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/compaction/Compactor.java
index c0b2adc758a..e708f55bad6 100644
---
a/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/compaction/Compactor.java
+++
b/modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/compaction/Compactor.java
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.pagememory.persistence.compaction;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.stream.Collectors.toCollection;
import static
org.apache.ignite.internal.failure.FailureType.SYSTEM_WORKER_TERMINATION;
@@ -287,15 +288,15 @@ public class Compactor extends IgniteWorker {
tracker.onCompactionEnd();
if (LOG.isInfoEnabled()) {
- float totalDurationInSeconds =
tracker.totalDuration(MILLISECONDS) / 1000.0f;
- float avgWriteSpeedInBytes = ((long) pageSize *
tracker.dataPagesWritten()) / totalDurationInSeconds;
+ long totalWriteBytes = (long) pageSize *
tracker.dataPagesWritten();
+ long totalDurationInNanos = tracker.totalDuration(NANOSECONDS);
LOG.info(
"Compaction round finished [compactionId={}, pages={},
duration={}ms, avgWriteSpeed={}MB/s]",
compactionId,
tracker.dataPagesWritten(),
tracker.totalDuration(MILLISECONDS),
-
WriteSpeedFormatter.formatWriteSpeed(avgWriteSpeedInBytes)
+ WriteSpeedFormatter.formatWriteSpeed(totalWriteBytes,
totalDurationInNanos)
);
}
}
diff --git
a/modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatterTest.java
b/modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatterTest.java
new file mode 100644
index 00000000000..d3d296ed13b
--- /dev/null
+++
b/modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/WriteSpeedFormatterTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.pagememory.persistence;
+
+import static
org.apache.ignite.internal.pagememory.persistence.WriteSpeedFormatter.formatWriteSpeed;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.util.Constants;
+import org.junit.jupiter.api.Test;
+
+/** For {@link WriteSpeedFormatter} testing. */
+public class WriteSpeedFormatterTest {
+ @Test
+ void testZeroDuration() {
+ assertEquals("0", formatWriteSpeed(1, 0));
+ }
+
+ @Test
+ void testZeroBytes() {
+ assertEquals("0", formatWriteSpeed(0, 1));
+ }
+
+ @Test
+ void testZeroBytesAndDuration() {
+ assertEquals("0", formatWriteSpeed(0, 0));
+ }
+
+ @Test
+ void testHighSpeed() {
+ long bytes = 2L * Constants.GiB;
+ long secInNanos = TimeUnit.SECONDS.toNanos(1);
+
+ assertEquals("2048", formatWriteSpeed(bytes, secInNanos));
+ assertEquals("1024", formatWriteSpeed(bytes, secInNanos * 2));
+ assertEquals("4096", formatWriteSpeed(bytes, secInNanos / 2));
+
+ assertEquals("205", formatWriteSpeed(bytes, secInNanos * 10));
+ assertEquals("20480", formatWriteSpeed(bytes, secInNanos / 10));
+ }
+
+ @Test
+ void testMediumSpeed() {
+ long bytes = 2L * Constants.MiB;
+ long secInNanos = TimeUnit.SECONDS.toNanos(1);
+
+ assertEquals("2.00", formatWriteSpeed(bytes, secInNanos));
+ assertEquals("1.00", formatWriteSpeed(bytes, secInNanos * 2));
+ assertEquals("4.00", formatWriteSpeed(bytes, secInNanos / 2));
+
+ assertEquals("0.20", formatWriteSpeed(bytes, secInNanos * 10));
+ assertEquals("8.00", formatWriteSpeed(bytes, secInNanos / 4));
+ }
+
+ @Test
+ void testLowSpeed() {
+ long bytes = 2L * Constants.KiB;
+ long secInNanos = TimeUnit.SECONDS.toNanos(1);
+
+ assertEquals("0.0020", formatWriteSpeed(bytes, secInNanos));
+ assertEquals("0.0010", formatWriteSpeed(bytes, secInNanos * 2));
+ assertEquals("0.0039", formatWriteSpeed(bytes, secInNanos / 2));
+
+ assertEquals("0.0002", formatWriteSpeed(bytes, secInNanos * 10));
+ assertEquals("0.0078", formatWriteSpeed(bytes, secInNanos / 4));
+ }
+}