I’ve spent a past few weeks doing thing with Ruby that I didn’t think the little scripting language can do (namely SSDP and UPnP). I have to admit that it’s very powerful, though not very well documented unless you bother spending some money on books. This doesn’t guarantee that you will learn about those undocumented features nobody but THE Ruby developers know about. For example the whole Socket family of classes is shrouded in mystery, and if you didn’t know how to do socket programing in Windows/Linux/UNIX you are up the creek without a paddle. For example in order to send a multicast group join you have to pass obscure structures into sock_options function and depending on which platform you’re on this structure changes. But enough about obscure sockets. Let’s talk about threads.
Threads in Ruby (1.8.7) are useless to the point of being unusable. Threads in Ruby does not translate into native threads on Windows, or POSIX threads, or anything that resembles threads in traditional sense. You just get a pseudo-asynchronous execution of blocks that all run in the same thread. It’s all runing in the same thread. You block one, you block all. One blocks up, the rest will just block and leave you scratching your noggin for hours. Awesome!
FYI: “Thread.abort_on_exception = true” is your friend.
When using Ruby to build heavy server applications (not Rails, it’s a different story) and attempting to take advantage of multi-core, hyper-threaded goodness of your monstrosity you’ll be suprised to find Ruby huddled in the corner chugging along as if you were running a single core, non hyper-threaded box. It’s comical to watch Ruby max out to 25% usage on quad-core box because the other 3 cores are inaccessible to it. There are arguments to be made for Green Threads (Java used them in medieval days, sometime around plague or Henry the VIII) but last I checked it’s 2007. Yarv (aka Ruby 1.9) will have native-ish Threads implemented so we’ll see how the code runs in an actual threaded environment. For now I’ll rely on multiple Ruby instances and DRb
Posted by mzolin 

