web_tsunami 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +4 -0
  2. data/Gemfile.lock +12 -0
  3. data/README +9 -0
  4. data/example.rb +28 -0
  5. data/web_tsunami.rb +53 -0
  6. metadata +50 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ gem 'typhoeus'
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ mime-types (1.18)
5
+ typhoeus (0.3.3)
6
+ mime-types
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ typhoeus
data/README ADDED
@@ -0,0 +1,9 @@
1
+ Benchmark your web application.
2
+
3
+ Why not using Apache Benchmark or any similar tool?
4
+
5
+ Because some times we need to send unique requests and AB doesn't fit for that need.
6
+
7
+ Check example.rb to see how it's working.
8
+
9
+ More documentation and gem is coming soon.
data/example.rb ADDED
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'web_tsunami'
4
+
5
+ # Triggers the following requests concurently:
6
+ # http://www.google.com
7
+ # http://www.google.com/search?q=ruby
8
+ # http://www.google.com/search?q=ruby&start=10
9
+
10
+ class GoogleTsunami < WebTsunami::Scenario
11
+ def run
12
+ get('http://www.google.com') do
13
+ puts 'http://www.google.com'
14
+ get('http://www.google.com/search?q=ruby') do
15
+ puts 'http://www.google.com/search?q=ruby'
16
+ get("http://www.google.com/search?q=ruby&start=#{rand(100)*10}") do
17
+ puts 'http://www.google.com/search?q=ruby&start=10'
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ # Set concurrency and duration in seconds and start your script.
25
+ # These numbers are voluntary low because I don't want any trouble with Google.
26
+ # But don't hesitate to set a higher concurrency and a duration of almost 5 minutes
27
+ # in order to get a reliable benchmark.
28
+ GoogleTsunami.start(concurrency: 2, duration: 10)
data/web_tsunami.rb ADDED
@@ -0,0 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'typhoeus'
4
+
5
+ module WebTsunami
6
+ class Scenario
7
+
8
+ attr_reader :concurrency
9
+
10
+ def self.start(options)
11
+ options[:duration].times { fork { new(options[:concurrency]).start } and sleep(1) }
12
+ Process.wait
13
+ end
14
+
15
+ def initialize(concurrency)
16
+ @sleeps = {}
17
+ @concurrency = concurrency
18
+ end
19
+
20
+ def requests
21
+ (@requests = Typhoeus::Hydra.new).disable_memoization unless @requests
22
+ @requests
23
+ end
24
+
25
+ def get(url, &block)
26
+ requests.queue(req = Typhoeus::Request.new(url, request_options))
27
+ req.on_complete do |response|
28
+ if response.timed_out?
29
+ puts "Timeout #{url}"
30
+ elsif response.code == 0
31
+ puts "#{response.curl_error_message} #{url}"
32
+ elsif !response.success? && response.code != 302
33
+ puts "#{response.code} #{url}"
34
+ end
35
+ block.call(response) if block
36
+ end
37
+ end
38
+
39
+ def start
40
+ concurrency.times { |i| run }
41
+ requests.run
42
+ end
43
+
44
+ def run
45
+ raise NotImplementedError
46
+ end
47
+
48
+ def request_options
49
+ {}
50
+ end
51
+
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: web_tsunami
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexis Bernard
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-13 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Benchmark your web application
15
+ email:
16
+ - alexis@official.fm
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - README
24
+ - example.rb
25
+ - web_tsunami.rb
26
+ homepage: https://github.com/officialfm/web_tsunami
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.10
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Benchmark your web application
50
+ test_files: []