Everything you ever wanted to know about threads...
summary
Ruby 1.8’s green threads use setitimer and signal handlers so a single spawned thread leaves a periodic setitimer/sigvtalrm interrupt running forever; tracing finds 3.5 million sigprocmask calls in 100s and huge memcpy costs copying kilobyte-sized stack frames. Patches stop the timer, add a zero-copy stack patch that mmaps stacks and swaps the stack pointer, eliminate the memcpy, cut CPU syscalls, and turn a 7,400s ring benchmark into about 13 minutes while improving many workloads ~30%.
AI-written summary · about
chapters (15)
- 0:00Start
- 1:27What is a thread?
- 2:08Green Threads (1:N)
- 3:15Native Threads (1:1)
- 4:08Hybrid Threads (M:N)
- 7:59Let's strace ruby..
- 10:04PATCH: stop the thread timer
- 18:39Stack vs. Heap
- 21:03gdb walkthrough
- 22:06What's on the ruby stack?
- 23:07How big is the stack?
- 25:04Recap: How do Ruby threads work?
- 27:22Benchmark
- 30:42rb_thread_schedule() sucks
- 31:59Ruby Enterprise Edition
related talks
47mWhat All Rubyists Should Know About Threads
24mDIY::Thread.profile -- Light-Weight Profiling in Pure Ruby
29mDiscussion on Thread between version 1.8.6 and 2.2.3
38mScaling Ruby with Actors, or How I Learned to Stop Worrying and Love Threads
42mLook out! Gotchas of Using Threads in Ruby
23mParallel Processing With Ruby
36mDebugging Ruby
29mHow the Ruby Global VM Lock impacts app performance
