Repository navigation
perf(software): cap parallel Fleet calls at 8 per api pod #2507
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
Closed
Closed
Changes from all commits
Commits
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
56 changes: 56 additions & 0 deletions
56
openframe-api-lib/src/test/java/com/openframe/api/service/rmm/fleet/FleetCallsTest.java
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,56 @@ | ||
| package com.openframe.api.service.rmm.fleet; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| class FleetCallsTest { | ||
|
|
||
| @Test | ||
| void inParallel_moreCallsThanTheCap_neverMoreInFlightAndResultsKeepKeyOrder() { | ||
| // setup | ||
| AtomicInteger inFlight = new AtomicInteger(); | ||
| AtomicInteger peak = new AtomicInteger(); | ||
| List<Integer> keys = IntStream.range(0, 30).boxed().toList(); | ||
|
|
||
| // execution | ||
| List<Integer> results = FleetCalls.inParallel(keys, key -> { | ||
| peak.accumulateAndGet(inFlight.incrementAndGet(), Math::max); | ||
| sleep(30); | ||
| inFlight.decrementAndGet(); | ||
| return key * 10; | ||
| }); | ||
|
|
||
| // verifications | ||
| assertThat(results).containsExactlyElementsOf(keys.stream().map(key -> key * 10).toList()); | ||
| assertThat(peak.get()).isBetween(2, FleetCalls.MAX_IN_FLIGHT); | ||
| } | ||
|
|
||
| @Test | ||
| void inParallel_failingCall_rethrowsItsException() { | ||
| // execution | ||
| IllegalStateException ex = assertThrows(IllegalStateException.class, | ||
| () -> FleetCalls.inParallel(List.of(1, 2), key -> { | ||
| if (key == 2) { | ||
| throw new IllegalStateException("fleet down"); | ||
| } | ||
| return key; | ||
| })); | ||
|
|
||
| // verifications | ||
| assertThat(ex.getMessage()).isEqualTo("fleet down"); | ||
| } | ||
|
|
||
| private static void sleep(long millis) { | ||
| try { | ||
| Thread.sleep(millis); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦩 🔴 [error/action_required]
OFJAVA-014limited() declares a checked throws InterruptedException, violating the unchecked-exceptions rule and losing the interrupt statusThe new private method
limitedis declaredthrows InterruptedException, a checked exception. Per OFJAVA-014 all exceptions in this codebase must be unchecked, with nothrowsclauses in signatures. Worse, because this call runs insideexecutor.submit(() -> limited(call, key)), the InterruptedException is captured by the Future and only surfaces later throughresultOf, which only special-cases RuntimeException — an InterruptedException thrown byIN_FLIGHT.acquire()is not a RuntimeException, sofuture.resultNow()will throwIllegalStateException(wrong state) instead of propagating the real cause, and the thread's interrupt status is silently lost (never re-set withThread.currentThread().interrupt()). This can turn a shutdown/interrupt signal into a confusing IllegalStateException, and defeats cooperative cancellation of the virtual-thread pool.Evidence
📝 Committable suggestion
🤖 Prompt for AI agents
confidence: verifier 75 · author 78 — react 👍/👎 to teach the reviewer