Event Machine
               Ricardo Almeida
               @almeidaricardo




https://github.com/eventmachine/eventmachine
PostRank Tools

     • Mysql, Ruby (API), Rails, Sinatra, Phyton,
          Java, JRuby, EC2, Nagios, Ganglia, Solr
     • Eventmachine, RabbitMQ
     • From XMPP to AMQP
     • Cassandra, Goliath
http://webpulp.tv/post/4184040219/scaling-postrank-using-ruby-and-eventmachine-with-ilya
Ilya Grigorik
Event Machine

• Fast, simple event-processing library for Ruby
  programs

• Event-driven I/O
• Reactor pattern
Designed to

• Extremely high scalability, performance and stability
• An API that eliminates the complexities of high-
  performance threaded network programming
Social Core

• Escalabilidade
• Disponibilidade - Todos requests devem ser
  respondidos

• Consistência
Architectures
                                    Job Manager
GET / POST                  Queue
             Server Event

                                    Process
Tools
•   Rails 3.1.0.rc6

•   Ruby 1.9.2-head

•   Event-Machine

•   Thin

•   Goliath

•   Mysql (gem mysql2 v 0.3.6)

•   MongoDB

•   RabbitMQ (AMQP)
EM-Tools

• https://github.com/eventmachine/eventmachine/wiki
• https://github.com/igrigorik/em-http-request
• https://github.com/igrigorik/em-synchrony
• https://github.com/postrank-labs/goliath
Benchmarks


• ApacheBench,Version 2.3
• Autoperf (httperf)
Provas!!
Sleep Select (1 sec)

• Tools:
 • ApacheBench
 • Rails 3.1.0.rc6 + Ruby 1.9.2-head + Mysql +
    webrick


 https://gist.github.com/1166610
Sleep Select (1 sec)

  •   ab -c 10 -n 10 'http://localhost:3000/people/wait'

  •   Time taken for tests:   11.255 seconds




https://gist.github.com/1166610
Sleep Select (1 sec)
• Tools:                        Assync Rails

 • ApacheBench
 • webrick
 • Rails 3.1.0.rc6 + Ruby 1.9.2-head + Mysql + Thin
    + EventMachine

 https://gist.github.com/1166610
Sleep Select (1 sec)

  •   ab -c 10 -n 10 'http://localhost:3000/people/wait'

  •   Time taken for tests:   2.371 seconds




https://gist.github.com/1166610
Goliath
•   Heartbeat

•   Assync Upload

•   Routes

•   Validations
Sleep Select (1 sec)
• Tools:
 • ApacheBench
 • Rails 3.1.0.rc6 + Thin
 • Ruby 1.9.2-head + EventMachine + Mysql +
    Goliath

 https://gist.github.com/1166462
Goliath +
ActiveRecord
Sleep Select (1 sec)

  •   ab -c 10 -n 10 'http://0.0.0.0:9000/wait?format=json'

  •   Time taken for tests:   2.198 seconds




https://gist.github.com/1166610
HTTP assinc
    Req/Resp no MongoDB
• Tools:
 • ApacheBench
 • Mysql
 • Ruby 1.9.2-head + EventMachine + Goliath +
   MongoDB
HTTP assinc
Req/Resp no MongoDB
•   ab -c 10 -n 10 'http://0.0.0.0:9000/teste?format=json'

•   Time taken for tests:   0.209 seconds
HTTP assinc
Req/Resp no MongoDB
•   ab -c 50 -n 50 'http://0.0.0.0:9000/teste?format=json'

•   Time taken for tests:   1.105 seconds
EM + RabbitMQ
EM + RabbitMQ
Domínios

•   AAPG              •   Facebook

•   Anotations        •   Twitter

•   Activity (New)    •   Google+
http://www.slideshare.net/hungryblank/distributed-and-concurrent-programming-with-rabbitmq-and-eventmachine-rails-underground-2009
http://www.slideshare.net/hungryblank/distributed-and-concurrent-programming-with-rabbitmq-and-eventmachine-rails-underground-2009
http://www.slideshare.net/hungryblank/distributed-and-concurrent-programming-with-rabbitmq-and-eventmachine-rails-underground-2009
SPDY




http://www.igvita.com/2011/04/07/life-beyond-http-11-googles-spdy/
Obrigado!
 Ricardo Almeida
 @almeidaricardo

Event machine