Skip to content

ENG-1678: Pilot fiber-based Sidekiq processing for Front queues - #1

Draft
alextrueman wants to merge 2 commits into
mainfrom
alex/eng-1678-front-fibers
Draft

alextrueman wants to merge 2 commits into
mainfrom
alex/eng-1678-front-fibers

Conversation

@alextrueman

@alextrueman alextrueman commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Replace the shared processor and per-job marker with bounded capsule-level runners that reuse upstream dispatch, middleware, retry, and acknowledgment. Preserve child-fiber routing and recover unfinished jobs at shutdown. Pin supported runtime versions; replace custom per-job Redis statistics and dashboard with standard reporting and periodic runtime metrics.

Verification: 23 standalone examples pass locally; application integration passes 188 affected examples using the immutable runtime pin. The application covers Rails isolation, Pro batches/expiry, Enterprise uniqueness/retries, busy reporting, drain/deadline, real SIGKILL recovery, persistent HTTPS failures/cancellation, and shared Redis limiter contention.

Crash recovery matched the threaded baseline: original JIDs recovered after natural heartbeat/cleanup expiry and another startup, about 65 seconds after kill. Immediate replacement alone did not recover work in the observed window; delivery remains at least once.

The application completed 38 representative local benchmark runs (1,752 jobs accounted for, only 60 intentionally triggered retries, zero leftover receipts). No clear local fiber benefit: throughput is similar, CPU higher, RSS slightly higher. The benchmark also caught an application HTTP checkout timeout issue, fixed and regression-tested in the companion PR. Full results and repeatable command are there.

Local verification gaps are closed. Keep production execution opt-in/default-threaded; a separate real-workload pilot is still required before claiming benefit. No production activation, merge, or deployment performed.

Ticket: https://linear.app/lugg/issue/ENG-1678/pilot-fiber-based-sidekiq-processing-for-front-queues

Application integration and benchmark results: https://github.com/lugg/api/pull/3908

@erickreutz erickreutz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I ran 102 local benchmarks covering 190,920 jobs, comparing ordinary Sidekiq threads, this fiber implementation, and fibers with an experimental Excon wait change.

I don’t think we have a performance case for shipping the fiber runtime yet. At concurrency 64, median throughput was essentially identical: 598 jobs/sec for threads versus 596 for fibers. Fibers used about 56% more CPU per job and 24% more peak memory. Higher concurrency and slow-response outliers showed the same pattern.

One concrete issue is the Excon/Async interaction: Excon uses IO.select, and the pinned Async version implements that by creating a native thread. These runs created roughly 8,000–9,000 threads per 6,400 jobs. Switching the single-socket waits to wait_readable/wait_writable eliminated that churn and brought CPU close to the threaded baseline, but still didn’t produce an advantage.

Connection reuse looks more promising. In the threaded comparison at concurrency 64, persistent connections reduced CPU about 70% and improved throughput about 9%. These are synthetic local HTTPS results, so we still need to validate the actual Rails/Front workload on Linux with our middleware and rate limiter.

My suggestion is to narrow the companion API PR to the persistent Front connection pool and measurements, covering both front and front_bulk on ordinary Sidekiq threads. Defer the separate process introduced for fiber isolation.

For this gem, I’d keep it experimental while we address the socket-wait overhead and the child-task cancellation issue identified above. Then compare it against an equally pooled threaded baseline under the same resource limits. We should require a repeatable throughput or resource benefit before adding the runtime complexity.

@alextrueman

Copy link
Copy Markdown
Collaborator Author

@erickreutz Followed your recommendation: API PR #3908 now keeps HTTP pooling on ordinary Sidekiq threads for front and front_bulk. No fiber dependency or dedicated worker. This fork remains experimental; runtime follow-ups are deferred.

Completed the Linux comparison using actual Rails Front jobs, Redis fetching, Pro/Enterprise middleware, and the limiter against synthetic HTTPS. 62 runs / 11,544 jobs; five alternating-order pairs per scenario, 192 jobs/run. HTTP pool matches concurrency; DB pool stays at 4; identical seeds and warm tag caches.

Per-mode medians, unpooled → pooled:

Scenario Concurrency CPU ms/job Jobs/sec
Fast, 50 ms 4 8.046 → 4.441 46.378 → 49.316
Fast, 50 ms 16 6.105 → 4.227 118.396 → 142.170
Slow, 1 s 4 13.077 → 8.691 2.932 → 2.937
Slow, 1 s 16 8.924 → 6.159 10.873 → 10.993
Mixed 429/500 4 8.624 → 5.757 38.120 → 41.577
Mixed 429/500 16 6.509 → 5.550 100.506 → 108.150

CPU/job improved in all 30 repeated pairs. No meaningful throughput regression; peak RSS roughly unchanged. CPU excludes boot/shutdown and includes failed attempts. Matched request counts/outcomes; 400 intentional retries, zero unacknowledged jobs. All CI passed.

The scenarios above use a test-only 6,000/minute allowance. The separate 12-job, 40/minute control had unchanged throughput (~0.663 jobs/sec) but 13.5% higher CPU/job with pooling (24.592 → 27.904 ms). One pair is insufficient for a resource verdict; production savings remain unproven.

An initial slowdown was a fixture artifact: separate header/body writes added ~40 ms on persistent Linux sockets. Server-only controls isolated it; the fixture now writes headers/body together. Results above use that correction, with no production-client tuning.

CI run and raw/summary artifacts, PR head 4f2482cb8, tested merge 81f590d938.

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