Ruby Fibers Vs Ruby Threads
1
Ruby 1.9 fibers are touted as lightweight concurrency elements that are much lighter than threads. I have noticed a sizable impact when I was benchmarking an application that made heavy use of fibers. So I wondered, what if I switched to threads instead? After some time fighting with threads, I decided I needed to write something specific for this comparison. I have written a small application that spawns a number of fibers (or threads) and then returns the time that went into this operation. I also recorded the VM size after the operation (all created fibers and threads are still reachable, hence, no garbage collection). I did not measure the cost of context switching for both approaches; maybe I'll do that another time.
Here are the results for creation time:

And the results for memory usage:

Conclusion:
Fibers are much faster to create than threads; they eat much less memory too. There is also a limit on the number of threads for 1.9, as I maxed on 3070 threads, while fibers were not complaining when I created 100,000 of them (but they took 203 seconds and occupied a whooping 500MB of RAM).
Written By:
Muhammad A. Ali (oldmoe.blogspot.com)
Comments
Post a Comment
eSpace podcast Prodcast
Archive
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

