mikemccand commented on code in PR #13190: URL: https://github.com/apache/lucene/pull/13190#discussion_r1532364018
########## lucene/core/src/java/org/apache/lucene/index/MergeRateLimiter.java: ########## @@ -118,24 +118,32 @@ private long maybePause(long bytes, long curNS) throws MergePolicy.MergeAbortedE throw new MergePolicy.MergeAbortedException("Merge aborted."); } - double rate = mbPerSec; // read from volatile rate once. - double secondsToPause = (bytes / 1024. / 1024.) / rate; - - // Time we should sleep until; this is purely instantaneous - // rate (just adds seconds onto the last time we had paused to); - // maybe we should also offer decayed recent history one? - long targetNS = lastNS + (long) (1000000000 * secondsToPause); - - long curPauseNS = targetNS - curNS; - - // We don't bother with thread pausing if the pause is smaller than 2 msec. - if (curPauseNS <= MIN_PAUSE_NS) { - // Set to curNS, not targetNS, to enforce the instant rate, not - // the "averaged over all history" rate: - lastNS = curNS; + final double rate = mbPerSec; // read from volatile rate once. + final double secondsToPause = (bytes / 1024. / 1024.) / rate; + + AtomicLong curPauseNSSetter = new AtomicLong(); + lastNS.updateAndGet( + last -> { + // Time we should sleep until; this is purely instantaneous + // rate (just adds seconds onto the last time we had paused to); + // maybe we should also offer decayed recent history one? + long targetNS = last + (long) (1000000000 * secondsToPause); + long curPauseNS = targetNS - curNS; + // We don't bother with thread pausing if the pause is smaller than 2 msec. + if (curPauseNS <= MIN_PAUSE_NS) { + // Set to curNS, not targetNS, to enforce the instant rate, not + // the "averaged over all history" rate: + curPauseNSSetter.set(0); + return curNS; + } Review Comment: > > is giving us here, ensuring we accurately account for all bytes written by N threads within a single merge > > That is not what it is doing. It is ensuring that the throttling timestamps stay in sync :/. Bytes being throttled are still per RateLimitedIndexOutput, which means they are per thread. Ahhhhhh gotchya. Each `RateLimitedIndexOutput` tracks its own `bytesSinceLastPause` and then invokes `pause` with its own private byte count, OK. So, yes, with the current approach we rate limit MB/sec per thread, not per merge. I think that's fine. Best effort! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org