Skip to content

Commit

Permalink
Clean up some legacy code and improve build (deephaven#4674)
Browse files Browse the repository at this point in the history
* Avoid extra copy of TypeScript/JavaScript files in proto/raw-js-openapi/Dockerfile

* Delete FishUtil. All usages have been eliminated, trivially inlined, or the files have migrated to more appropriate modules.

* Refactor TrackedFileHandleFactory to use a ScheduledExecutorService instead of Scheduler

* Refactor Liveness to use a ScheduledExecutorService instead of Scheduler for (currently unused) scheduleCountReport

* Replace Scheduler usage in PeriodicUpdateGraph with ScheduledExecutorService. Standardize on nanoseconds for timing. Eliminate unnecessary initializations.

* Replace Scheduler usage in StatsDriver with ScheduledExecutorService

* Delete :Net. Delete io.sched package. Delete gradle :Net and fishnet projects/configurations. Delete dependencies on same.

* Delete legacy utility that used reflection to reach into the guts of SelectorImpl

---------

Co-authored-by: Colin Alworth <[email protected]>
rcaudy and niloc132 authored Nov 30, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 7e596a6 commit e719136
Showing 58 changed files with 173 additions and 4,481 deletions.
Original file line number Diff line number Diff line change
@@ -4,13 +4,10 @@
package io.deephaven.base.stats;

public interface ItemUpdateListener {
public void handleItemUpdated(Item item, long now, long appNow, int intervalIndex, long intervalMillis,
String intervalName);

public static final ItemUpdateListener NULL = new ItemUpdateListener() {
public void handleItemUpdated(Item item, long now, long appNow, int intervalIndex, long intervalMillis,
String intervalName) {
// empty
}
void handleItemUpdated(
Item<?> item, long now, long appNow, int intervalIndex, long intervalMillis, String intervalName);

ItemUpdateListener NULL = (item, now, appNow, intervalIndex, intervalMillis, intervalName) -> {
};
}
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public void testSample() throws Exception {
// should have a count of 1 in bin[1]..bin[63]; bin[0]=2

Stats.update(new ItemUpdateListener() {
public void handleItemUpdated(Item item, long now, long appNow, int intervalIndex, long intervalMillis,
public void handleItemUpdated(Item<?> item, long now, long appNow, int intervalIndex, long intervalMillis,
String intervalName) {
// Value v = item.getValue();
HistogramPower2 nh;
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public void testSample() throws Exception {
// This should print 10 invocations every time

Stats.update(new ItemUpdateListener() {
public void handleItemUpdated(Item item, long now, long appNow, int intervalIndex, long intervalMillis,
public void handleItemUpdated(Item<?> item, long now, long appNow, int intervalIndex, long intervalMillis,
String intervalName) {
Value v = item.getValue();
History history = v.getHistory();
14 changes: 0 additions & 14 deletions FishUtil/build.gradle

This file was deleted.

89 changes: 0 additions & 89 deletions FishUtil/cpp/MicroTimer.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions FishUtil/cpp/MicroTimer.h

This file was deleted.

9 changes: 0 additions & 9 deletions FishUtil/cpp/SignalUtils.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions FishUtil/cpp/SignalUtils.h

This file was deleted.

1 change: 0 additions & 1 deletion FishUtil/gradle.properties

This file was deleted.

955 changes: 0 additions & 955 deletions FishUtil/src/main/java/io/deephaven/util/DateUtil.java

This file was deleted.

22 changes: 0 additions & 22 deletions FishUtil/src/main/java/io/deephaven/util/ExceptionUtil.java

This file was deleted.

19 changes: 0 additions & 19 deletions FishUtil/src/main/java/io/deephaven/util/Mailer.java

This file was deleted.

155 changes: 0 additions & 155 deletions FishUtil/src/main/java/io/deephaven/util/ThreadSafeDateFormat.java

This file was deleted.

110 changes: 0 additions & 110 deletions FishUtil/src/main/java/io/deephaven/util/Validate.java

This file was deleted.

120 changes: 0 additions & 120 deletions FishUtil/src/main/java/io/deephaven/util/formatters/ISO8601.java

This file was deleted.

111 changes: 0 additions & 111 deletions FishUtil/src/main/java/io/deephaven/util/signals/SignalSender.java

This file was deleted.

110 changes: 0 additions & 110 deletions FishUtil/src/main/java/io/deephaven/util/signals/SignalUtils.java

This file was deleted.

48 changes: 0 additions & 48 deletions FishUtil/src/main/java/io/deephaven/util/threads/ThreadDump.java

This file was deleted.

109 changes: 0 additions & 109 deletions IO/src/main/java/io/deephaven/io/NioUtil.java

This file was deleted.

66 changes: 0 additions & 66 deletions IO/src/main/java/io/deephaven/io/sched/Job.java

This file was deleted.

65 changes: 0 additions & 65 deletions IO/src/main/java/io/deephaven/io/sched/JobState.java

This file was deleted.

211 changes: 0 additions & 211 deletions IO/src/main/java/io/deephaven/io/sched/JobStateTimeoutQueue.java

This file was deleted.

199 changes: 0 additions & 199 deletions IO/src/main/java/io/deephaven/io/sched/Scheduler.java

This file was deleted.

30 changes: 0 additions & 30 deletions IO/src/main/java/io/deephaven/io/sched/TimedJob.java

This file was deleted.

979 changes: 0 additions & 979 deletions IO/src/main/java/io/deephaven/io/sched/YASchedulerImpl.java

This file was deleted.

124 changes: 0 additions & 124 deletions IO/src/test/java/io/deephaven/io/sched/TestJobStateTimeoutQueue.java

This file was deleted.

30 changes: 0 additions & 30 deletions Net/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion Net/gradle.properties

This file was deleted.

111 changes: 0 additions & 111 deletions Net/src/main/java/io/deephaven/net/CommBase.java

This file was deleted.

285 changes: 0 additions & 285 deletions Net/src/main/java/io/deephaven/net/impl/nio/FastNIODriver.java

This file was deleted.

295 changes: 0 additions & 295 deletions Net/src/main/java/io/deephaven/net/impl/nio/NIODriver.java

This file was deleted.

2 changes: 0 additions & 2 deletions Stats/build.gradle
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ dependencies {
implementation project(':DataStructures')
implementation project(':IO')
implementation project(':Configuration')
implementation project(':FishUtil')
implementation project(':Net')
implementation project(':log-factory')
implementation project(':engine-context')
compileOnly 'com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0'
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
import io.deephaven.configuration.Configuration;
import io.deephaven.internal.log.LoggerFactory;
import io.deephaven.io.logger.Logger;
import io.deephaven.util.OSUtil;
import io.deephaven.stats.util.OSUtil;
import io.deephaven.base.stats.*;
import io.deephaven.hash.KeyedLongObjectHash;
import io.deephaven.hash.KeyedLongObjectHashMap;
60 changes: 34 additions & 26 deletions Stats/src/main/java/io/deephaven/stats/StatsDriver.java
Original file line number Diff line number Diff line change
@@ -5,23 +5,27 @@

import io.deephaven.base.clock.Clock;
import io.deephaven.engine.context.ExecutionContext;
import io.deephaven.net.CommBase;
import io.deephaven.util.SafeCloseable;
import io.deephaven.util.formatters.ISO8601;
import io.deephaven.base.stats.*;
import io.deephaven.base.text.TimestampBuffer;
import io.deephaven.configuration.Configuration;
import io.deephaven.io.log.*;
import io.deephaven.io.sched.TimedJob;
import io.deephaven.io.log.impl.LogEntryPoolImpl;
import io.deephaven.io.log.impl.LogSinkImpl;
import io.deephaven.util.annotations.ReferentialIntegrity;
import io.deephaven.util.thread.NamingThreadFactory;

import java.util.Properties;
import java.util.TimeZone;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
* Drives the collection of statistics on a 1-second timer task.
*/
public class StatsDriver extends TimedJob {
public class StatsDriver {
public interface StatusAdapter {
void sendAlert(String alertText);

@@ -39,11 +43,11 @@ public boolean cmsAlertEnabled() {
}

private final LogEntryPool entryPool;
private final LogSink sink;
private final LogSink<?> sink;
private final LogEntry[] entries;

private final LogEntryPool entryPoolHisto;
private final LogSink sinkHisto;
private final LogSink<?> sinkHisto;
private final LogEntry[] entriesHisto;

private final TimestampBuffer systemTimestamp;
@@ -52,9 +56,8 @@ public boolean cmsAlertEnabled() {
public final static String header =
"Stat,IntervalName,NowSec,NowString,AppNowSec,AppNowString,TypeTag,Name,N,Sum,Last,Min,Max,Avg,Sum2,Stdev";

private long nextInvocation = System.currentTimeMillis();
private long nextCpuUpdate = nextInvocation + CPU_INTERVAL;
private long nextMemUpdate = nextInvocation + MEM_INTERVAL;
private long nextCpuUpdate;
private long nextMemUpdate;

private static final long STEP = 1000;
private static final long MEM_INTERVAL = 1000;
@@ -71,9 +74,14 @@ public boolean cmsAlertEnabled() {
private final StatsIntradayLogger intraday;
private final Value clockValue;
private final ExecutionContext executionContext;
@ReferentialIntegrity
private final ScheduledExecutorService scheduler;
@ReferentialIntegrity
private final ScheduledFuture<?> updateJobFuture;

private final StatsMemoryCollector memStats;
private final StatsCPUCollector cpuStats;
@ReferentialIntegrity
private ObjectAllocationCollector objectAllocation;

public StatsDriver(Clock clock) {
@@ -116,8 +124,9 @@ public StatsDriver(Clock clock, StatsIntradayLogger intraday, boolean getFdStats
}
}

this.systemTimestamp = new TimestampBuffer(ISO8601.serverTimeZone());
this.appTimestamp = new TimestampBuffer(ISO8601.serverTimeZone());
final TimeZone serverTimeZone = Configuration.getInstance().getServerTimezone();
this.systemTimestamp = new TimestampBuffer(serverTimeZone);
this.appTimestamp = new TimestampBuffer(serverTimeZone);

if (path == null) {
this.entryPool = null;
@@ -150,23 +159,30 @@ public StatsDriver(Clock clock, StatsIntradayLogger intraday, boolean getFdStats
clockValue = null;
}

long now = System.currentTimeMillis();
long delay = STEP - (now % STEP);
nextInvocation = now + delay;
final long now = System.currentTimeMillis();
final long delay = STEP - (now % STEP);
nextCpuUpdate = now + delay + CPU_INTERVAL;
nextMemUpdate = now + delay + MEM_INTERVAL;

cpuStats = new StatsCPUCollector(CPU_INTERVAL, getFdStats);
memStats = new StatsMemoryCollector(MEM_INTERVAL, statusAdapter::sendAlert, statusAdapter::cmsAlertEnabled);
if (Configuration.getInstance().getBoolean("allocation.stats.enabled")) {
objectAllocation = new ObjectAllocationCollector();
}
executionContext = ExecutionContext.getContext();

// now that the StatsDriver is completely constructed, we can schedule the first iteration
// now that the StatsDriver is completely constructed, we can schedule the update job
if (Configuration.getInstance().getBoolean("statsdriver.enabled")) {
schedule();
scheduler = Executors.newSingleThreadScheduledExecutor(
new NamingThreadFactory(StatsDriver.class, "updateScheduler", true));
updateJobFuture = scheduler.scheduleAtFixedRate(this::update, delay, STEP, TimeUnit.MILLISECONDS);
} else {
scheduler = null;
updateJobFuture = null;
}
}

public void timedOut() {
private void update() {
long t0 = System.nanoTime();
long now = System.currentTimeMillis();
long appNow = clock == null ? now : clock.currentTimeMillis();
@@ -207,20 +223,12 @@ public void timedOut() {
}
}

schedule();

statsTiming.sample((System.nanoTime() - t0 + 500) / 1000);
}

private void schedule() {
CommBase.getScheduler().installJob(this, nextInvocation);
long steps = Math.max(1L, (((System.currentTimeMillis() - nextInvocation) / STEP) + 1));
nextInvocation += steps * STEP;
}

private final ItemUpdateListener LISTENER = new ItemUpdateListener() {
@Override
public void handleItemUpdated(Item item, long now, long appNow, int intervalIndex, long intervalMillis,
public void handleItemUpdated(Item<?> item, long now, long appNow, int intervalIndex, long intervalMillis,
String intervalName) {
final Value v = item.getValue();
final History history = v.getHistory();
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.util;
package io.deephaven.stats.util;

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.function.Predicate;

@SuppressWarnings("WeakerAccess")
public class OSUtil {

public enum OSFamily {

LINUX(name -> name.startsWith("Linux")), WINDOWS(name -> name.contains("Windows")), MAC_OS(
name -> name.startsWith("Mac OS")), SOLARIS(name -> name.startsWith("SunOs"));
// @formatter:off
LINUX(name -> name.startsWith("Linux")),
WINDOWS(name -> name.contains("Windows")),
MAC_OS(name -> name.startsWith("Mac OS")),
SOLARIS(name -> name.startsWith("SunOs"));
// @formatter:on

private final Predicate<String> nameMatcher;

6 changes: 1 addition & 5 deletions TableLogger/TableLogger.gradle
Original file line number Diff line number Diff line change
@@ -2,12 +2,8 @@ plugins {
id 'io.deephaven.project.register'
}

configurations {
implementation.extendsFrom fishUtil, fishData
testImplementation.extendsFrom fishDataTest
}

dependencies {
implementation project(':Base')
implementation project(':Util')
testRuntimeOnly project(path: ':configs')
testRuntimeOnly project(path: ':test-configs')
Original file line number Diff line number Diff line change
@@ -9,8 +9,8 @@
import io.deephaven.io.log.LogEntry;
import io.deephaven.io.log.LogLevel;
import io.deephaven.io.logger.Logger;
import io.deephaven.util.threads.ThreadDump;
import io.deephaven.internal.log.LoggerFactory;
import io.deephaven.util.thread.ThreadDump;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Original file line number Diff line number Diff line change
@@ -29,14 +29,12 @@ configurations {
fishDataStructure.extendsFrom fishIo
fishConfig.extendsFrom fishDataStructure
fishDataGenerator.extendsFrom jdom
fishNet.extendsFrom fishIo
fishNumerics.extendsFrom fishBase
fishUtil.extendsFrom fishConfig
fishBaseTest.extendsFrom junit
fishIoTest.extendsFrom fishBaseTest

dhNumerics.extendsFrom fishNumerics, jama
dhUtil.extendsFrom commonsIo, commonsLang3, commonsText, fishUtil, fishNet, fishIo, jdom
dhUtil.extendsFrom commonsIo, commonsLang3, commonsText, fishConfig, fishIo, jdom
dhPlot.extendsFrom dhUtil
dhBenchmarkSupport.extendsFrom fishData
dhIntegrations.extendsFrom math3
@@ -70,10 +68,6 @@ dependencies {

fishConfig project(':Configuration')

fishUtil project(':FishUtil')

fishNet project(':Net')

fishBaseTest project(path: ':Base', configuration: 'tests')

fishIoTest project(path: ':IO', configuration: 'tests')
2 changes: 0 additions & 2 deletions engine/table/build.gradle
Original file line number Diff line number Diff line change
@@ -28,8 +28,6 @@ dependencies {
implementation project(':Configuration')
implementation project(':log-factory')
implementation project(':Stats')
implementation project(':Net')
implementation project(':FishUtil')

implementation 'com.github.f4b6a3:uuid-creator:5.2.0'
// TODO(deephaven-core#3204): t-digest 3.3 appears to have higher errors than 3.2
Original file line number Diff line number Diff line change
@@ -27,9 +27,6 @@
import io.deephaven.io.log.LogEntry;
import io.deephaven.io.log.impl.LogOutputStringImpl;
import io.deephaven.io.logger.Logger;
import io.deephaven.io.sched.Scheduler;
import io.deephaven.io.sched.TimedJob;
import io.deephaven.net.CommBase;
import io.deephaven.util.SafeCloseable;
import io.deephaven.util.annotations.TestUseOnly;
import io.deephaven.util.datastructures.SimpleReferenceManager;
@@ -51,6 +48,8 @@
import java.util.function.BooleanSupplier;
import java.util.function.LongConsumer;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
* <p>
* This class uses a thread (or pool of threads) to periodically update a set of monitored update sources at a specified
@@ -132,25 +131,30 @@ public static PerformanceEntry createUpdatePerformanceEntry(
private final Thread refreshThread;
private volatile boolean running = true;

/**
* {@link ScheduledExecutorService} used for scheduling the {@link #watchDogTimeoutProcedure}.
*/
private final ScheduledExecutorService watchdogScheduler;

/**
* If this is set to a positive value, then we will call the {@link #watchDogTimeoutProcedure} if any single run
* loop takes longer than this value. The intention is to use this for strategies, or other queries, where a
* PeriodicUpdateGraph loop that is "stuck" is the equivalent of an error. Set the value with
* {@link #setWatchDogMillis(int)}.
*/
private int watchDogMillis = 0;
private volatile int watchDogMillis = 0;
/**
* If a timeout time has been {@link #setWatchDogMillis(int) set}, this procedure will be called if any single run
* loop takes longer than the value specified. Set the value with
* {@link #setWatchDogTimeoutProcedure(LongConsumer)}.
*/
private LongConsumer watchDogTimeoutProcedure = null;
private volatile LongConsumer watchDogTimeoutProcedure;

public static final String ALLOW_UNIT_TEST_MODE_PROP = "PeriodicUpdateGraph.allowUnitTestMode";
private final boolean allowUnitTestMode;
private int notificationAdditionDelay = 0;
private int notificationAdditionDelay;
private Random notificationRandomizer = new Random(0);
private boolean unitTestMode = false;
private boolean unitTestMode;
private ExecutorService unitTestRefreshThreadPool;

public static final String DEFAULT_TARGET_CYCLE_DURATION_MILLIS_PROP =
@@ -162,27 +166,27 @@ public static PerformanceEntry createUpdatePerformanceEntry(
private final long minimumCycleDurationToLogNanos;

/** when to next flush the performance tracker; initializes to zero to force a flush on start */
private long nextUpdatePerformanceTrackerFlushTime = 0;
private long nextUpdatePerformanceTrackerFlushTimeNanos;

/**
* How many cycles we have not logged, but were non-zero.
*/
private long suppressedCycles = 0;
private long suppressedCyclesTotalNanos = 0;
private long suppressedCyclesTotalSafePointTimeMillis = 0;
private long suppressedCycles;
private long suppressedCyclesTotalNanos;
private long suppressedCyclesTotalSafePointTimeMillis;

/**
* Accumulated UpdateGraph exclusive lock waits for the current cycle (or previous, if idle).
*/
private long currentCycleLockWaitTotalNanos = 0;
private long currentCycleLockWaitTotalNanos;
/**
* Accumulated delays due to intracycle yields for the current cycle (or previous, if idle).
*/
private long currentCycleYieldTotalNanos = 0L;
private long currentCycleYieldTotalNanos;
/**
* Accumulated delays due to intracycle sleeps for the current cycle (or previous, if idle).
*/
private long currentCycleSleepTotalNanos = 0L;
private long currentCycleSleepTotalNanos;

public static class AccumulatedCycleStats {
/**
@@ -331,6 +335,14 @@ public PeriodicUpdateGraph(
}
}), "PeriodicUpdateGraph." + name + ".refreshThread");
refreshThread.setDaemon(true);
watchdogScheduler = Executors.newSingleThreadScheduledExecutor(
new NamingThreadFactory(PeriodicUpdateGraph.class, "watchdogScheduler", true) {
@Override
public Thread newThread(@NotNull final Runnable r) {
// Not a refresh thread, but should still be instrumented for debugging purposes.
return super.newThread(ThreadInitializationFactory.wrapRunnable(r));
}
});

updatePerformanceTracker = new UpdatePerformanceTracker(this);
}
@@ -593,15 +605,6 @@ public void setWatchDogTimeoutProcedure(LongConsumer procedure) {
this.watchDogTimeoutProcedure = procedure;
}

private class WatchdogJob extends TimedJob {
@Override
public void timedOut() {
if (watchDogTimeoutProcedure != null) {
watchDogTimeoutProcedure.accept(watchDogMillis);
}
}
}

/**
* Install a real NotificationProcessor and start the primary refresh thread.
*
@@ -1129,7 +1132,7 @@ public Runnable flushAllNormalNotificationsForUnitTests(@NotNull final BooleanSu
final ControlledNotificationProcessor controlledNotificationProcessor = new ControlledNotificationProcessor();
notificationProcessor = controlledNotificationProcessor;
final Future<?> flushJobFuture = unitTestRefreshThreadPool.submit(() -> {
final long deadlineNanoTime = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
final long deadlineNanoTime = System.nanoTime() + MILLISECONDS.toNanos(timeoutMillis);
boolean flushed;
while ((flushed = flushOneNotificationForUnitTestsInternal(false)) || !done.getAsBoolean()) {
if (!flushed) {
@@ -1676,8 +1679,6 @@ private static LogEntry appendAsMillisFromNanos(final LogEntry entry, final long
* {@link #getTargetCycleDurationMillis() minimum cycle time}.
*/
private void refreshTablesAndFlushNotifications() {
final Scheduler sched = CommBase.getScheduler();
final long startTime = sched.currentTimeMillis();
final long startTimeNanos = System.nanoTime();
jvmIntrospectionContext.startSample();

@@ -1686,17 +1687,20 @@ private void refreshTablesAndFlushNotifications() {
} else {
currentCycleLockWaitTotalNanos = currentCycleYieldTotalNanos = currentCycleSleepTotalNanos = 0L;

WatchdogJob watchdogJob = null;
ScheduledFuture<?> watchdogFuture = null;

if ((watchDogMillis > 0) && (watchDogTimeoutProcedure != null)) {
watchdogJob = new WatchdogJob();
sched.installJob(watchdogJob, startTime + watchDogMillis);
final long localWatchdogMillis = watchDogMillis;
final LongConsumer localWatchdogTimeoutProcedure = watchDogTimeoutProcedure;
if ((localWatchdogMillis > 0) && (localWatchdogTimeoutProcedure != null)) {
watchdogFuture = watchdogScheduler.schedule(
() -> localWatchdogTimeoutProcedure.accept(localWatchdogMillis),
localWatchdogMillis, MILLISECONDS);
}

refreshAllTables();

if (watchdogJob != null) {
sched.cancelJob(watchdogJob);
if (watchdogFuture != null) {
watchdogFuture.cancel(true);
}
jvmIntrospectionContext.endSample();
final long cycleTimeNanos = System.nanoTime() - startTimeNanos;
@@ -1707,7 +1711,7 @@ private void refreshTablesAndFlushNotifications() {
Thread.yield();
}

waitForNextCycle(startTime, sched);
waitForNextCycle(startTimeNanos);
}

private void computeStatsAndLogCycle(final long cycleTimeNanos) {
@@ -1791,24 +1795,25 @@ private void logSuppressedCycles() {
* wait the remaining period.
* </p>
*
* @param startTime The start time of the last run cycle
* @param timeSource The source of time that startTime was based on
* @param startTimeNanos The start time of the last run cycle as reported by {@link System#nanoTime()}
*/
private void waitForNextCycle(final long startTime, final Scheduler timeSource) {
final long now = timeSource.currentTimeMillis();
long expectedEndTime = startTime + targetCycleDurationMillis;
private void waitForNextCycle(final long startTimeNanos) {
final long nowNanos = System.nanoTime();
long expectedEndTimeNanos = startTimeNanos + MILLISECONDS.toNanos(targetCycleDurationMillis);
if (minimumInterCycleSleep > 0) {
expectedEndTime = Math.max(expectedEndTime, now + minimumInterCycleSleep);
expectedEndTimeNanos =
Math.max(expectedEndTimeNanos, nowNanos + MILLISECONDS.toNanos(minimumInterCycleSleep));
}
if (expectedEndTime >= nextUpdatePerformanceTrackerFlushTime) {
nextUpdatePerformanceTrackerFlushTime = now + UpdatePerformanceTracker.REPORT_INTERVAL_MILLIS;
if (expectedEndTimeNanos >= nextUpdatePerformanceTrackerFlushTimeNanos) {
nextUpdatePerformanceTrackerFlushTimeNanos =
nowNanos + MILLISECONDS.toNanos(UpdatePerformanceTracker.REPORT_INTERVAL_MILLIS);
try {
updatePerformanceTracker.flush();
} catch (Exception err) {
log.error().append("Error flushing UpdatePerformanceTracker: ").append(err).endl();
}
}
waitForEndTime(expectedEndTime, timeSource);
waitForEndTime(expectedEndTimeNanos);
}

/**
@@ -1819,21 +1824,22 @@ private void waitForNextCycle(final long startTime, final Scheduler timeSource)
* If the delay is interrupted for any other {@link InterruptedException reason}, it will be logged and continue to
* wait the remaining period.
*
* @param expectedEndTime The time which we should sleep until
* @param timeSource The source of time that startTime was based on
* @param expectedEndTimeNanos The time (as reported by {@link System#nanoTime()}) which we should sleep until
*/
private void waitForEndTime(final long expectedEndTime, final Scheduler timeSource) {
long remainingMillis;
while ((remainingMillis = expectedEndTime - timeSource.currentTimeMillis()) > 0) {
private void waitForEndTime(final long expectedEndTimeNanos) {
long remainingNanos;
while ((remainingNanos = expectedEndTimeNanos - System.nanoTime()) > 0) {
if (refreshRequested.get()) {
return;
}
synchronized (refreshRequested) {
if (refreshRequested.get()) {
return;
}
final long millisToWait = remainingNanos / 1_000_000;
final int extraNanosToWait = (int) (remainingNanos - (millisToWait * 1_000_000));
try {
refreshRequested.wait(remainingMillis);
refreshRequested.wait(millisToWait, extraNanosToWait);
} catch (final InterruptedException logAndIgnore) {
log.warn().append("Interrupted while waiting on refreshRequested. Ignoring: ").append(logAndIgnore)
.endl();
@@ -2031,7 +2037,7 @@ public static final class Builder {
Configuration.getInstance().getBooleanWithDefault(ALLOW_UNIT_TEST_MODE_PROP, false);
private long targetCycleDurationMillis =
Configuration.getInstance().getIntegerWithDefault(DEFAULT_TARGET_CYCLE_DURATION_MILLIS_PROP, 1000);
private long minimumCycleDurationToLogNanos = TimeUnit.MILLISECONDS.toNanos(
private long minimumCycleDurationToLogNanos = MILLISECONDS.toNanos(
Configuration.getInstance().getIntegerWithDefault(MINIMUM_CYCLE_DURATION_TO_LOG_MILLIS_PROP, 25));

private String name;
Loading

0 comments on commit e719136

Please sign in to comment.