Home > Articles > Programming > Ruby

Distributed Ruby: Mark Bates Sheds New Light

Sometimes Ruby code is too cool to run on just one computer at a time. In this interview with Hal Fulton, Mark Bates explains how he defines distributed programming, reasonable concerns about Ruby performance, and how to choose Ruby libraries.
Like this article? We recommend

Like this article? We recommend

If you're reading this, you may already be sold on the idea that Ruby is a fun and productive language. Certainly, I am. As someone with ten years of Ruby experience (and two editions of The Ruby Way) behind me, you must forgive me if I'm not objective.

Besides the tendency toward more agile languages, the industry is also seeing distributed programming techniques grow in popularity. Distributed programming in Ruby has been possible for years. But certain areas were not well-understood by many people, since the documentation has not been wholly adequate (unless you speak Japanese).

Mark Bates recently helped fill that gap. His new book, Distributed Programming with Ruby, addresses libraries, tools, and techniques that facilitate distributed coding in Ruby.

Hal Fulton: What was your motivation in writing this book, other than the minimum-wage pay?

Mark Bates: A colleague approached me at the Ruby Conference last year (in November 2008), after I spoke about building distributed applications. He suggested I should write a book on the subject, because no comparable book existed. It seemed like a good idea, especially since the documentation around DRb/Rinda is almost nonexistent. I thought it would be a real benefit to the community to explain what those libraries are, how they work, and what you can and can't do with them. From that impetus, the book just grew.

Hal Fulton: Do you write distributed applications often?

Mark Bates: In a way, I think we all write distributed apps more than we think we do; we just usually don't think about it.

The company I was working for a year ago was heading down a real distributed app path, which is how I got so deeply into this area. Over the past year I've been working at a company where we have a few applications that aren't traditionally "distributed" applications, but there is still a high amount of queuing and communication that needs to happen between the apps. So in some way, I work on distributed apps every day.

Hal Fulton: What problem domains have you specifically coded with these techniques?

Mark Bates: Throughout the book, I try to relate the technologies and techniques to problems that I or others have encountered. I present the problems (and the solutions to those problems) in a way that makes sense to the reader, so that they can find value and relevance to their own projects. Personally, I've had to deal with communication between different apps, remote method invocation, offloading heavy tasks, messaging – really, the whole range of issues that accompany any decent-sized application.

A lot of those experiences are spelled out in the book to help keep people from falling into the same traps that caught me along the way.

Hal Fulton: Is it your perception that there are significant gaps in distributed Ruby as it exists now? Tools, libraries, or features that are missing?

Mark Bates: I don't think there is any one perfect solution out there for Ruby, or for any other language for that matter. This is a hard question to answer; what is the real definition of "distributed Ruby" anyhow? In the book, as I talk about different technologies, and the solutions they present, I try to point out what's missing and how things could be improved.

I think the DRb/Rinda packages offer some great tools. But they can be slow at times, and they could be made easier to use.

Hal Fulton: You said, "I think we all write distributed apps more than we think we do, we just usually don't know it." That's intriguing to me. Can you give an example or two of applications whose distributed nature might be less than obvious?

Mark Bates: Any app that has ever offloaded some heavy lifting to a background process has dabbled in distributed programming. If you use a service like Amazon's new RDS, Hadoop, or any other remote service you are writing distributed applications.

I think people get it in their heads that distributed programming means just one or two different things, some sort of remote method invocation or having a bunch of computers all chewing on some complex data set or problem. But really it's a lot broader a field than that. I tried to demonstrate that in the book by giving examples of some of the different types of distributed programming there are.

Hal Fulton: Many people associate distributed programming with map-reduce type problems of the SETI@Home variety. Do you find existing Ruby tools adequate for this type of task (barring, of course, the fact that Ruby tends to be slower than C)?

Mark Bates: There's no denying that if you're talking about raw number crunching speed, a C app will certainly be a lot faster than Ruby. With that said, I don't think most people are writing those kinds of programs. For most of us, it's offloading a heavy task, sending messages, or communicating with a service somewhere that is doing some heavy lifting or is "isolating" code for us. In those circumstances, Ruby is definitely fast enough.

There are a few map-reduce libraries available for Ruby; I talk about them in the book, but they haven't really caught on. I don't know if that is because there aren't enough people in the community writing applications that require map-reduce, or that the libraries are too slow.

During the course of writing this book, I looked at a few of those libraries, and unfortunately I was not overly impressed by them. I'm hoping that if this book goes to a second edition, there will be a really great Ruby map-reduce library out there for me to include. Developers, start your engines!

Hal Fulton: Some applications are "inherently" distributed by their nature (such as a multi-person chat client). Do you see these as a special subset of distributed apps, or are they just "more of the same"?

Mark Bates: I wouldn't say they are a special subset of distributed apps. I think they are a flavor of distributed applications, of which there are many flavors.

Hal Fulton: More generally: Are there distinct classes of apps that are more or less challenging?

Mark Bates: Dealing with background jobs can be fairly straightforward, and certainly libraries like Delayed::Job help make it easier. The same goes for message queuing. Even so, it's easy to get yourself stuck in a tricky situation with those.

On the more complex side of things, I think any sort of remote method invocation can easily lead you down a rabbit hole. When you make RMI calls you are tying your application to the internal design of another application. With a REST API you know that you will deal with a very clear API that shouldn't be changing too much, and that will publish basic data types. With RMI, it's possible that the developer of the other app could easily change a method definition, or change the return data type, or even make a simple change within the method itself which can easily break your application.

And security becomes an even bigger concern as you can now execute code remotely on another server. Scary stuff.

Hal Fulton: Many existing tools and libraries offer similar functionality in different ways, and therefore overlap here and there. Have you discovered particular tools that conflict with (or better, complement) each other?

Mark Bates: I believe that you should try to keep your environment as clean as possible. If you don't like the message queue you are currently using, don't bring in a second one and use them both. Instead, refactor your code to use the new one. Otherwise it's confusing to code, difficult to deploy, and definitely error-prone. That's the biggest conflict I think you'd find with most of these libraries.

As for complementary libraries, I really enjoy using RabbitMQ/AMQP and Delayed::Job together. I find that these complement each other incredibly well. For example, I had several business groups each asking for various "slices" of data from requests to the app. One group wanted the data presented one way, another wanted it another way, and so on. So I built a simple Rack app that took the request info (headers, params, cookies, etc.) and sent it to RabbitMQ. Then we wrote some processes that would subscribe to the queue and generate Delayed::Jobs for each type of reporting we needed. We got the speed of RabbitMQ and the power of subscribing to queues. And, in addition, we got the security of the Delayed::Job database-backed storage and error handling. It's worked out really well for us, and it's certainly a pattern I'll use again.

Hal Fulton: While you wrote this book, did particular libraries emerge as your favorite pieces of technology?

Mark Bates: If I had to pick one, it would have to be Delayed::Job. It's incredibly easy to set up and use. You can easily prioritize tasks and monitor them, and great error handling is built in. I use it all the time. It's an excellent way to deal with those heavy background tasks.

I did have to extend it for my own purposes. I wanted things like Hoptoad Notification and an easy way to re-enqueue a task, so I built the delayed_job_extras gem, but apart from those things, it's pretty awesome right out of the box.

Hal Fulton: In writing this book, what insights or important truths did you learn?

Mark Bates: I learned that DRb/Rinda needs better documentation in the core!

While it's not necessarily something I learned while writing this book, my advice would be: Don't get caught up with the "new, hot, sexy" library. It's easy to read a book like this one and decide you have to implement RabbitMQ because it's so cool, even if you don't have an actual business need for it. Before you go and spend crazy amounts of time implementing any technology into your project, first ask yourself: Is this the right technology for the problem at hand, or am I you just trying to add it to my resume?

In either case, when you introduce a new tool, I recommend playing with it a little bit on a small scale. Open up an empty editor and try playing with the technology on its own for a few hours. Dig into the source code. Read the documentation. Try out a few of the features. You'll quickly learn whether the technology is right for you and the project at hand. It's quicker and easier than trying to shoehorn it into some big existing project.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020