aboutsummaryrefslogtreecommitdiffstats
path: root/toys/brhute-rb/brhute
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-04-21 10:02:21 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-04-21 10:02:21 +0200
commitbc3f7d771f8ec4b8bb6c39619cba036b6f20b9cd (patch)
tree40f3f50ddb76a759878585029ca92e83fbcc9ba3 /toys/brhute-rb/brhute
parentadd de - ideas on distributed execution (diff)
downloadlaurent-tools-bc3f7d771f8ec4b8bb6c39619cba036b6f20b9cd.tar.xz
laurent-tools-bc3f7d771f8ec4b8bb6c39619cba036b6f20b9cd.zip
brhute: start for the rb version
Diffstat (limited to 'toys/brhute-rb/brhute')
-rwxr-xr-xtoys/brhute-rb/brhute/brhute.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/toys/brhute-rb/brhute/brhute.rb b/toys/brhute-rb/brhute/brhute.rb
new file mode 100755
index 0000000..26021d3
--- /dev/null
+++ b/toys/brhute-rb/brhute/brhute.rb
@@ -0,0 +1,52 @@
+require 'eventmachine'
+require 'em-http'
+#require 'fiber'
+
+# Ressources - emhttp:
+# https://github.com/igrigorik/em-http-request/blob/master/examples/multi.rb
+# https://github.com/igrigorik/em-http-request/wiki/Keep-Alive-and-HTTP-Pipelining
+# Ressources - fiber
+# https://github.com/igrigorik/em-http-request/blob/master/examples/fibered-http.rb
+# http://www.igvita.com/2009/05/13/fibers-cooperative-scheduling-in-ruby/
+
+class Brhute_proc
+ def initialize(urls, reqs_per_connection, verbose)
+ attr_accessor :nb_connections
+ @urls, @reqs_per_connection = urls, reqs_per_connection
+ @nb_connections = 3
+ @run()
+
+ def run()
+ EventMachine.run do
+ # Fiber.new{
+ # puts "Setting up HTTP request #1"
+ # data = async_fetch('http://www.google.com/')
+ # puts "Fetched page #1: #{data.response_header.status}"
+ # puts "Setting up HTTP request #2"
+ # data = async_fetch('http://www.google.com/toto')
+ # puts "Fetched page #2: #{data.response_header.status}"
+ # puts "Setting up HTTP request #3"
+ # data = async_fetch('http://www.google.com/tata')
+ # puts "Fetched page #3: #{data.response_header.status}"
+
+ multi = EventMachine::MultiRequest.new
+
+ reqs.each_with_index do |url, idx|
+ http = EventMachine::HttpRequest.new(url, :connect_timeout => 1)
+ req = http.get
+ multi.add idx, req
+ end
+
+ multi.callback do
+ p multi.responses[:callback].size
+ p multi.responses[:errback].size
+
+ EventMachine.stop
+ end
+ # }.resume
+ end
+end
+
+class Brhute
+ def initialize(urls, nb_connections=3, req_per_connection=10, verbose=false)
+ Brhute_proc(urls, nb_connections, req_per_connection, verbose)