Shopify

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

May 31, 2022
To Thread or Not to Thread: An In-Depth Look at Ruby’s Execution Models - Shopify
SummaryAI, from the source post

This post delves into the mechanics and reasoning behind the popularity of threaded servers (like Puma and Sidekiq) in Ruby applications. It explains the memory usage model of web applications, differentiating between static and processing memory, and introduces the concept of Copy-on-Write (CoW) to illustrate how forked processes can share memory. The post critically examines memory metrics like RSS, PSS, and `smaps_rollup` to accurately measure memory usage and improve CoW efficiency. It provides practical advice on configuring servers for full application loading and leveraging `eager_load_namespaces` to improve CoW. Finally, it argues for the continued use of process-based servers (like Unicorn and Resque) by highlighting their advantages in clean timeout mechanisms and resiliency, which are difficult to achieve with threads.

More from the Ruby Execution Models and Threading trail