-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Java] Introduce SnapshotDurationTracker
- Loading branch information
Showing
7 changed files
with
288 additions
and
14 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
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
101 changes: 101 additions & 0 deletions
101
aeron-cluster/src/main/java/io/aeron/cluster/service/SnapshotDurationTracker.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,101 @@ | ||
/* | ||
* Copyright 2014-2023 Real Logic Limited. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 io.aeron.cluster.service; | ||
|
||
import org.agrona.concurrent.status.AtomicCounter; | ||
|
||
// TODO: check against duty cycle tracker | ||
// TODO: worry about false sharing? | ||
// TODO: mike b -- think about being able to delegate measurements to an aggregator | ||
|
||
/** | ||
* Snapshot duration tracker that tracks maximum snapshot duration and also keeps count of how many times a predefined | ||
* duration threshold is breached. | ||
*/ | ||
public class SnapshotDurationTracker | ||
{ | ||
private final AtomicCounter maxSnapshotDuration; | ||
private final AtomicCounter snapshotDurationThresholdExceededCount; | ||
private final long durationThresholdNs; | ||
private long snapshotStartTimeNs = Long.MIN_VALUE; | ||
|
||
/** | ||
* Create a tracker to track max snapshot duration and breaches of a threshold. | ||
* | ||
* @param maxSnapshotDuration counter for tracking. | ||
* @param snapshotDurationThresholdExceededCount counter for tracking. | ||
* @param durationThresholdNs to use for tracking breaches. | ||
*/ | ||
public SnapshotDurationTracker( | ||
final AtomicCounter maxSnapshotDuration, | ||
final AtomicCounter snapshotDurationThresholdExceededCount, | ||
final long durationThresholdNs) | ||
{ | ||
this.maxSnapshotDuration = maxSnapshotDuration; | ||
this.snapshotDurationThresholdExceededCount = snapshotDurationThresholdExceededCount; | ||
this.durationThresholdNs = durationThresholdNs; | ||
} | ||
|
||
/** | ||
* Get max snapshot duration counter. | ||
* | ||
* @return max snapshot duration counter. | ||
*/ | ||
public AtomicCounter maxSnapshotDuration() | ||
{ | ||
return maxSnapshotDuration; | ||
} | ||
|
||
/** | ||
* Get counter tracking number of times {@link SnapshotDurationTracker#durationThresholdNs} was exceeded | ||
* | ||
* @return duration threshold exceeded counter. | ||
*/ | ||
public AtomicCounter snapshotDurationThresholdExceededCount() | ||
{ | ||
return snapshotDurationThresholdExceededCount; | ||
} | ||
|
||
/** | ||
* Called when snapshotting has started. | ||
* | ||
* @param timeNanos snapshot start time in nanoseconds. | ||
*/ | ||
public void onSnapshotStart(final long timeNanos) | ||
{ | ||
snapshotStartTimeNs = timeNanos; | ||
} | ||
|
||
/** | ||
* Called when snapshot has been taken. | ||
* | ||
* @param timeNanos snapshot end time in nanoseconds. | ||
*/ | ||
public void onSnapshotTaken(final long timeNanos) | ||
{ | ||
if (snapshotStartTimeNs != Long.MIN_VALUE) | ||
{ | ||
final long snapshotDurationNs = timeNanos - snapshotStartTimeNs; | ||
|
||
if (snapshotDurationNs > durationThresholdNs) | ||
{ | ||
snapshotDurationThresholdExceededCount.increment(); | ||
} | ||
|
||
maxSnapshotDuration.proposeMax(snapshotDurationNs); | ||
} | ||
} | ||
} |
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.