You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/06/03 12:58:20 UTC

[GitHub] [ignite] SammyVimes commented on a diff in pull request #9924: IGNITE-16582 Improve behavior of speed-based throttling when dirty pages ratio is low

SammyVimes commented on code in PR #9924:
URL: https://github.com/apache/ignite/pull/9924#discussion_r888909062


##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/IgniteThrottlingUnitTest.java:
##########
@@ -100,34 +100,51 @@ public class IgniteThrottlingUnitTest extends GridCommonAbstractTest {
      *
      */
     @Test
-    public void breakInCaseTooFast() {
+    public void shouldThrottleWhenWritingFasterThanTargetSpeedAndDirtyRatioIsAboveTargetRatio() {

Review Comment:
   it's a bit too hard to read without spacing. Maybe leave the old name and add a clarifying comment?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/SpeedBasedMemoryConsumptionThrottlingStrategy.java:
##########
@@ -367,11 +325,30 @@ private long calcSpeedToMarkAllSpaceTillEndOfCp(double dirtyPagesRatio, long don
         if (dirtyPagesRatio >= MAX_DIRTY_PAGES)
             return 0;
 
-        double remainedClearPages = (MAX_DIRTY_PAGES - dirtyPagesRatio) * totalPages;
+        // IDEA: here, when calculating the count of clean pages, it includes the pages under checkpoint. It is kinda
+        // legal because they can be written (using the Checkpoint Buffer to make a copy of the value to be
+        // checkpointed), but the CP Buffer is usually not too big, and if it gets nearly filled, writes become
+        // throttled really hard by exponential throttler. Maybe we should subtract the number of not-yet-written-by-CP
+        // pages from the count of clean pages? In such a case, we would lessen the risk of CP Buffer-caused throttling.
+        double remainedCleanPages = (MAX_DIRTY_PAGES - dirtyPagesRatio) * pageMemTotalPages();
+
+        double secondsTillCPEnd = 1.0 * (cpTotalPages - donePages) / avgCpWriteSpeed;
+
+        return (long)(remainedCleanPages / secondsTillCPEnd);
+    }
+
+    /** Returns total number of pages storable in page memory. */
+    private long pageMemTotalPages() {
+        long currentTotalPages = pageMemTotalPages;
+
+        if (currentTotalPages == 0) {

Review Comment:
   When is it 0 I wonder?



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/SpeedBasedThrottleIntegrationTest.java:
##########
@@ -0,0 +1,114 @@
+/*
+ * 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.processors.cache.persistence.pagemem;
+
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.persistence.db.SlowCheckpointMetadataFileIOFactory;
+import org.apache.ignite.testframework.ListeningTestLogger;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE;
+
+/**
+ * Integration tests for {@link PagesWriteSpeedBasedThrottle}.
+ */
+public class SpeedBasedThrottleIntegrationTest extends GridCommonAbstractTest {
+    /***/
+    private final ListeningTestLogger listeningLog = new ListeningTestLogger(log);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        DataStorageConfiguration dbCfg = new DataStorageConfiguration()
+            .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                // set small region size to make it easy achieve the necessity to throttle with speed-based throttle
+                .setMaxSize(60 * 1024 * 1024)
+                .setPersistenceEnabled(true)
+            )
+            .setCheckpointFrequency(200)
+            .setWriteThrottlingEnabled(true)
+            .setFileIOFactory(
+                new SlowCheckpointMetadataFileIOFactory(
+                    new AtomicBoolean(true), TimeUnit.MILLISECONDS.toNanos(10000)
+                )
+            );
+
+        return cfg.setDataStorageConfiguration(dbCfg)
+            .setConsistentId(gridName)
+            .setGridLogger(listeningLog);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        stopAllGrids();
+
+        super.beforeTest();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        super.afterTest();
+
+        cleanPersistenceDir();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long getTestTimeout() {
+        return 3 * 60 * 1000;

Review Comment:
   3 minutes for a test? Looks a bit odd



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/IgniteThrottlingUnitTest.java:
##########
@@ -100,34 +100,51 @@ public class IgniteThrottlingUnitTest extends GridCommonAbstractTest {
      *
      */
     @Test
-    public void breakInCaseTooFast() {
+    public void shouldThrottleWhenWritingFasterThanTargetSpeedAndDirtyRatioIsAboveTargetRatio() {
         PagesWriteSpeedBasedThrottle throttle = new PagesWriteSpeedBasedThrottle(pageMemory2g, null, stateChecker, log);
 
-        long time = throttle.getCleanPagesProtectionParkTime(0.67,
+        long parkTime = throttle.getCleanPagesProtectionParkTime(0.67,
             (362584 + 67064) / 2,
             328787,
             1,
             60184,
             23103);
 
-        assertTrue(time > 0);
+        assertTrue(parkTime > 0);
     }
 
     /**
      *
      */
     @Test
-    public void noBreakIfNotFastWrite() {
+    public void shouldNotThrottleWhenWritingSlowly() {
         PagesWriteSpeedBasedThrottle throttle = new PagesWriteSpeedBasedThrottle(pageMemory2g, null, stateChecker, log);
 
-        long time = throttle.getCleanPagesProtectionParkTime(0.47,
+        long parkTime = throttle.getCleanPagesProtectionParkTime(0.47,
             ((362584 + 67064) / 2),
             328787,
             1,
             20103,
             23103);
 
-        assertEquals(0, time);
+        assertEquals(0, parkTime);
+    }
+
+    /**
+     *
+     */
+    @Test
+    public void shouldNotThrottleWhenWritingFasterThanCPSpeedButThereAreManyCleanPages() {

Review Comment:
   Same about long name



##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagesWriteThrottleSandboxTest.java:
##########
@@ -142,25 +151,38 @@ public void testThrottle() throws Exception {
                             if (m.getName().equals("dfltDataRegion"))
                                 dirtyPages = m.getDirtyPages();
 
-                        long cpBufPages = 0;
+                        long cpBufPages;
 
                         long cpWrittenPages;
 
-                        AtomicInteger cntr = ((GridCacheDatabaseSharedManager)((ignite(0))
-                            .context().cache().context().database())).getCheckpointer().currentProgress().writtenPagesCounter();
+                        Checkpointer checkpointer = ((GridCacheDatabaseSharedManager)((ignite(0))
+                            .context().cache().context().database())).getCheckpointer();
+                        AtomicInteger cntr = checkpointer.currentProgress().writtenPagesCounter();
 
                         cpWrittenPages = cntr == null ? 0 : cntr.get();
 
                         try {
-                            cpBufPages = ((ignite(0)).context().cache().context().database()
-                                .dataRegion("dfltDataRegion").pageMemory()).checkpointBufferPagesCount();
+                            PageMemoryEx pageMemory = (PageMemoryEx)(ignite(0)).context().cache().context().database()
+                                .dataRegion("dfltDataRegion").pageMemory();
+                            cpBufPages = pageMemory.checkpointBufferPagesCount();
+
+                            if (System.nanoTime() - startNanos > TimeUnit.SECONDS.toNanos(10)) {
+                                double currentDirtyRatio = (double)dirtyPages / pageMemory.totalPages();
+                                double newMaxDirtyRatio = Math.max(maxDirtyRatio.get(), currentDirtyRatio);
+                                maxDirtyRatio.set(newMaxDirtyRatio);
+                            }
                         }
                         catch (IgniteCheckedException e) {
                             e.printStackTrace();
+                            throw new RuntimeException("Something went wrong", e);
                         }
 
-                        System.out.println("@@@ putsPerSec=," + (putRate.value()) + ", getsPerSec=," + (getRate.value()) + ", dirtyPages=,"
-                            + dirtyPages + ", cpWrittenPages=," + cpWrittenPages + ", cpBufPages=," + cpBufPages);
+                        System.out.println("@@@ globalPutsPerSec="

Review Comment:
   should be `log` instead of `System.out` probably



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/SpeedBasedMemoryConsumptionThrottlingStrategy.java:
##########
@@ -183,6 +182,9 @@ private long computeParkTime(@NotNull AtomicInteger writtenPagesCounter, long cu
      * @return estimation of work done (in pages)
      */
     private int cpDonePagesEstimation(int cpWrittenPages) {
+        // TODO: IGNITE-16879 - this only works correctly if time-to-write a page is close to time-to-sync a page.
+        // In reality, this oes not seem to hold, which produces wrong estimations. We could measure the real times

Review Comment:
   ```suggestion
           // In reality, this does not seem to hold, which produces wrong estimations. We could measure the real times
   ```



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org