Skip to content

perf(software): cap parallel Fleet calls at 8 per api pod - #2507

Closed
semen-flamingo wants to merge 1 commit into
mainfrom
feature/fleet-calls-cap
Closed

semen-flamingo wants to merge 1 commit into
mainfrom
feature/fleet-calls-cap

Conversation

@semen-flamingo

Copy link
Copy Markdown
Contributor

What

With openframe.rmm.software.fleet-paging.enabled on (#2484), a few Software Management tabs call Fleet in parallel: one call per software version, or one per row on the page.

One Fleet serves every tenant and their agents. On prod it has 1 CPU and a shared MySQL pool. One click on a title with many versions could send it ~40–80 calls at once.

FleetCalls now lets at most 8 Fleet calls run at a time per api pod; the rest queue. The cap is shared across requests, so several users clicking at once still stay under 8. Results keep their order, and a failing call still throws its own exception.

Measured on QA: versions per software title have a median of 1, p90 of 4, p99 of 9 and a max of 38 (AdGuard). The worst case becomes 5 waves of ~0.1–0.3 s.

Fleet calls per screen, before and after #2484

QA numbers:

  • Fleet holds 2365 titles for the tenant and more than 5000 CVEs;
  • Google Chrome has 8 versions and 381 CVEs;
  • the top CVE is on 8 devices;
  • a page is 20 rows.

The "snapshot" means ⌈hosts/100⌉ calls to /hosts?populate_software=true. Each call returns 100 hosts with all their software. The snapshot is cached for 2 min per pod, and it is what runs prod api pods out of heap.

Screen Before: calls (at once) Flag on + this PR: calls (at once)
All Software, open (list + facet) 10 + snapshot (1) 1 (1)
All Software, each next page 5 (1) 1 (1)
Vulnerabilities 10 + snapshot (1) 1 (1)
Software detail 2 (1) 1 (1)
Software → Vulnerabilities, Chrome 382 (1–2) 9 (≤ 8)
Software → Devices, Chrome (list + facet) 18 (1) 18 (≤ 8)
CVE detail, CVE on 8 devices 9 + snapshot (1) 2 (1)
CVE → Devices snapshot 2 (1)
Device → Software 6 + snapshot (1) 22 (≤ 8)
Device → Vulnerabilities 1 + snapshot (1) 22 (≤ 8)

The two device tabs make more calls than before. But each call is a light lookup of one title or one CVE, while before the tab built or reused the snapshot of every host's software.

Tests

  • FleetCallsTest: 30 calls never exceed 8 in flight, results keep key order, and the failing call's exception is rethrown.
  • The inventory tests in both flag modes are unchanged and green (83 tests).

🤖 Generated with Claude Code

https://claude.ai/code/session_011SqwrRpyZt3bP1sWEUYr2P

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦩 Flamingo Code Review

1 finding(s) — 1 action required · 0 recommended · 0 informational

Mode: advisory · Rules cited: OFJAVA-014

Inline comments: 1 new


Need another pass? Commits pushed after this review are not reviewed automatically.

  • Review the new commits — the commits added since this review
  • Review the whole diff again — ignoring what was already reviewed

Prefer typing? Comment @flamingo-review, or @flamingo-review full. To review every push on this pull request, add the flamingo-review-always label.

React 👍/👎 on inline comments to teach the reviewer.

Started 2026-10-01 14:28 UTC · updated 2026-10-01 14:30 UTC · workflow run

Comment on lines +31 to +38
private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException {
IN_FLIGHT.acquire();
try {
return call.apply(key);
} finally {
IN_FLIGHT.release();
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🦩 🔴 [error/action_required] OFJAVA-014 limited() declares a checked throws InterruptedException, violating the unchecked-exceptions rule and losing the interrupt status

The new private method limited is declared throws InterruptedException, a checked exception. Per OFJAVA-014 all exceptions in this codebase must be unchecked, with no throws clauses in signatures. Worse, because this call runs inside executor.submit(() -> limited(call, key)), the InterruptedException is captured by the Future and only surfaces later through resultOf, which only special-cases RuntimeException — an InterruptedException thrown by IN_FLIGHT.acquire() is not a RuntimeException, so future.resultNow() will throw IllegalStateException (wrong state) instead of propagating the real cause, and the thread's interrupt status is silently lost (never re-set with Thread.currentThread().interrupt()). This can turn a shutdown/interrupt signal into a confusing IllegalStateException, and defeats cooperative cancellation of the virtual-thread pool.

Evidence
    private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException {
        IN_FLIGHT.acquire();
        try {
            return call.apply(key);
        } finally {
            IN_FLIGHT.release();
        }
    }

📝 Committable suggestion

Suggested change
private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException {
IN_FLIGHT.acquire();
try {
return call.apply(key);
} finally {
IN_FLIGHT.release();
}
}
private static <T, R> R limited(Function<T, R> call, T key) {
try {
IN_FLIGHT.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IllegalStateException("interrupted while waiting for Fleet call slot", e);
}
try {
return call.apply(key);
} finally {
IN_FLIGHT.release();
}
}
🤖 Prompt for AI agents
In openframe-api-lib/src/main/java/com/openframe/api/service/rmm/fleet/FleetCalls.java around lines 31-38, address this code-review finding: limited() declares a checked throws InterruptedException, violating the unchecked-exceptions rule and losing the interrupt status.
The new private method `limited` is declared `throws InterruptedException`, a checked exception. Per OFJAVA-014 all exceptions in this codebase must be unchecked, with no `throws` clauses in signatures. Worse, because this call runs inside `executor.submit(() -> limited(call, key))`, the InterruptedException is captured by the Future and only surfaces later through `resultOf`, which only special-cases RuntimeException — an InterruptedException thrown by `IN_FLIGHT.acquire()` is not a RuntimeException, so `future.resultNow()` will throw `IllegalStateException` (wrong state) instead of propagating the real cause, and the thread's interrupt status is silently lost (never re-set with `Thread.currentThread().interrupt()`). This can turn a shutdown/interrupt signal into a confusing IllegalStateException, and defeats cooperative cancellation of the virtual-thread pool.
The flagged code:
```
    private static <T, R> R limited(Function<T, R> call, T key) throws InterruptedException {
        IN_FLIGHT.acquire();
        try {
            return call.apply(key);
        } finally {
            IN_FLIGHT.release();
        }
    }
```
A suggested replacement for the flagged range:
    private static <T, R> R limited(Function<T, R> call, T key) {
        try {
            IN_FLIGHT.acquire();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException("interrupted while waiting for Fleet call slot", e);
        }
        try {
            return call.apply(key);
        } finally {
            IN_FLIGHT.release();
        }
    }
Make the minimal change that resolves the finding; do not refactor unrelated code.

confidence: verifier 75 · author 78 — react 👍/👎 to teach the reviewer

@aliaska-varieva

Copy link
Copy Markdown
Contributor

Closing as stale: no activity for over a week. Reopen if still needed.

@aliaska-varieva
aliaska-varieva deleted the feature/fleet-calls-cap branch November 9, 2026 01:23
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.

2 participants