9 responses to “Ruby’s EventMachine – Part 2 : Asynchronous != Faster”

  1. yuan

    great! how can I integrate eventmachine to my rails apps?

  2. Ludovic Henry

    What are the results if you use epoll instead of select? Thank you.

  3. Phil Pirozhkov

    It’s a very good example that EM is still far from being perfect.
    This is mostly due to the poor memcached protocol implementation, which adds all these callbacks to an array and is poping it one by one.

    There’s a problem in test itself, you should consider that in evented style you never know which operation finishes first, and you cannot be sure that DEL is sent after SET and GET. So this should be better:

    require 'em-synchrony'
    require 'em-synchrony/em-memcache'
    
    def async2
      EventMachine.synchrony do
        cache = EM::P::Memcache.connect
    
        TEST_SIZE.times do |n|
          cache.set "key#{n}", "value#{n}"
        end
        TEST_SIZE.times do |n|
          value = cache.get "key#{n}"
        end
        TEST_SIZE.times do |n|
          cache.delete("key#{n}")
        end
    
        EventMachine.stop
      end
    end
    
    puts Benchmark.measure { puts "async:"; async2 }
    

    However, the overhead is the same.

    1. Phil Pirozhkov

      Forgot to mention that on my machine sync is only 50%-100% faster than async given your benchmark. (2 cores, linux 3.5.4).

  4. Jarmo Pertman

    You could also try Benchmark.bmbm instead of .measure to see if there’s any effect when having also the rehearsal phase.

  5. Nicolás

    Greate post! Waiting for part 3!!!

You can login to comment using your favorite social network (optional)

Leave a Reply

close