Created
October 31, 2016 15:49
-
-
Save zymtx5g79k/614b25a1639e4404022b7533d136b815 to your computer and use it in GitHub Desktop.
test_em_copy
This file contains 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
#!/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 | |
} | |
} |
This file contains 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
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