Created
March 1, 2012 16:58
-
-
Save balepc/1951392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
require 'em-synchrony' | |
require 'em-synchrony/connection_pool' | |
require 'em-synchrony/activerecord' | |
require 'mysql2' | |
require 'active_record' | |
#require 'rack/fiber_pool' | |
ActiveRecord::Base.establish_connection({:host => 'localhost', | |
:adapter => "em_mysql2", | |
:database => 'ask.fm', | |
:username => 'root', | |
:password => 'xxxxxxx', | |
:encoding => 'utf8', | |
:pool => 1, | |
:real_pool => 1, | |
:connections => 1} | |
) | |
RAILS_ROOT = Dir.pwd | |
require File.join(RAILS_ROOT, "/app/jobs/models/user.rb") | |
EM.synchrony do | |
timer = Time.now | |
fibers = [] | |
1.upto(10) do | |
fibers << Fiber.new do | |
time = Benchmark.realtime { | |
1.upto(10000) do |index| | |
User.find_by_id(index) | |
end | |
} | |
puts "#{time*1000} milliseconds" | |
end | |
end | |
fibers.each { |t| t.resume } | |
Fiber.new do | |
loop do | |
unless fibers.any?(&:alive?) | |
puts "" | |
puts "Total time: #{Time.now - timer}" | |
EM.stop | |
end | |
EM::Synchrony.sleep 0.5 | |
end | |
end.resume | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment