website logo

← All articles

Solid Queue's Fiber Async Mode: Unshackling Threads for LLM-Heavy Loads

Unleash the power of fibers in your AI-backed Rails app features.

If you’ve wired LLM features into Rails over the past year, you’ve likely hit this scene: a ChatCompletionJob gets dropped into the queue, and then a worker thread sits there, pinned, waiting for OpenAI or Anthropic to dribble back a streaming response token by token. The thread isn’t doing anything: it’s just waiting on network I/O. Ramp up concurrency and the thread pool saturates, the database connection pool follows suit, and you know damn well the CPU is basically idle.

Solid Queue 1.6.0’s fiber execution mode is aimed squarely at this problem. At top level, what you need to understand isn’t just “flip a config switch” but rather it’s how this changes the economics of I/O-bound queues at the architectural level.

What Solid Queue’s Fiber Async Mode Actually Is

First, a distinction that trips people up: Solid Queue has two different layers of “async”

Supervisor Mode’s async refers to the supervisor running workers, dispatchers, and schedulers on threads rather than forked processes. This mode returned in v1.3.0, primarily to save memory, and the official recommendation still favors the default fork mode.

The fiber execution mode in v1.6.0, by contrast, is a change to the concurrency model inside the worker: instead of a thread pool running jobs, multiple fibers run on a single fiber reactor thread. In configuration, you replace threads: with fibers:. These two are completely independent: you can safely use fiber workers under the default fork supervisor mode.

For LLM workloads, we’re talking about the latter.

How It Works: From Thread Blocking to Cooperative Yielding

In the traditional thread model, a job occupies an OS thread. When that job fires off an HTTP request and waits for the LLM to respond, the thread enters a blocked state. While MRI’s GVL does allow other threads to run during I/O waits, each thread still carries its own memory stack overhead (typically 1–2 MB), and the thread count directly dictates the floor for your database connection pool. 100 concurrent LLM calls means 100 threads and at least matching connection pressure.

Fiber mode flips this model. It relies on the reactor provided by the async gem under the hood, with all jobs running as fibers on a single thread. When a fiber hits a scheduler-aware I/O operation (like an HTTP request or database query), it voluntarily yields control, and the reactor immediately switches to another ready fiber. The wait time on LLM streaming responses gets used to push forward dozens or hundreds of other jobs.

The actual configuration looks like this:

# config/queue.yml
production:
  workers:
    - queues: "llm_streaming"
      fibers: 100
      polling_interval: 0.05
    - queues: "default"
      threads: 5

You also need to enable fiber isolation in config/application.rb:

config.active_support.isolation_level = :fiber

And add gem "async" to your Gemfile. Without this isolation setting, Rails’ CurrentAttributes and IsolatedExecutionState share state at the thread level, leading to hard-to-reproduce data leakage bugs.

Why LLM Streaming HTTP Responses Are a Perfect Fit for Fiber Mode

LLM API calls have a very distinct profile: extremely long I/O waits, extremely short CPU computation. A streaming conversation might last 5 to 30 seconds, with 99% of that time spent waiting for network packets.

Thread mode is pure waste here. What you’re paying for is thread stack memory, OS scheduling overhead, and linear growth in the database connection pool. The benchmark data is telling: in a scenario with 6 worker processes at 50 concurrency each, thread mode required configuring 312 queue database connections; the same configuration with fibers needs only 18. On ActiveRecord 7.2+, Solid Queue’s connection pool estimate for fiber workers is fixed at 3 and doesn’t balloon with the fibers: value. For teams running on Render, Fly.io, or PlanetScale with connection limits, this math directly determines your billing tier.

Streaming responses introduce another pain point under thread mode: long-tail blocking. A slow streaming connection occupies a thread until it finishes, during which that thread can’t process any new jobs. In fiber mode, 100 fibers can be “in flight” simultaneously, each waiting on its own token stream, with the reactor rotating among them efficiently. Solid Queue’s benchmarks show LLM streaming workloads gain roughly 12% average throughput in fiber mode, reaching 22% under optimal configuration.

But the real killer feature is stability. Under stress tests from 25 to 200 concurrent jobs, fiber mode completed all 10 test cells; thread mode completed only 1 before collapsing under connection pressure. LLM application traffic tends to be bursty, and this robustness difference matters more in production than average throughput numbers.

Key Decisions for Production Rollout

Fiber mode isn’t a silver bullet, and its boundaries are clear.

Only use fibers for pure I/O queues. CPU-intensive jobs (image processing, large file serialization, complex computation) gain nothing in fiber mode, benchmarks show differences within the noise range. More dangerously, a blocking C extension call will stall the entire reactor thread, halting all in-flight fibers on that worker. Keep CPU work and potentially blocking gems on separate thread workers.

Reassess your database connections. In fiber mode, ActiveRecord connections are released between queries, so you don’t need to size the pool to match the fiber count. But if you hold long transactions in your jobs, manually call lease_connection, or wrap the entire LLM call in a with_connection block, connections get pinned, and fiber’s concurrency advantage gets eaten by connection pool queuing. Make sure to release any database connections before initiating the LLM request.

You can lower the polling interval. The polling_interval: 0.05 in the example lets the reactor pick up new jobs more frequently, which helps with latency-sensitive streaming scenarios but increases database polling pressure. Start with 0.1 or 0.05 and adjust based on observed load.

Closing Thoughts

Solid Queue’s fiber mode was contributed by Carmine Paolino, the author of RubyLLM, and he was blunt in his implementation notes: he needed Rails background jobs to handle long-running LLM streams without allocating a worker thread per conversation. This feature started from a community pain point and ultimately landed in the official version of Rails’ default queue.

As a technical leader, the lens through which you should evaluate this feature goes beyond “what config do I change.” It fundamentally redefines the unit of concurrency in background queues: from OS threads to user-space fibers, transferring the cost of waiting time from hardware resources to the scheduler. For LLM-heavy Rails applications, this may be the most worthwhile queue-layer architectural adjustment you make this year.