Permalink
Browse files

As requested by Peter Veentjer, benchmarking rountines

  • Loading branch information...
1 parent 118ce24 commit b5a027a98e66e9f9d298bca9f2ea6f604a20ebb3 @danielribeiro committed Dec 19, 2010
Showing with 92 additions and 5 deletions.
  1. +16 −5 Rakefile
  2. +2 −0 benchmark.sh
  3. +74 −0 lib/benchmarking_akka.rb
View
@@ -6,14 +6,25 @@ require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'
+def jruby_execute(filename = nil, args = [])
+ vendorFiles = [''] + %w[akka_2.8.0-0.10.jar akka-core_2.8.0-0.10.jar scala-library.jar]
+ ENV['CLASSPATH'] = vendorFiles.map { |v| File.expand_path v, 'vendor' }.join(":")
+ filename = "lib/actor_word_count.rb" if filename.nil?
+ system 'jruby', *(['-Ilib', filename] + args)
+end
+
task :default => :run
desc "Runs jruby on a file with the correct classpath. By default runs actor_word_cout.
To run other file, like basic_example.rb, just pass the arguemnt:
$rake run[lib/basic_example.rb]"
task :run, :filename do |t, args|
- vendorFiles = [''] + %w[akka_2.8.0-0.10.jar akka-core_2.8.0-0.10.jar scala-library.jar]
- ENV['CLASSPATH'] = vendorFiles.map { |v| File.expand_path v, 'vendor' }.join(":")
- filename = args.filename
- filename = "lib/actor_word_count.rb" if filename.nil?
- system 'jruby', '-Ilib', filename
+ jruby_execute args.filename
+end
+
+
+desc "Benchmarks the actors word count.
+Receives two arguments: chunkSize and mapActorsCount"
+task :benchmark, :chunkSize, :mapActorsCount do |t, args|
+ jruby_execute 'lib/benchmarking_akka.rb',
+ [args.chunkSize || "200", args.mapActorsCount || "2"]
end
View
@@ -0,0 +1,2 @@
+#!/bin/bash
+rake benchmark[$1,$2]
View
@@ -0,0 +1,74 @@
+require 'akka'
+require 'regular_word_count'
+module AkkaDispatcher
+ include_package 'se.scalablesolutions.akka.dispatch'
+ def self.workStealer(name)
+ Dispatchers.newExecutorBasedEventDrivenWorkStealingDispatcher 'mappers'
+ end
+end
+
+class Benchmark
+ include Actors
+ attr_accessor :chunkSize, :mapActorsCount
+
+ def initialize(chunkSize = 500 , mapActorsCount = 2)
+ @chunkSize = chunkSize
+ @mapActorsCount = mapActorsCount
+ end
+
+ def execute
+ file = File.join(File.dirname(__FILE__), 'shakespeare.txt')
+ input = IO.readlines(file).each_slice(chunkSize).map &:join
+
+ start = nil
+ values = Hash.new 0
+ linesToRead = input.size
+ reduceActor = actor do |message|
+ linesToRead -= 1
+ hash = message
+ hash.each do |key, value|
+ values[key] += value
+ end
+ if linesToRead == 0
+ puts ">> All over: Just to say we used any computed value: #{values['shakespeare']}"
+ finish = Time.now
+ puts ">> Total time: #{finish - start}s"
+ Akka::ActorRegistry.shutdownAll()
+ end
+ end
+
+ mapActors = []
+ wordCount = WordCount.new
+ workStealer = AkkaDispatcher.workStealer 'mappers'
+ mapActorsCount.times do
+ mapActor = actor do |message|
+ reduceActor.sendOneWay wordCount.count message
+ end
+ mapActor.setDispatcher workStealer
+ mapActors.push mapActor
+ end
+
+ mapActor = mapActors.first
+ producer = actor do |message|
+ for line in input
+ mapActor.sendOneWay line
+ end
+ end
+
+ allActors = [reduceActor, producer] + mapActors
+ allActors.each do |a|
+ a.start
+ end
+ start = Time.now
+ producer.sendOneWay :start
+ end
+end
+
+if $PROGRAM_NAME == __FILE__
+ if ARGV.size != 2
+ puts "Please provide both chunkSize and mapActorsCount "
+ end
+ chunkSize, mapActorsCount = ARGV
+ Benchmark.new(chunkSize.to_i, mapActorsCount.to_i).execute
+end
+

0 comments on commit b5a027a

Please sign in to comment.