The dRuby Book
Distributed and Parallel Computing with Ruby
by Masatoshi Seki, translated by Makoto Inoue
Version: P1.0 (March 2012)
Original Japanese edition: dRuby niyoru Bunsan Web Programming by Masatoshi Seki, Copyright 2005. Published by Ohmsha, Ltd. This English translation, revised for Ruby 1.9, is Copyright 2012 Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trust-don't allow othersto use your copy of the book. Thanks.
- Dave & Andy.
Table of Contents
Original Japanese edition:
dRuby niyoru Bunsan Web Programming by Masatoshi Seki
Copyright 2005. Published by Ohmsha, Ltd
This English translation, revised for Ruby 1.9, is Copyright 2012, The Pragmatic Bookshelf.
What Readers Are Saying About The dRuby Book
The dRuby Book is a fantastic introduction to distributed programming in Ruby for all levels of users. The book covers all aspects of dRuby, including the principles of distributed programming and libraries and techniques to make your work easier. I recommend this book for anyone who is interested in distributed programming in Ruby and wants to learn the basics all the way to advanced process coordination strategies.
Eric Hodel |
Ruby committer, RDoc and RubyGems maintainer |
dRuby is the key component that liberates Ruby objects from processesand machine platforms. Masatoshi himself explains its design,features, case studies, and even more in this book.
Yuki Yugui Sonoda |
Ruby 1.9 release manager |
dRuby naturally extends the simplicity and power Ruby provides. Throughout this book, Rubyists should be able to enjoy a conversation with dRuby that makes you feel as if your own thoughts are traveling across processes and networks.
Kakutani Shintaro |
RubyKaigi organizer, Ruby no Kai |
Any programmer wanting to understand concurrency and distributedsystems using Ruby should read this book. The explanations andexample code make these topics approachable and interesting.
Aaron Patterson |
Ruby and Ruby on Rails core committer |
A fascinating and informative look at what is classically a total pain in the neck: distributed object management and process coordination on a single machine or across a network.
Jesse Rosalia |
Senior software engineer |
Foreword
In 2004, Ruby on Rails became public. The world wassurprised by its productivity and by the magic of Ruby thatenabled Ruby on Rails. Many people knew Ruby before Rails,but few realized the power of the language, especiallymetaprogramming.
But Rails is not the first framework to realize the power ofRuby. dRuby came long before Rails. It usesmetaprogramming features for distributed programming. Proxyobjects automagically delegate method calls to remoteobjects. You dont have to write interface definitions inXML or any IDL. dRuby is a good example of a veryflexible system implemented by Ruby. In this sense, Railsis a follower.
Even though dRuby has a long history, its importance hasnt beenreduced a bit in recent years. In fact, distributedprogramming is getting more important. We have access to more andmore computers over the Internet. In the cloud age, we should finda way to utilize those enormous numbers of computers. Andwe already have the answer: dRuby.
dRuby is not known outside of Japan asmuch as it should be. I hope this book helps people learn the lesser-known technology proven by history. Andyou will see the power and magic of dRuby and Ruby.
Yukihiro Matz Matsumoto
Japan, November 2011
Original Japanese edition:
dRuby niyoru Bunsan Web Programming by Masatoshi Seki
Copyright 2005. Published by Ohmsha, Ltd
This English translation, revised for Ruby 1.9, is Copyright 2012, The Pragmatic Bookshelf.
Acknowledgments
For the Japanese Edition
I would like to thank the development team of Ohmsha, Ltd., for publishing the dRuby book again; Akira Yamada, Kouhei Sutou, and Shintaro Kakutani for reviews; and the fireflies from Houki River for encouraging me.
For the English Edition
I would like to thank Makoto Inoue for translating this book, Dave Thomas and Susannah Pfalzer of Pragmatic Bookshelf for giving me the opportunity to publish the English edition, Hisashi Morita and Shintaro Kakutani for advice based on knowledge of the Japanese edition, and all the reviewersEric Hodel, Ivo Balbaert, Sam Rose, Kim Shrier, Javier Collado, Brian Schau, Tibor Simic, Stefan Turalski, Colin Yates, Leonard Chin, Elise Huard, Jesse Rosalia, and Chad Dumler-Montplaisir.
Original Japanese edition:
dRuby niyoru Bunsan Web Programming by Masatoshi Seki
Copyright 2005. Published by Ohmsha, Ltd
This English translation, revised for Ruby 1.9, is Copyright 2012, The Pragmatic Bookshelf.
Preface
Stateful web servers are a core concept of dRuby. dRuby lets you pass normal Ruby objects and call their methods across processes and networks seamlessly. With dRuby, youll experience the world of distributed computing as a natural extension of Ruby.
The most widely used distributed system in the world is probably the Web. Its one of the most successful ways to distribute documents around the worldand dRubys history is related to the Web. Back when Ruby was still in version 1.1, a web server called shttpsrv was available. shttpsrv was similar to WEBrick, but WEBrick was so innovative that Shinichiro Haraone of the core committers of Ruby and the author of shttpsrvdecided to ditch the new version of shttpsrv in favor of WEBrick (which now comes as part of Rubys standard libraries). But I really liked the small and cool web server called shttpsrv, so I wrote a servlet extension for it. With this extension, shttpsrv transformed from an ordinary web server to a special TCP server with state. And that is how dRuby started.
This is the third edition of The dRuby Book (the previous two editions were in Japanese). For this edition, Ive rewritten the book to cover the latest dRuby information and new libraries. If you are looking for theoretical definitions of distributed objects or detailed comparisons of various systems, look elsewhere! This book is full of hands-on exercises and interesting code examples. I hope you put this book to use by writing code as you read and discovering new things along the way.
Ruby changes your thinking process, and so does dRuby. dRuby is not just a tool to extend a method invocation. Youll discover new techniques, programming styles, and much more as you learn how dRuby works.
dRuby will show you a side of Ruby youve never seen before. Lets explore together!
Who This Book Is For
Youll gain a lot from this book if you are...
Interested in finding out about the benefits of writing apps using dRuby
Excited by the concept of distributed systems such as NoSQL but think most of the existing systems are too complicated
Interested in client-server network programming and web programming but are interested in a more lightweight alternative to Ruby on Rails or Sinatra