This is an automated email from the ASF dual-hosted git repository. williamsong pushed a commit to branch snapshot-branch2 in repository https://gitbox.apache.org/repos/asf/ratis.git
commit 3165c25e54dd03445b8709ba0feab2cfd07e3d72 Author: Potato <[email protected]> AuthorDate: Mon Aug 7 22:33:49 2023 +0800 RATIS-1867. To uniformly manage the timeout parameters for detecting gc. (#899) --- .../src/main/java/org/apache/ratis/util/JvmPauseMonitor.java | 8 +++++--- .../main/java/org/apache/ratis/server/impl/RaftServerProxy.java | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java b/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java index 532bd2255..fac3d0ede 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/JvmPauseMonitor.java @@ -88,14 +88,16 @@ public class JvmPauseMonitor { } private static final TimeDuration SLEEP_TIME = TimeDuration.valueOf(500, TimeUnit.MILLISECONDS); - private static final TimeDuration WARN_THRESHOLD = TimeDuration.valueOf(100, TimeUnit.MILLISECONDS); + private final TimeDuration sleepDeviationThreshold; private final String name; private final AtomicReference<Thread> threadRef = new AtomicReference<>(); private final CheckedConsumer<TimeDuration, IOException> handler; - public JvmPauseMonitor(Object name, CheckedConsumer<TimeDuration, IOException> handler) { + public JvmPauseMonitor(Object name, TimeDuration sleepDeviationThreshold, + CheckedConsumer<TimeDuration, IOException> handler) { this.name = JavaUtils.getClassSimpleName(getClass()) + "-" + name; + this.sleepDeviationThreshold = sleepDeviationThreshold; this.handler = handler; } @@ -119,7 +121,7 @@ public class JvmPauseMonitor { return; } - if (extraSleep.compareTo(WARN_THRESHOLD) > 0) { + if (extraSleep.compareTo(sleepDeviationThreshold) > 0) { final Map<String, GcInfo> after = getGcTimes(); LOG.warn("{}: {}", this, toString(before, extraSleep, after)); } diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java index 528790981..bceeb44a1 100644 --- a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java +++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java @@ -218,9 +218,10 @@ class RaftServerProxy implements RaftServer { RaftServerConfigKeys.ThreadPool.proxySize(properties), id + "-impl"); + final TimeDuration sleepDeviationThreshold = RaftServerConfigKeys.sleepDeviationThreshold(properties); final TimeDuration rpcSlownessTimeout = RaftServerConfigKeys.Rpc.slownessTimeout(properties); final TimeDuration leaderStepDownWaitTime = RaftServerConfigKeys.LeaderElection.leaderStepDownWaitTime(properties); - this.pauseMonitor = new JvmPauseMonitor(id, + this.pauseMonitor = new JvmPauseMonitor(id, sleepDeviationThreshold, extraSleep -> handleJvmPause(extraSleep, rpcSlownessTimeout, leaderStepDownWaitTime)); this.threadGroup = threadGroup == null ? new ThreadGroup(this.id.toString()) : threadGroup; }
