Unicorn Unix Magic Tricks
summary
Unicorn actually implements a pre-forked Ruby web server: master opens listening socket, preload-before-fork loads the Rails app so 16 workers fork in under a second, and workers inherit the socket and call select and accept. Signals adjust worker count (TTYN/TTOU) and a self-pipe trick serializes async handlers into the master loop. Hot reload uses fork then exec while passing raw file descriptors through environment variables so the new master starts serving with zero downtime.
AI-written summary · about
chapters (14)
- 0:00Start
- 4:51Ruby and fork(2)
- 6:36How does Unicorn use fork(2)?
- 9:02Ruby and pipe (2)
- 9:58How does Unicorn use pipe (2)?
- 12:18socket lifecycle
- 13:27select(2)
- 14:02Ruby, sockets and accept(2)
- 16:18Unicorn and sockets
- 19:56Ruby and signal handling
- 20:49Unicorn and signals
- 24:44Scaling workers with signals
- 28:00Hot Reload - #reexec
- 32:59That's why!
related talks
30mGrow Your Unix Beard Using Ruby
21mConquering Massive Traffic Spikes in Ruby Applications with Pitchfork
25mUnderstanding Ruby Web Server Internals: Puma, Falcon, and...
44mRuby Web Application Security Defense in Depth
27mUnicorns die with bullets made of glitter
41mHow Puma Works
29mParticular Particulars about "Zero Downtime Deploys"
39mWhat the fork()?
