From caedd72dab6cd22eb1de300c8b0a0e2828644db0 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Thu, 25 Jul 2024 07:23:13 +0300 Subject: [PATCH] Improved documentation for the BackoffIdleStrategy. Linux by default will not respect the park windows. It will coalesce timer events in 50 us groups. So if you want to wait e.g. 51 us, it could be you need to wait 100 us. Some documentation was added to explain this and how this can be improved. --- .../org/agrona/concurrent/BackoffIdleStrategy.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/agrona/src/main/java/org/agrona/concurrent/BackoffIdleStrategy.java b/agrona/src/main/java/org/agrona/concurrent/BackoffIdleStrategy.java index e317e3aac..72b9eb0d9 100644 --- a/agrona/src/main/java/org/agrona/concurrent/BackoffIdleStrategy.java +++ b/agrona/src/main/java/org/agrona/concurrent/BackoffIdleStrategy.java @@ -105,7 +105,18 @@ abstract class BackoffIdleStrategyData extends BackoffIdleStrategyPrePad *

* Spin for maxSpins, then * {@link Thread#yield()} for maxYields, then - * {@link java.util.concurrent.locks.LockSupport#parkNanos(long)} on an exponential backoff to maxParkPeriodNs + * {@link java.util.concurrent.locks.LockSupport#parkNanos(long)} on an exponential backoff to maxParkPeriodNs. + *

+ * Under Linux, multiple timer events will be coalesced in a 50 us window to minimize the timer overhead + * on the CPU. E.g. if you want to wait 10 us, it could be you need to wait 50us. This situation can be + * improved by changing the value of the timerslack_ns property which defaults to 50000. This can be done + * like this: + * + * echo 10000 > /proc/PID/timerslack_ns + * + * This will set the timer slack to 10 microseconds for the given PID of the thread. This property + * can't be set at the process level, so needs to be set for each thread specifically. Also it isn't + * guaranteed that after setting the property, the waiting time will be respected. */ public final class BackoffIdleStrategy extends BackoffIdleStrategyData implements IdleStrategy {