ibessonov commented on code in PR #9924:
URL: https://github.com/apache/ignite/pull/9924#discussion_r849169443
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/SpeedBasedMemoryConsumptionThrottlingStrategy.java:
##########
@@ -149,15 +147,16 @@ private long computeParkTime(@NotNull AtomicInteger
writtenPagesCounter, long cu
final int cpWrittenPages = writtenPagesCounter.get();
final long donePages = cpDonePagesEstimation(cpWrittenPages);
- final long markDirtySpeed =
markSpeedAndAvgParkTime.getSpeedOpsPerSec(curNanoTime);
+ final long instantaneousMarkDirtySpeed =
markSpeedAndAvgParkTime.getSpeedOpsPerSec(curNanoTime);
// NB: we update progress for speed calculation only in this (clean
pages protection) scenario, because
// we only use the computed speed in this same scenario and for
reporting in logs (where it's not super
// important to display an ideally accurate speed), but not in the CP
Buffer protection scenario.
// This is to simplify code.
// The progress is set to 0 at the beginning of a checkpoint, so we
can be sure that the start time remembered
// in cpWriteSpeed is pretty accurate even without writing to
cpWriteSpeed from this method.
cpWriteSpeed.setProgress(donePages, curNanoTime);
- final long curCpWriteSpeed = cpWriteSpeed.getOpsPerSecond(curNanoTime);
+ // IDEA: use exponential moving average instead of regular moving
average so that we react to changes faster?
Review Comment:
Should we create a JIRA ticket with expanded idea description? It'll get
lost otherwise
##########
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 shouldThrottleWhenWritingTooFast() {
Review Comment:
Is there a chance to add comments to what's happening? If it's too boring
than you can just say "NO"
##########
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) {
+ // IDEA: this only works correctly if time-to-write a page is close to
time-to-sync a page. In reality, this
Review Comment:
I'd link this to JIRA as well
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagesWriteThrottleSandboxTest.java:
##########
@@ -172,14 +194,27 @@ public void testThrottle() throws Exception {
}
}, "metrics-view");
+ final boolean sawForm = false;
+
try (IgniteDataStreamer<Object, Object> ds =
ig.dataStreamer(CACHE_NAME)) {
ds.allowOverwrite(true);
- for (int i = 0; i < keyCnt * 10; i++) {
- ds.addData(ThreadLocalRandom.current().nextInt(keyCnt),
new TestValue(ThreadLocalRandom.current().nextInt(),
- ThreadLocalRandom.current().nextInt()));
+ while (true) {
+ long tensOfSecondsPassed =
TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - startNanos) / 10;
+ if (sawForm && tensOfSecondsPassed % 2 == 1) {
+ System.out.println("... sleeping ...");
+ Thread.sleep(1000);
+ }
+ else {
+
ds.addData(ThreadLocalRandom.current().nextInt(keyCnt), new
TestValue(ThreadLocalRandom.current().nextInt(),
+ ThreadLocalRandom.current().nextInt()));
- putRate.increment();
+ putRate.increment();
+ putCount.incrementAndGet();
+ }
+
+ if (System.nanoTime() - startNanos >
TimeUnit.MINUTES.toNanos(10))
Review Comment:
10 minutes, is this a typo?
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagesWriteThrottleSandboxTest.java:
##########
@@ -247,4 +287,9 @@ private void deleteWorkFiles() throws Exception {
cleanPersistenceDir();
U.delete(U.resolveWorkDirectory(U.defaultWorkDirectory(), "snapshot",
false));
}
+
+ /** {@inheritDoc} */
+ @Override protected FailureHandler getFailureHandler(String
igniteInstanceName) {
+ return new StopNodeOrHaltFailureHandler();
Review Comment:
Please don't use halting failure handler, it stops the entire process. It's
bad for TC, for example
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/IgniteThrottlingUnitTest.java:
##########
@@ -140,17 +157,14 @@ public void testCorrectTimeToPark() {
int markDirtySpeed = 34422;
int cpWriteSpeed = 19416;
- long time = throttle.getCleanPagesProtectionParkTime(0.04,
+ long time = throttle.getCleanPagesProtectionParkTime(0.67,
Review Comment:
Does this mean we lose one of older test scenarios?
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagesWriteThrottleSandboxTest.java:
##########
@@ -172,14 +194,27 @@ public void testThrottle() throws Exception {
}
}, "metrics-view");
+ final boolean sawForm = false;
Review Comment:
I don't think I understand this flag, and it's always false
##########
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;
+ }
+
+ /**
+ */
+ @Test
+ public void speedBasedThrottleShouldBeActivatedWhenNeeded() throws
Exception {
+ AtomicBoolean throttled = new AtomicBoolean(false);
+ listeningLog.registerListener(message -> {
Review Comment:
There are regexp-based or substring-based matchers for these loggers, you
should probably use them. Just check out other usages
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]