Take Away
Good discussion of the different facilities available to Ruby and the underlying operating system and their tradeoffs.
Introduction
Aman Gupta - Joe Damato - Threads
http://timetobleed.com Joe's blog.
Fundamentals
What is a thread?
A thread is just a set of execution state.
Models
- Green threads
- Native
- Hybrid
Green 1:N
- Lightweight
- Kernel doesn't know they exist
- Implementation is in userland.
Pros
- Create lots cheaply
- Switch them.
- Schedule them however you want.
Cons
- Main one is that these can switch only between a single Ruby process.
Native Threads 1:1
- Kernel knows they exist
- Some user land code.
Pros
- Take advantage of SMP
- Shared memory
- Blocking in one thread doesn't block
Cons
- didn't get
Hybrid Threads (M;N)
Pros
- Take advantage of SMP
- Cheap setup and teardown
Cons
- Need 2 schedulers
Ruby 1.9 and Erlang use hybrid threads
Preemptive Multitasking
- Operating system switches process regardless of process states.
Cooperative Multitasking
- thread gives up voluntarily.
Fibers
Tools
- strace
- google-perf
lsof - "list of open files" - a utility. Can also be used to get a list of open sockets.
strace
trace system calls and signals.
Ruby: SIGVTALRM used
github.com/ice799/matzruby
- heap_stcks branch
- heap_stacks_186 branch
github.com/tmm1/ruby187
- fibers branch
No comments:
Post a Comment