Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gank a thread and sleep instead of scheduling, cope with broken assumptions about queue size and timing #616

Merged
merged 5 commits into from
Oct 23, 2024

Conversation

niklasf
Copy link
Member

@niklasf niklasf commented Oct 21, 2024

based on #615

  • somehow ... the queue got huge and now flushQ.size complexity prevents recovery -> an estimate for the size is enough, so use a separate atomic integer to get queue size in O(1)
  • somehow ... time spent flushing is significant compared to configured interval size -> effectively subtract time spent flushing from interval
  • somehow ... we can't keep up despite the sleep time going to zero -> too bad ... we only have this one thread (in particular, computing a more accurate maxDelayFactor based on the real interval wouldn't help, because the loop is already hot)

@niklasf niklasf force-pushed the sleep-and-flush-robustness branch 2 times, most recently from ab1da61 to 4ce7d70 Compare October 21, 2024 21:18
private val monitor = Monitor.connector.flush
private val flushThread = Future:
while !workers.isShuttingDown && !workers.isTerminated do
Thread.sleep(0, flush().timeLeft.toNanos.toInt.atLeast(0))
Copy link
Collaborator

@ornicar ornicar Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    public static void sleep(long millis, int nanos) throws InterruptedException {
        if (nanos < 0 || nanos > 999999) {
            throw new IllegalArgumentException("nanosecond timeout value out of range");
        }

Are we sure we'll never call Thread.sleep(0, nanos) with nanos > 999999? Because I think that would blow lila-ws up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, I didn't expect that. Would have definitely been possible, depending on the configuration. Fixed.

@ornicar ornicar merged commit 3446313 into master Oct 23, 2024
2 checks passed
@lenguyenthanh lenguyenthanh deleted the sleep-and-flush-robustness branch October 25, 2024 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants