Skip to content

Optimize in-memory job acquisition and queries - #232

Merged
viceroypenguin merged 1 commit into
mainfrom
perf/in-memory-job-storage
Oct 16, 2026
Merged

viceroypenguin merged 1 commit into
mainfrom
perf/in-memory-job-storage

Conversation

@viceroypenguin

@viceroypenguin viceroypenguin commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Fair acquisition repeatedly scans the entire job store and rebuilds eligible groups for every claim. Build ordered group backlogs and active counts once per queue acquisition, then advance the selected group and update active counts and round-robin sequences after each claim. Cache definition eligibility within the locked acquisition and invalidate it after each successful claim so rate and concurrency limits remain enforced.

Use dictionary lookup for exact job handles, apply query filters and paging before copying records, and count monitoring states in one pass. Add six regression cases covering exhausted definition limits and request capacities across groups, noisy-group reclassification within a batch, and exact-handle filters with updated queue metadata.

Performance

Local Release microbenchmark on .NET 10.0.13, compiled with SDK 11.0.100-preview.7.26381.103. Medians of 11 measurements after three warmups, excluding setup, disposal, and explicit GC. Each measurement uses a fresh store containing 50,000 jobs: 5,000 due pending jobs and 45,000 succeeded jobs, split across two definitions and 20 groups in one queue. Acquisition batch size is 64; filtered paging returns 25 pending jobs of one definition after skipping 100. Results are workload-specific and do not measure contention.

Operation Before After
Fair acquisition of 64 jobs 256.65 ms 7.01 ms
Filtered page query 7.05 ms 1.51 ms
Monitoring snapshot 7.06 ms 3.91 ms
Ordinary acquisition of 64 jobs 3.49 ms 3.49 ms

Fair acquisition allocations decrease from 144,109,704 to 569,656 bytes (99.6% reduction).

Validation

  • Shared project Release builds pass for net8.0, net10.0, and net11.0.
  • All 98 in-memory storage conformance and regression tests pass on .NET 10.
  • All 92 CapturingJobStorage conformance cases pass on .NET 10.
  • git diff --check passes.

Summary by CodeRabbit

  • Performance
    • Job acquisition and monitoring queries now process in-memory job data more efficiently.
  • Bug Fixes
    • Fair job acquisition now advances past definitions that have no available capacity and updates group selection after each claim.
    • Job queries now combine filters consistently and report a job’s current queue after its definition changes.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1495ca6-db97-4580-a678-3f4c259aee53
📥 Commits

Reviewing files that changed from the base of the PR and between 7ec85e7 and 337bd03.

📒 Files selected for processing: 3
  • src/Immediate.Jobs.Shared/Storage/InMemoryJobStorage.Acquire.cs
  • src/Immediate.Jobs.Shared/Storage/InMemoryJobStorage.Query.cs
  • tests/Immediate.Jobs.StorageTests/InMemoryStoragePerformanceRegressionTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The in-memory job storage acquisition, monitoring, and query paths now reduce repeated eligibility checks, scans, or record conversions. Regression tests cover acquisition ordering under capacity limits and query filtering after a job definition’s queue changes.

Changes: In-memory job storage

Layer / File(s) Summary
Job acquisition selection
src/Immediate.Jobs.Shared/Storage/InMemoryJobStorage.Acquire.cs, tests/Immediate.Jobs.StorageTests/InMemoryStoragePerformanceRegressionTests.cs
Acquisition paths cache eligibility checks. Fair acquisition uses per-group backlogs and tracks active jobs as it selects jobs. Tests cover capacity limits, group ordering, and acquisition helpers.
Monitoring and job queries
src/Immediate.Jobs.Shared/Storage/InMemoryJobStorage.Query.cs, tests/Immediate.Jobs.StorageTests/InMemoryStoragePerformanceRegressionTests.cs
Monitoring counts job states in one pass. Query methods filter stored records before converting results. Tests check combined filters and the current queue after a job definition changes.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to 337bd

The acquisition and query changes have no identified issue requiring resolution before merge; normal build and test checks still apply.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main changes to in-memory job acquisition and query paths.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 38971347490

Coverage decreased (-0.02%) to 92.044%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 59 of 59 lines across 2 files are fully covered (100%).
  • 5 coverage regressions across 2 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

5 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
src/Immediate.Jobs.EntityFrameworkCore/EntityFrameworkCoreJobStorage.Lifecycle.cs 4 93.21%
src/Immediate.Jobs.LinqToDB/LinqToDBJobStorage.Lifecycle.cs 1 93.01%

Coverage Stats

Coverage Status
Relevant Lines: 17697
Covered Lines: 16289
Line Coverage: 92.04%
Coverage Strength: 2.98 hits per line

💛 - Coveralls

@viceroypenguin
viceroypenguin merged commit 91c36be into main Oct 16, 2026
2 of 3 checks passed
@viceroypenguin
viceroypenguin deleted the perf/in-memory-job-storage branch October 16, 2026 22:52
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