Sha256: 81973e077e67c3512f95a1a35d36e93a02cda0ba98b1d5e534cdff5f8c59057b

Contents?: true

Size: 1.38 KB

Versions: 8

Compression:

Stored size: 1.38 KB

Contents

#!/usr/bin/env ruby

require 'benchmark'

require 'rubygems'
require 'bundler'
Bundler.setup

require 'dcell'
DCell.setup
DCell.run!

RECEIVER_PORT = 2043

$receiver_pid = Process.spawn Gem.ruby, File.expand_path("../receiver.rb", __FILE__)
STDERR.print "Waiting for test node to start up..."

socket = nil
30.times do
  begin
    socket = TCPSocket.open("127.0.0.1", RECEIVER_PORT)
    break if socket
  rescue Errno::ECONNREFUSED
    STDERR.print "."
    sleep 1
  end
end

if socket
  STDERR.puts " done!"
  socket.close
else
  STDERR.puts " FAILED!"
  raise "couldn't connect to test node!"
end

class AsyncPerformanceTest
  include Celluloid

  def initialize(progenator, n = 10000)
    @n = n
    @receiver = progenator.spawn_async_receiver(n, current_actor)
  end

  def run
    @n.times { @receiver.async.increment }
    wait :complete
  end

  def complete
    signal :complete
  end
end

DCell.start :id => "messaging_node", :addr => "tcp://127.0.0.1:2042",
  :directory => {
    :id => "benchmark_receiver",
    :addr => "tcp://127.0.0.1:#{RECEIVER_PORT}"
  }

receiver = DCell::Node['benchmark_receiver']
progenator = receiver[:progenator]

test = AsyncPerformanceTest.new progenator
time = Benchmark.measure { test.run }.real
messages_per_second = 1 / time * 10000

puts "messages_per_second: #{"%0.2f" % messages_per_second}"

Process.kill 9, $receiver_pid
Process.wait $receiver_pid rescue nil

exit 0

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
dcell-0.16.1 benchmarks/messaging.rb
stn-dcell-0.16.0 benchmarks/messaging.rb
dcell-0.16.0 benchmarks/messaging.rb
dcell-0.16.0.pre benchmarks/messaging.rb
dcell-0.15.0 benchmarks/messaging.rb
dcell-0.15.0.pre benchmarks/messaging.rb
dcell-0.14.0 benchmarks/messaging.rb
dcell-0.13.0 benchmarks/messaging.rb