“Divide and conquer
      riding rabbits and
        trading gems”
   - a tale about distributed programming -

   • http://www.slideshare.net/hungryblank
   • http://github.com/hungryblank/rabbit_starter
Paolo Negri                     @hungryblank
Resources

• http://www.slideshare.net/hungryblank
• http://github.com/hungryblank/rabbit_starter
About me
Time
       GNU/Linux - Dbs
                          Perl
         “systems”
                                   PHP
                          Python




                         Ruby
Summary:
Distributed
Concurrent
Programming
rabbitMQ




http://www.flickr.com/photos/myxi/448253580
Control
The problem
   Given a dictionary of
1.000.000 search phrases,
  compare for each one
the first page of results on
 google.com and bing.com
Don’t do it.
It’s a violation of terms
        of service!
(Sorry, I needed an example that
required little or no explanation)
Comparison
The whole process
Great! but...

• Fetching, parsing and analyzing
  2.000.000 pages of results will take a
  long time
• we want to collect the statistics in a
  limited time and this sequential
  approach is not quick enough
Distributed Computing
Is a method of solving computational
problem by dividing the problem into
  many tasks run simultaneously on
many hardware or software systems

            (Wikipedia)
Map Reduce "Map" step

  the master node takes the
input, chops it up into smaller
sub-problems, and distributes
   those to worker nodes.
         (Wikipedia)
Problems:

• How many nodes?
• How many workers?
• Distribution mechanism to
 feed the workers?
What about queuing?

• the master node takes the input, chops
  it up into smaller sub-problems, and
  publishes them in a queue
• workers independently consume the
  content of the queue
Here comes

• RabbitMQ is an implementation of AMQP,
  the emerging standard for high
  performance enterprise messaging
• It’s opensource
• Written in Erlang
Erlang?
• general-purpose concurrent programming
  language designed by Ericsson
• first version written by J. Armstrong in 1986
• distributed
• fault tolerant
• soft real time
• high availability
Erlang - is coming back
• Projects
 • CouchDB - RESTful document storage
 • WebMachine - REST toolkit
 • Nitrogen - web framework
 • Mochiweb - web framework
• Ruby shops using it
 • 37 Signal - Campfire
 • Heroku
+ Erlang


It’s messages all the way down
Install it


    • sudo apt-get install rabbitmq
    • sudo gem install tmm1-amqp
Note: rabbitMQ must be v1.6.0 and amqp gem v 0.6.4
           to follow the code in the slides
Do it! - master node
Do it! - worker node
Get for free

• Decoupling master/worker
• Workers take care of feeding themselves
• Flexible number of workers
Behind the scenes

                            Worker1
Master

msg A    Exchange   Queue   Worker2


                            Worker3
Behind the scenes

                            Worker1
Master

         Exchange   Queue   Worker2
          msg A

                            Worker3
Behind the scenes

                                  Worker1
Master

         Exchange   Queue msg A   Worker2


                                  Worker3
Behind the scenes

                            msg A   Worker1
Master

         Exchange   Queue           Worker2


                                    Worker3
RabbitMQ
• Multiple exchanges (and multiple types of
  exchange)
• Multiple queues
• Queues are connected by bindings to
  exchanges
• Exchanges route messages to queues
RabbitMQ

• Exchanges and queues have names
• BUT direct exchanges created implicitly are
  not public and don’t have name
• Queues and messages are resident in RAM
  and can be persisted on disk (at a
  performance price)
What and where
                          Master
                          (ruby)
     RabbitMQ
      (Erlang)            Worker
                 TCP/IP
                          (ruby)

                          Worker
                          (ruby)
Exchange Queue            Worker
                          (ruby)
Problem #1




If a worker has a problem we might lose one
             or more messages
                    http://www.flickr.com/photos/danzen/2288625136/
Solution - ACK in worker
Acknoledgement
• messages - 1 or more depending by
  prefetch settings - are passed to the client
• the client processes and acknowledges the
  messages one by one
• if the client connection closes =>
  unacknowledged messages go back in the
  queue
http://www.flickr.com/photos/streetfly_jz/2770586821/



           Problem #2




No convenient way to control the workers
System queue - worker
System queue - control




• save it as system_command.rb
• ruby system_command.rb halt
System queue

                              Queue1   Worker1
Control script

   msg A           Exchange   Queue2   Worker2


                              Queue3   Worker3
System queue

                              Queue1   Worker1
Control script
                   Exchange   Queue2   Worker2
                    msg A

                              Queue3   Worker3
System queue

                              msg A Queue1   Worker1
Control script
                   Exchange   msg A Queue2   Worker2


                              msg A Queue3   Worker3
EventMachine
EventMachine
Is an implementation of Reactor Pattern


• Non blocking IO and lightweight
  concurrency
• eliminate the complexities of high-
  performance threaded network
  programming
without EM                with EM
Ruby process          Ruby process
               Time
    code                  code



  network                                 network
  operation               Free
                                          operation

 use network           use network
  operation             operation
                                     Callback
    result                result


    Free
                          Free
EventMachine

amqp gem is built on top of
EventMachine => you’re in a
  context where you can
    leverage concurrent
        programming
EM - Deferrables

“The Deferrable pattern allows you to specify
 any number of Ruby code blocks that will be
executed at some future time when the status
      of the Deferrable object changes “
EM - Deferrables
EM - Deferrables
EM - Deferrables
EM - Deferrables
Deferrables
without deferrables      with deferrables


    GooglePage          GooglePage
                                        BingPage



     BingPage


                      Time
http://www.flickr.com/photos/philocrites/341850461/



          Problem #3




How many of them?
what are they doing?
Heartbeat - worker
Heartbeat monitor
Heartbeat queue

Worker1 msg A


Worker2           Exchange   Queue   Monitor


Worker3
          msg B
Heartbeat queue

Worker1

             msg A
Worker2     Exchange   Queue   Monitor
             msg B

Worker3
Heartbeat queue

Worker1


Worker2     Exchange   Queue msg B msg A   Monitor


Worker3
Clustering
         RabbitMQ - node A   RabbitMQ - node B

TCP/IP                                           TCP/IP



         RabbitMQ - node C

TCP/IP
async vs sync
       Syncronous clients on github



• famoseagle/carrot
• celldee/bunny
Rabbits on github
• danielsdeleo/moqueue Tests/stubbing
• Check out ezmobius/nanite
  “self assembling fabric of ruby daemons”
• Keep an eye on tonyg/rabbithub
  implementation of pubsubhubbub (PubSub
  over REST)
• auser/alice web app to monitor RabbitMQ
More rabbits on github

• tmm1/em-spec
• eventmachine/eventmachine
• tmm1/amqp
• macournoyer/thin
Q&A


 ?
Thanks!
(Thanks Mark!)

    Paolo Negri

/        hungryblank

More Related Content

PDF
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
PDF
RabbitMQ with python and ruby RuPy 2009
PDF
Improvements in RabbitMQ
PDF
RabbitMQ Data Ingestion
PDF
RabbitMQ Data Ingestion at Craft Conf
PDF
Scaling applications with RabbitMQ at SunshinePHP
PPTX
RabbitMQ Model and Some Example Applications
PDF
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
RabbitMQ with python and ruby RuPy 2009
Improvements in RabbitMQ
RabbitMQ Data Ingestion
RabbitMQ Data Ingestion at Craft Conf
Scaling applications with RabbitMQ at SunshinePHP
RabbitMQ Model and Some Example Applications

What's hot (19)

PDF
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
PPTX
Scaling application with RabbitMQ
PDF
Dissecting the rabbit: RabbitMQ Internal Architecture
PDF
RabbitMQ Operations
PPTX
High powered messaging with RabbitMQ
PDF
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
PPTX
Spring RabbitMQ
PDF
Troubleshooting RabbitMQ and services that use it
PDF
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
PDF
RabbitMQ fairly-indepth
PDF
Messaging Standards and Systems - AMQP & RabbitMQ
PDF
Integrating PostgreSql with RabbitMQ
PPTX
The RabbitMQ Message Broker
PDF
PostgreSQL: meet your queue
PDF
The details of CI/CD environment for Ruby
PDF
Introduction to AMQP Messaging with RabbitMQ
KEY
Cooking a rabbit pie
PDF
How to develop the Standard Libraries of Ruby?
PDF
On Rabbits and Elephants
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Scaling application with RabbitMQ
Dissecting the rabbit: RabbitMQ Internal Architecture
RabbitMQ Operations
High powered messaging with RabbitMQ
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
Spring RabbitMQ
Troubleshooting RabbitMQ and services that use it
Practical Message Queuing Using RabbitMQ (PHPem, 3rd July 2014)
RabbitMQ fairly-indepth
Messaging Standards and Systems - AMQP & RabbitMQ
Integrating PostgreSql with RabbitMQ
The RabbitMQ Message Broker
PostgreSQL: meet your queue
The details of CI/CD environment for Ruby
Introduction to AMQP Messaging with RabbitMQ
Cooking a rabbit pie
How to develop the Standard Libraries of Ruby?
On Rabbits and Elephants
Ad

Viewers also liked (20)

KEY
Ruby 1.9 Fibers
PDF
EventMachine
PDF
Mongrel2, a short introduction
PDF
A Documentation Crash Course, LinuxCon 2016
PPT
Why you should come to DrupalSouth
PPTX
Content Management Systems and Refactoring - Drupal, WordPress and eZ Publish
PPTX
Entrez dans le mouvement Maker à l’aide des technologies Microsoft
PDF
Electron - Solving our cross platform dreams?
PDF
Scaling Social Games
PDF
SimpleDb, an introduction
PDF
Offre développeur Javascript Back-end
PPTX
Contentful Berlin Offices
PDF
Automate your docs, automate yourself
PDF
Erlang introduction geek2geek Berlin
PDF
The Anatomy of Content Management (workshop by J Gollner at Intelligent Conte...
PDF
AWS Lambda in infrastructure
PDF
Le futur de Drupal et des applications web
PDF
Devoxx France 2015 - Se préparer à l'arrivée d'Angular 2
PDF
Back to the future with static site generators
PDF
ParisJS #10 : PhantomJs
Ruby 1.9 Fibers
EventMachine
Mongrel2, a short introduction
A Documentation Crash Course, LinuxCon 2016
Why you should come to DrupalSouth
Content Management Systems and Refactoring - Drupal, WordPress and eZ Publish
Entrez dans le mouvement Maker à l’aide des technologies Microsoft
Electron - Solving our cross platform dreams?
Scaling Social Games
SimpleDb, an introduction
Offre développeur Javascript Back-end
Contentful Berlin Offices
Automate your docs, automate yourself
Erlang introduction geek2geek Berlin
The Anatomy of Content Management (workshop by J Gollner at Intelligent Conte...
AWS Lambda in infrastructure
Le futur de Drupal et des applications web
Devoxx France 2015 - Se préparer à l'arrivée d'Angular 2
Back to the future with static site generators
ParisJS #10 : PhantomJs
Ad

Similar to Distributed and concurrent programming with RabbitMQ and EventMachine Rails Underground 2009 (20)

ZIP
Message Queues in Ruby - An Overview
KEY
Real time system_performance_mon
PDF
Scaling Ruby with Evented I/O - Ruby underground
ODP
The Art of Message Queues - TEKX
KEY
High scale flavour
ODP
Introduction to Python Celery
KEY
Concurrency in ruby
PDF
Presentation
PDF
Lindsay distributed geventzmq
PDF
Life in a Queue - Using Message Queue with django
PDF
Microservices communication styles and event bus
PDF
Evented applications with RabbitMQ and CakePHP
PPTX
Message Queuing on a Large Scale: IMVUs stateful real-time message queue for ...
PDF
Queue Everything and Please Everyone
PDF
Messaging with amqp and rabbitmq
KEY
RabbitMQ And Nanite
PDF
Webinar: Queues with RabbitMQ - Lorna Mitchell
PDF
The Future of Messaging: RabbitMQ and AMQP
KEY
Servers with Event Machine - David Troy - RailsConf 2011
PDF
Ruby Microservices with RabbitMQ
Message Queues in Ruby - An Overview
Real time system_performance_mon
Scaling Ruby with Evented I/O - Ruby underground
The Art of Message Queues - TEKX
High scale flavour
Introduction to Python Celery
Concurrency in ruby
Presentation
Lindsay distributed geventzmq
Life in a Queue - Using Message Queue with django
Microservices communication styles and event bus
Evented applications with RabbitMQ and CakePHP
Message Queuing on a Large Scale: IMVUs stateful real-time message queue for ...
Queue Everything and Please Everyone
Messaging with amqp and rabbitmq
RabbitMQ And Nanite
Webinar: Queues with RabbitMQ - Lorna Mitchell
The Future of Messaging: RabbitMQ and AMQP
Servers with Event Machine - David Troy - RailsConf 2011
Ruby Microservices with RabbitMQ

Recently uploaded (20)

PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
TEXTILE technology diploma scope and career opportunities
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
The various Industrial Revolutions .pptx
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PDF
Five Habits of High-Impact Board Members
PDF
Architecture types and enterprise applications.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Benefits of Physical activity for teenagers.pptx
PPTX
Configure Apache Mutual Authentication
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
CloudStack 4.21: First Look Webinar slides
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
What is a Computer? Input Devices /output devices
Zenith AI: Advanced Artificial Intelligence
TEXTILE technology diploma scope and career opportunities
Developing a website for English-speaking practice to English as a foreign la...
The various Industrial Revolutions .pptx
Final SEM Unit 1 for mit wpu at pune .pptx
NewMind AI Weekly Chronicles – August ’25 Week III
sbt 2.0: go big (Scala Days 2025 edition)
Five Habits of High-Impact Board Members
Architecture types and enterprise applications.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Benefits of Physical activity for teenagers.pptx
Configure Apache Mutual Authentication
Flame analysis and combustion estimation using large language and vision assi...
Improvisation in detection of pomegranate leaf disease using transfer learni...
OpenACC and Open Hackathons Monthly Highlights July 2025
sustainability-14-14877-v2.pddhzftheheeeee
CloudStack 4.21: First Look Webinar slides
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
A contest of sentiment analysis: k-nearest neighbor versus neural network
What is a Computer? Input Devices /output devices

Distributed and concurrent programming with RabbitMQ and EventMachine Rails Underground 2009