Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Inside Rails Boot: Puma's Role in Initialization

Inside Rails Boot: Puma's Role in Initialization

Trace what happens when you run `rails server`! From Rails boot to Puma launch, uncover how components load, signals fire, plugins initialize, and requests are handled.

RubyConf India 2025

Udbhav Gambhir

October 01, 2025

Transcript

29 slides
  1. 9 / 2 1 / 2 0 2 5 1

    INSIDE THE RAILS BOOT PROCESS: UNPACKING PUMA’S ROLE IN RAILS SERVER INITIALIZATION
  2. H O W D O Y O U S TA

    R T T H E P U M A ? ❑ rails server ❑ foreman (via Procfile) ❑ puma-dev ❑ pumactl ❑ bundle exec puma ❑ Any other...? 9 / 2 1 / 2 0 2 5 3
  3. P O S T-T E A M Y S T

    E R Y: W H AT H A P P E N S A F T E R R A I L S S E R V E R ? 9 / 2 1 / 2 0 2 5 4
  4. 9 / 2 1 / 2 0 2 5 5

    if Object.const_defined?(:Rackup) && ::Rackup.const_defined?(:Handler) module Rackup module Handler module Puma class << self include ::Puma::RackHandler end end register :puma, Puma end end else do_register = Object.const_defined?(:Rack) && ::Rack.release < '3' module Rack module Handler module Puma class << self include ::Puma::RackHandler end end end end ::Rack::Handler.register(:puma, ::Rack::Handler::Puma) if do_register end
  5. 9 / 2 1 / 2 0 2 5 6

    # rackup was removed in Rack 3, it is now a separate gem if Object.const_defined?(:Rackup) && ::Rackup.const_defined?(:Handler) module Rackup module Handler module Puma class << self include ::Puma::RackHandler end end register :puma, Puma end end else do_register = Object.const_defined?(:Rack) && ::Rack.release < '3' module Rack module Handler module Puma class << self include ::Puma::RackHandler end end end end ::Rack::Handler.register(:puma, ::Rack::Handler::Puma) if do_register end
  6. B U N D L E E X E C

    P U M A 9 / 2 1 / 2 0 2 5 9
  7. P U M A C O N T R O

    L F L OW 9 / 2 1 / 2 0 2 5 10
  8. P O S T-T E A M Y S T

    E R Y: W H AT H A P P E N S A F T E R R A I L S S E R V E R ? 9 / 2 1 / 2 0 2 5 11
  9. P U M A C O N T R O

    L F L OW 9 / 2 1 / 2 0 2 5 12
  10. L E T ' S K E E P I

    T S I M P L E ! ❑ Load the entire application ❑ Start all the background plugins ❑ Starts Control Server ❑ Start Server 9 / 2 1 / 2 0 2 5 13
  11. 9 / 2 1 / 2 0 2 5 14

    while true @requests_count += 1 handle_request(client, requests + 1)
  12. 9 / 2 1 / 2 0 2 5 15

    I T ' S A S C A L I N G P R O B L E M !
  13. 9 / 2 1 / 2 0 2 5 16

    while true @requests_count += 1 handle_request(client, requests + 1)
  14. M E M O R Y U S AG E

    ❑ memory_usage = static_memory + (threads * processing_memory) 9 / 2 1 / 2 0 2 5 18
  15. P L E T H O R A O F

    D I S A D VAN TAG E S 9 / 2 1 / 2 0 2 5 19
  16. 9 / 2 1 / 2 0 2 5 20

    G L O BA L V I RT UA L M AC H I N E L O C K ( GV L )
  17. 9 / 2 1 / 2 0 2 5 21

    R A C E C O N D I T I O N S
  18. 9 / 2 1 / 2 0 2 5 22

    FA ULT TO L E R A N C E
  19. 9 / 2 1 / 2 0 2 5 23

    M ULT I -T H R E A D I N G V S M ULT I - P R O C E S S I N G
  20. M E M O R Y U S AG E

    ❑ memory_usage = (static_memory + processing_memory) * processes 9 / 2 1 / 2 0 2 5 24
  21. S O L U T I O N = >

    C oW ( C O P Y O N W R I T E ) 9 / 2 1 / 2 0 2 5 25 ❑ memory_usage = static_memory + (processes * processing_memory)
  22. P U M A C O N T R O

    L F L OW 9 / 2 1 / 2 0 2 5 26
  23. L E T ' S K E E P I

    T S I M P L E ! ❑ Load the entire application ❑ Start all the background plugins ❑ Starts Control Server ❑ Start Server 9 / 2 1 / 2 0 2 5 27
  24. P U M A A N D C oW 9

    / 2 1 / 2 0 2 5 28 def spawn_worker(idx, master) @config.run_hooks(:before_worker_fork, idx, @log_writer) pid = fork { worker(idx, master) } @config.run_hooks(:after_worker_fork, idx, @log_writer) pid end
  25. T H A N K YO U ! 9 /

    2 1 / 2 0 2 5 29

Other Decks in Education