-
-
Notifications
You must be signed in to change notification settings - Fork 52
ADFA-5172: Instrument the accept loop to locate the periodic 1 s stall #1688
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
Open
davidschachterADFA
wants to merge
4
commits into
stage
Choose a base branch
from
bugfix/ADFA-5172-webserver-accept-stalls
base: stage
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+257
−42
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0afe807
ADFA-5172: Instrument the accept loop to locate the periodic 1 s stall
davidschachterADFA 3968a4b
ADFA-5172: Stop reporting an idle wait in accept() as a stall
davidschachterADFA d955b9b
Merge branch 'stage' into bugfix/ADFA-5172-webserver-accept-stalls
davidschachterADFA df93f25
ADFA-5172: Flatten the accept loop, and pin the report's boundaries
davidschachterADFA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
app/src/test/java/com/itsaky/androidide/localWebServer/AcceptWaitReportingTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package com.itsaky.androidide.localWebServer | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import org.junit.Test | ||
| import java.util.concurrent.TimeUnit | ||
|
|
||
| /** | ||
| * Covers when a wait in accept() is worth a log line (ADFA-5172). Waiting is the normal state of a | ||
| * server with nothing to do, so the interesting case is narrow: long enough to be a retransmitted | ||
| * handshake, short enough not to be an idle server, and arriving in the middle of steady traffic. | ||
| */ | ||
| class AcceptWaitReportingTest { | ||
| private val thresholdMs = 200L | ||
|
|
||
| // Every path is given explicitly: ServerConfig's defaults reach for external storage, which a | ||
| // JVM test has no stub for. | ||
| private fun server(stallThresholdMs: Long = thresholdMs) = | ||
| WebServer( | ||
| ServerConfig( | ||
| port = 0, | ||
| databasePath = "/nonexistent/test.db", | ||
| fileDirPath = "/tmp", | ||
| debugDatabasePath = "/nonexistent/debug.db", | ||
| debugEnablePath = "/nonexistent/debug-flag", | ||
| experimentsEnablePath = "/nonexistent/exp-flag", | ||
| clearCacheEnablePath = "/nonexistent/cs0-flag", | ||
| projectDatabasePath = "/nonexistent/recent-projects.db", | ||
| stallThresholdMs = stallThresholdMs, | ||
| ), | ||
| ) | ||
|
|
||
| private fun millis(value: Long) = TimeUnit.MILLISECONDS.toNanos(value) | ||
|
|
||
| private val noPreviousIteration = -1L | ||
|
|
||
| @Test | ||
| fun `a one second wait between promptly served requests is the stall being hunted`() { | ||
| assertThat(server().shouldReportAcceptWait(millis(1_020), previousAcceptWaitNanos = millis(0))).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `the first request after startup is never reported, however long the wait`() { | ||
| assertThat(server().shouldReportAcceptWait(millis(74_000), noPreviousIteration)).isFalse() | ||
| assertThat(server().shouldReportAcceptWait(millis(1_020), noPreviousIteration)).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a wait after an already long wait is an idle server, not a stall`() { | ||
| assertThat(server().shouldReportAcceptWait(millis(1_020), previousAcceptWaitNanos = millis(30_000))).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a wait far past the retransmission ladder is nobody browsing`() { | ||
| assertThat(server().shouldReportAcceptWait(millis(60_000), previousAcceptWaitNanos = millis(5))).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a wait within the retransmission ladder is still reported`() { | ||
| // 1 s, 3 s and 7 s are Linux's first three SYN retransmissions. | ||
| assertThat(server().shouldReportAcceptWait(millis(3_100), previousAcceptWaitNanos = millis(5))).isTrue() | ||
| assertThat(server().shouldReportAcceptWait(millis(7_200), previousAcceptWaitNanos = millis(5))).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `an ordinary wait below the threshold is not reported`() { | ||
| assertThat(server().shouldReportAcceptWait(millis(30), previousAcceptWaitNanos = millis(5))).isFalse() | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| fun `the threshold itself is inclusive, and one millisecond under it is not reported`() { | ||
| val server = server() | ||
|
|
||
| assertThat(server.shouldReportAcceptWait(millis(thresholdMs - 1), previousAcceptWaitNanos = millis(5))).isFalse() | ||
| assertThat(server.shouldReportAcceptWait(millis(thresholdMs), previousAcceptWaitNanos = millis(5))).isTrue() | ||
| assertThat(server.shouldReportAcceptWait(millis(thresholdMs + 1), previousAcceptWaitNanos = millis(5))).isTrue() | ||
| } | ||
|
|
||
| @Test | ||
| fun `the ten second ceiling is inclusive, and one millisecond over it is an idle server`() { | ||
| val server = server() | ||
|
|
||
| assertThat(server.shouldReportAcceptWait(millis(9_999), previousAcceptWaitNanos = millis(5))).isTrue() | ||
| assertThat(server.shouldReportAcceptWait(millis(10_000), previousAcceptWaitNanos = millis(5))).isTrue() | ||
| assertThat(server.shouldReportAcceptWait(millis(10_001), previousAcceptWaitNanos = millis(5))).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `the previous wait counts as steady load right up to the threshold`() { | ||
| val server = server() | ||
|
|
||
| assertThat(server.shouldReportAcceptWait(millis(1_020), previousAcceptWaitNanos = millis(thresholdMs - 1))).isTrue() | ||
| assertThat(server.shouldReportAcceptWait(millis(1_020), previousAcceptWaitNanos = millis(thresholdMs))).isFalse() | ||
| } | ||
|
|
||
| @Test | ||
| fun `a zero or negative threshold silences the accept-wait report instead of flooding it`() { | ||
| // "The previous iteration waited less than the threshold" cannot hold when the threshold is | ||
| // zero, so this branch goes quiet rather than reporting every wait. A negative threshold is | ||
| // clamped to zero and behaves the same. The busy-phase report, which has no such | ||
| // precondition, does fire for every iteration at these settings. | ||
| assertThat(server(stallThresholdMs = 0).shouldReportAcceptWait(millis(1_020), previousAcceptWaitNanos = 0)).isFalse() | ||
| assertThat(server(stallThresholdMs = -5).shouldReportAcceptWait(millis(1_020), previousAcceptWaitNanos = 0)).isFalse() | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.