forked from gridgain/apache-ignite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GG-33675 Speed-based throttling hasn't managed to protect the checkpo…
…int buffer of a node (apache#2187) - speed-based throttling had a bug that prevented it to protect CP Buffer when CP progress was not yet reported; it's fixed here - speed-based throttling has been heavily refactored to make it easier to understand - the machinery comprising and surrounding write throttling has been commented
- Loading branch information
Showing
17 changed files
with
1,295 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...gnite/internal/processors/cache/persistence/pagemem/CheckpointBufferOverflowWatchdog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 GridGain Systems, Inc. and Contributors. | ||
* | ||
* Licensed under the GridGain Community Edition License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license | ||
* | ||
* 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 static org.apache.ignite.internal.processors.cache.persistence.pagemem.PagesWriteThrottlePolicy.CP_BUF_FILL_THRESHOLD; | ||
|
||
/** | ||
* Logic used to determine whether Checkpoint Buffer is in danger zone and writer threads should be throttled. | ||
*/ | ||
class CheckpointBufferOverflowWatchdog { | ||
/** Page memory. */ | ||
private final PageMemoryImpl pageMemory; | ||
|
||
/** | ||
* Creates a new instance. | ||
* | ||
* @param pageMemory page memory to use | ||
*/ | ||
CheckpointBufferOverflowWatchdog(PageMemoryImpl pageMemory) { | ||
this.pageMemory = pageMemory; | ||
} | ||
|
||
/** | ||
* Returns true if Checkpoint Buffer is in danger zone (more than | ||
* {@link PagesWriteThrottlePolicy#CP_BUF_FILL_THRESHOLD} of the buffer is filled) and, hence, writer threads need | ||
* to be throttled. | ||
* | ||
* @return {@code true} iff Checkpoint Buffer is in danger zone | ||
*/ | ||
boolean isInDangerZone() { | ||
int checkpointBufLimit = (int)(pageMemory.checkpointBufferPagesSize() * CP_BUF_FILL_THRESHOLD); | ||
|
||
return pageMemory.checkpointBufferPagesCount() > checkpointBufLimit; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...a/org/apache/ignite/internal/processors/cache/persistence/pagemem/ExponentialBackoff.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2021 GridGain Systems, Inc. and Contributors. | ||
* | ||
* Licensed under the GridGain Community Edition License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license | ||
* | ||
* 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.atomic.AtomicInteger; | ||
|
||
/** | ||
* Implements exponential backoff logic. Contains a counter and increments it on each {@link #nextDuration()}. | ||
* May be reset using {@link #reset()}. | ||
*/ | ||
class ExponentialBackoff { | ||
/** | ||
* Starting backoff duration. | ||
*/ | ||
private final long startingBackoffNanos; | ||
|
||
/** | ||
* Backoff ratio. Each next duration will be this times longer. | ||
*/ | ||
private final double backoffRatio; | ||
|
||
/** | ||
* Exponential backoff counter. | ||
*/ | ||
private final AtomicInteger exponentialBackoffCounter = new AtomicInteger(0); | ||
|
||
/** | ||
* Constructs a new instance with the given parameters. | ||
* | ||
* @param startingBackoffNanos duration of first backoff in nanoseconds | ||
* @param backoffRatio each next duration will be this times longer | ||
*/ | ||
public ExponentialBackoff(long startingBackoffNanos, double backoffRatio) { | ||
this.startingBackoffNanos = startingBackoffNanos; | ||
this.backoffRatio = backoffRatio; | ||
} | ||
|
||
/** | ||
* Returns next backoff duration (in nanoseconds). As a side effect, increments the backoff counter so that | ||
* next call will return a longer duration. | ||
* | ||
* @return next backoff duration in nanoseconds | ||
*/ | ||
public long nextDuration() { | ||
int exponent = exponentialBackoffCounter.getAndIncrement(); | ||
return (long) (startingBackoffNanos * Math.pow(backoffRatio, exponent)); | ||
} | ||
|
||
/** | ||
* Resets the exponential backoff counter so that next call to {@link #nextDuration()} | ||
* will return {@link #startingBackoffNanos}. | ||
* | ||
* @return {@code true} iff this backoff was not already in a reset state | ||
*/ | ||
public boolean reset() { | ||
int oldValue = exponentialBackoffCounter.getAndSet(0); | ||
return oldValue != 0; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...e/internal/processors/cache/persistence/pagemem/ExponentialBackoffThrottlingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2021 GridGain Systems, Inc. and Contributors. | ||
* | ||
* Licensed under the GridGain Community Edition License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license | ||
* | ||
* 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; | ||
|
||
/** | ||
* Logic used to protect memory (mainly, Checkpoint Buffer) from exhaustion using exponential backoff. | ||
*/ | ||
class ExponentialBackoffThrottlingStrategy { | ||
/** | ||
* Starting throttle time. Limits write speed to 1000 MB/s. | ||
*/ | ||
private static final long STARTING_THROTTLE_NANOS = 4000; | ||
|
||
/** | ||
* Backoff ratio. Each next park will be this times longer. | ||
*/ | ||
private static final double BACKOFF_RATIO = 1.05; | ||
|
||
/** | ||
* Exponential backoff used to throttle threads. | ||
*/ | ||
private final ExponentialBackoff backoff = new ExponentialBackoff(STARTING_THROTTLE_NANOS, BACKOFF_RATIO); | ||
|
||
/** | ||
* Computes next duration (in nanos) to throttle a thread to protect Checkpoint Buffer. | ||
* | ||
* @return park time in nanos | ||
*/ | ||
long protectionParkTime() { | ||
return backoff.nextDuration(); | ||
} | ||
|
||
/** | ||
* Resets the backoff counter. Invoked when no throttling is needed anymore. | ||
* | ||
* @return {@code true} iff the backoff was not already in a reset state | ||
*/ | ||
boolean resetBackoff() { | ||
return backoff.reset(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.