celluloid-benchmark 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a93b7e2da94de515289b206900f7e8672a3ed2e
4
- data.tar.gz: 13c898934494aa9365d6a2c5fd445b39d42c20b0
3
+ metadata.gz: 9b4f96a47f1a9d4c90006868c81711b9b6bdfc52
4
+ data.tar.gz: ed693552569f5428d0d080f433ee698dd5957968
5
5
  SHA512:
6
- metadata.gz: df661160938f2506686e0876c61fcb444a93327cee17c42c47326e38dad43278f35426b7fcfd748c4d1e21e630b20c217e8df0ae6e307b57e4b91b8bf172e54f
7
- data.tar.gz: cf3cd1bbbda270cd1e2d77c178bc41f3bf1ff9f9b4e5cbc054a7ff844e73b71db56226552d88638be9c1b0afb4a71338e162c401e353a53ece419bb7d9bc06d8
6
+ metadata.gz: 45acfeefe059bb4bb16f65f814790c5311c93f015ba2f92a738608822f9bb4dffda0e11a1fbdab2e584ec76e85b1185b643bb418fb332280f3c1bbf05e080805
7
+ data.tar.gz: 2629ee0d3f1583eb1a33e12375f5d28b4e17744be9e648fa7cf33a54341c03b9ca25e1b5590f91325fa45baa0e55438227de7be4efb07b3af934fc2f1e2eb5d3
data/README.md CHANGED
@@ -16,8 +16,10 @@ For your own tests, create a session file and pass its path to celluloid-benchma
16
16
 
17
17
  Simple scenario
18
18
  ---------------
19
- benchmark :home_page, 1
20
- get "https://github.com/scottwillson/celluloid-benchmark"
19
+ CelluloidBenchmark::Session.define do
20
+ benchmark :home_page, 1
21
+ get "https://github.com/scottwillson/celluloid-benchmark"
22
+ end
21
23
 
22
24
  `benchmark :label, duration` means "measure the following requests and group them under 'label'".
23
25
  Duration is optional and defaults to 0.3 seconds.
@@ -50,6 +52,18 @@ Simulate AJAX
50
52
  }
51
53
  end
52
54
 
55
+ JSON requests (e.g., a mobile app API)
56
+ --------------------------------------
57
+ get "/mobile-api/v2/offers.json", [], nil, {
58
+ "Accept" => "application/json, text/javascript, */*; q=0.01"
59
+ }
60
+
61
+ post(
62
+ "/mobile-api/v2/signup.json",
63
+ MultiJson.dump({ email: email }),
64
+ { "Content-Type" => "application/json" }
65
+ )
66
+
53
67
  Test data
54
68
  ---------
55
69
  Because test scenarios are plain Ruby, you can drive tests in many different ways. The
@@ -72,12 +86,27 @@ Celluloid Benchmark can also pull random test data from CSV files. For example:
72
86
 
73
87
  `random_data(:post_zone)` pulls a random line from tmp/data/post_zones.csv
74
88
 
89
+ Extending session DSL
90
+ ---------------------
91
+ The DSL is simple and will change in early releases. To add custom DSL methods, add methods to Visitor
92
+ module CelluloidBenchmark
93
+ class Visitor
94
+ def visit_from_homepage(target)
95
+ ...
96
+ end
97
+ end
98
+ end
99
+
75
100
  Celluloid Benchmark agents delegate calls to Mechanize. If you need something more complicated
76
101
  than the examples, check out the [Mechanize API](http://mechanize.rubyforge.org/HTTP/Agent.html) and call it directly with `browser.` in your test scenario.
77
102
 
78
103
  For a longer test, pass in a second duration argument (seconds):
79
104
  celluloid-benchmark my_test_session.rb 180
80
105
 
106
+ Sessions are defined as Procs, which means that you can't call `return` in a session definition. If you do need to
107
+ short-circuit a session (for example, to simulate an early visitor exit), encapsulate that part of the session in a
108
+ method. You can call return from the method. See "Extending session DSL" above.
109
+
81
110
  Why
82
111
  ===
83
112
  I need to simulate a lot of realistic traffic against preproduction code.
@@ -1,12 +1,14 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require_relative "../lib/celluloid_benchmark"
4
+ require "os"
4
5
 
5
- benchmark_run = CelluloidBenchmark::Runner.run ARGV[0], (ARGV[1] || 20).to_i, (ARGV[2] || OS.cpu_count * 1.5).to_i
6
+ session_path = File.expand_path(ARGV[0])
7
+ benchmark_run = CelluloidBenchmark::Runner.run session_path, (ARGV[1] || 20).to_i, (ARGV[2] || OS.cpu_count * 1.5).to_i
6
8
 
7
9
  p benchmark_run
8
10
  puts
9
- p "#{benchmark_run.requests / benchmark_run.elapsed_time} requests per second. #{benchmark_run.requests} requests in #{benchmark_run.elapsed_time} seconds by #{Celluloid::Actor[:visitor_pool].size} visitors."
11
+ p "#{benchmark_run.requests / benchmark_run.elapsed_time} requests per second. #{benchmark_run.requests} requests in #{benchmark_run.elapsed_time} seconds by #{CelluloidBenchmark::Visitor.pool.size} visitors."
10
12
 
11
13
  puts
12
14
  benchmark_run.benchmarks.each do |trans|
@@ -1,4 +1,5 @@
1
1
  require "celluloid"
2
+ require_relative "session"
2
3
  require_relative "visitor_group"
3
4
 
4
5
  Celluloid.logger = nil
@@ -10,24 +11,25 @@ module CelluloidBenchmark
10
11
  raise("session_path is required") unless session_path
11
12
  raise("'#{session_path}' does not exist") unless File.exists?(session_path)
12
13
 
13
- visitor_group = VisitorGroup.run!
14
+ require session_path
15
+
16
+ VisitorGroup.run!
14
17
  set_visitors_pool_size visitors
15
18
  benchmark_run = Celluloid::Actor[:benchmark_run]
16
19
 
17
20
  benchmark_run.mark_start
18
- futures = run_sessions(session_path, benchmark_run, duration)
21
+ futures = run_sessions(benchmark_run, duration)
19
22
  futures.map(&:value)
20
23
  benchmark_run.mark_end
21
24
 
22
25
  benchmark_run
23
26
  end
24
27
 
25
- def self.run_sessions(session_path, benchmark_run, duration)
26
- session = File.read(session_path)
28
+ def self.run_sessions(benchmark_run, duration)
27
29
  visitors = Celluloid::Actor[:visitor_pool]
28
30
  futures = []
29
31
  (visitors.size - 2).times do
30
- futures << visitors.future.run_session(session, benchmark_run, duration)
32
+ futures << visitors.future.run_session(benchmark_run, duration)
31
33
  end
32
34
  futures
33
35
  end
@@ -0,0 +1,13 @@
1
+ module CelluloidBenchmark
2
+ module Session
3
+ @session_block = nil
4
+
5
+ def self.define(&block)
6
+ @session_block = block
7
+ end
8
+
9
+ def self.run(visitor)
10
+ visitor.instance_eval(&@session_block)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module CelluloidBenchmark
2
- VERSION = "0.0.10"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -25,14 +25,14 @@ module CelluloidBenchmark
25
25
  browser.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14"
26
26
  end
27
27
 
28
- def run_session(session, benchmark_run, duration)
28
+ def run_session(benchmark_run, duration)
29
29
  @benchmark_run = benchmark_run
30
30
 
31
31
  elapsed_time = 0
32
32
  started_at = Time.now
33
33
  until elapsed_time >= duration
34
34
  begin
35
- instance_eval session
35
+ Session.run self
36
36
  rescue Mechanize::ResponseCodeError => e
37
37
  log_response_code_error e
38
38
  end
@@ -51,6 +51,10 @@ module CelluloidBenchmark
51
51
  case value
52
52
  when :iphone
53
53
  browser.user_agent = "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
54
+ when :android
55
+ browser.user_agent = "Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/BuildID) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36"
56
+ when :ipad
57
+ browser.user_agent = "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
54
58
  else
55
59
  browser.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14"
56
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid-benchmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Willson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-05-16 00:00:00 Z
12
+ date: 2014-06-11 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -81,6 +81,7 @@ files:
81
81
  - lib/celluloid_benchmark/benchmark_run.rb
82
82
  - lib/celluloid_benchmark/data_sources.rb
83
83
  - lib/celluloid_benchmark/runner.rb
84
+ - lib/celluloid_benchmark/session.rb
84
85
  - lib/celluloid_benchmark/version.rb
85
86
  - lib/celluloid_benchmark/visitor.rb
86
87
  - lib/celluloid_benchmark/visitor_group.rb