Skip to content

Instantly share code, notes, and snippets.

@zymtx5g79k
Created October 31, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zymtx5g79k/614b25a1639e4404022b7533d136b815 to your computer and use it in GitHub Desktop.
Save zymtx5g79k/614b25a1639e4404022b7533d136b815 to your computer and use it in GitHub Desktop.
test_em_copy
#!/usr/bin/env ruby
#define path
$:.unshift File.expand_path("../", __FILE__)
require 'rubygems'
require 'eventmachine'
#Faster
require 'em-http'
#Slower
#require 'em-http-request'
require 'json'
require 'object_manager'
require 'fiber'
def print_msg
print "\r@_completed: #{@_completed}, @_error: #{@_error}"
end
def stop timer
EM.cancel_timer(timer) unless timer.nil?; EM.stop; puts "Stopped ..."
end
period = 0.001
@_max_count = 10000
@_completed = 0
@_error = 0
@requests = {}; @completed = {}
@options = { :connect_timeout => 1, :inactivity_timeout => 10 }
@request_options = { :keepalive => true } #@request_options = { :query => @query, :keepalive => true }
@time = Time.now.to_i; print_msg
EventMachine.run {
timer = EventMachine.add_periodic_timer(period) {
r = EM::HttpRequest.new("http://radyodilara.net/", @options).get({ :query => '' })
r.callback {
@_completed += 1; print_msg
stop timer unless @_completed < @_max_count
}
r.errback { |http| @_error += 1; print_msg; }
EM.cancel_timer(timer) unless @_completed < @_max_count
}
}
source 'https://rubygems.org'
gem 'eventmachine'
gem 'em-http-request'
gem 'mongo'
gem 'json'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment