---
title: "To Thread or Not to Thread: An In-Depth Look at Ruby’s Execution Models"
description: "Threaded Ruby servers like Puma and Sidekiq save memory over forking servers, but the gap is smaller than RSS suggests once copy-on-write sharing is measured properly with PSS and /proc/$PID/smaps_rollup."
url: "https://swe.quest/articles/to-thread-or-not-to-thread-an-in-depth-look-at-ruby-s-execution-models-18ca691643d5cc44"
canonical: "https://shopify.engineering/ruby-execution-models"
source: "Shopify Engineering"
published: "2022-05-31"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 15
tags: ["ruby","concurrency","memory-management","performance","runtimes"]
---

# To Thread or Not to Thread: An In-Depth Look at Ruby’s Execution Models

A post on [Shopify Engineering](https://swe.quest/sources/shopify.md), published 2022-05-31, 15 min read, Deep dive. Original: [https://shopify.engineering/ruby-execution-models](https://shopify.engineering/ruby-execution-models)

## Summary

Threaded Ruby servers like Puma and Sidekiq save memory over forking servers, but the gap is smaller than RSS suggests once copy-on-write sharing is measured properly with PSS and /proc/$PID/smaps\_rollup. In one Shopify production app an extra Unicorn worker cost about 427MiB versus about 257MiB for an extra thread, not the ~750MiB RSS implied, and preloading plus eager loading improves CoW efficiency. Processes still offer clean request timeouts and avoid Global VM Lock contention, which hurts latency more than commonly assumed because Ruby web requests are less I/O-heavy than believed and GC also holds the GVL. Ractors and Fibers are not drop-in replacements, and a proposed GVL instrumentation API for Ruby 3.2 would let teams measure the latency cost of threads.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Ruby](https://swe.quest/tags/ruby.md) (Languages)
- [Concurrency](https://swe.quest/tags/concurrency.md) (Compilers & runtimes)
- [Memory management](https://swe.quest/tags/memory-management.md) (Compilers & runtimes)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)

## Prerequisites

- Ruby on Rails deployment ([easy posts on Ruby](https://swe.quest/tags/ruby.md?difficulty=easy))
- Unix fork and processes
- threads and locks basics

## Keywords

Global VM Lock, Copy on Write, Puma, Unicorn, Sidekiq, Ractors, Proportional Set Size, Ruby heap-profiler

## Related posts

- [Adventures in Garbage Collection: Improving GC Performance in our Massive Monolith](https://swe.quest/articles/adventures-in-garbage-collection-improving-gc-performance-in-our-massive-7c8cc3e83e915743.md): Shopify Engineering · 2023-04-06 · Hard · 13 min read · Memory management, Ruby, Performance engineering, Runtimes & VMs
  Shopify cut Ruby garbage-collection tail latency in its monolith by finding why major GCs were triggered, via GC.latest\_gc\_info(:major\_by), and removing each cause in turn.
- [Performance at GitHub: deferring stats with rack.after\_reply](https://swe.quest/articles/performance-at-github-deferring-stats-with-rack-after-reply-fed8f334f87dc4fe.md): GitHub Engineering · 2022-04-11 · Medium · 3 min read · Ruby, Performance engineering, Observability
  GitHub cut 30ms at p50 and 50ms+ at p99 from every request by buffering statsd metrics during a request and flushing them in one batch through \`rack.after\_reply\`, a hook that runs callables after the full response reaches the client.
- [Evolving our real-time timeseries storage again: Built in Rust for performance at scale](https://swe.quest/articles/evolving-our-real-time-timeseries-storage-again-built-in-rust-for-performance-cbd41a18b9630cd7.md): Datadog Engineering · 2025-08-04 · Hard · 21 min read · Storage engines, Rust, Performance engineering, Databases, Concurrency
  Datadog's sixth-generation real-time timeseries database (RTDB) is a Rust rewrite that unifies two earlier engines, one for scalar metrics and one for DDSketch distributions, after earlier generations built on Cassandra, Redis, MDBM, a Go B+ tree and RocksDB.
- [Code Ranges: A Deeper Look at Ruby Strings](https://swe.quest/articles/code-ranges-a-deeper-look-at-ruby-strings-b87e06d5cb44fa84.md): Shopify Engineering · 2022-04-14 · Hard · 14 min read · Ruby, Runtimes & VMs, Data structures, Performance engineering
  Ruby strings are mutable and encoding-aware across 100+ encodings, so runtimes cache a per-string "code range" (UNKNOWN, 7BIT, VALID, BROKEN) to avoid repeated O(n) validity scans.
- [Announcing Silk: a silky smooth fiber runtime for ClickHouse](https://swe.quest/articles/announcing-silk-a-silky-smooth-fiber-runtime-for-clickhouse-bd3ca633b291b6b6.md): ClickHouse · 2026-06-25 · Hard · 11 min read · Concurrency, Runtimes & VMs, C & C++, Performance engineering, Linux
  Silk is a C++ stackful-fiber runtime for ClickHouse. It pins one scheduler thread per CPU, uses io\_uring as its I/O foundation, steals work in order of CPU topology cost (hyperthread sibling, then same socket, then cross-socket), and does zero heap allocation in the steady-state hot path through mmap'd stack pools, stack-resident futures and intrusive containers.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
