celluloid-benchmark 0.1.4 → 0.1.5

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: 489556fa1dd07270a9e5d256b6b29d652c83576d
4
- data.tar.gz: b302af61be3b35a226a99e122770d3ea5a0a3e5c
3
+ metadata.gz: c5053fec389c66821a970308a2a660788e0d2c63
4
+ data.tar.gz: 5bbcac6fff25c7465a179413b5a3a5f3db15ca98
5
5
  SHA512:
6
- metadata.gz: c3fff2ef1156ae00624f2f88b103e36404731c70550873200c9e33f480fb095fd42e70c89d68b84a454431815233649c0ce9063c4b7249dc3c1559b2d6bd0388
7
- data.tar.gz: f0cc0a4c8d1f09895020e8c15f3cd7b909e81aa9ffa330c9fe7372b6aca692a71cf90060b5769048c82386e12f52cb04947af7c3c6f5212602a3928e860307cf
6
+ metadata.gz: 1790062aba09ef03ec6e6f42dd95b9dc94b0eb38172869487aa9394d352c02c3d1881172aac099f70050d086194bd45d75276d1602143cc6caac0488362e2184
7
+ data.tar.gz: ff926c409d718b55a1f2edca1429fe3c59051b0cf4ffa48cca2c11963cbcffb060c73d9d47d83a868a8368cc775b6a6141e8a1614a26e3c4a48368042476150f
@@ -1,7 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  require_relative "../lib/celluloid_benchmark"
4
- require "os"
5
4
 
6
5
  session_path = File.expand_path(ARGV[0])
7
6
 
@@ -10,11 +9,11 @@ if duration == 0
10
9
  duration = 20
11
10
  end
12
11
 
13
- benchmark_run = CelluloidBenchmark::Runner.run session_path, duration, (ARGV[2] || OS.cpu_count * 1.5).to_i
12
+ benchmark_run = CelluloidBenchmark::Runner.run session_path, duration, ARGV[2] && ARGV[2].to_i
14
13
 
15
14
  p benchmark_run
16
15
  puts
17
- 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."
16
+ p "#{benchmark_run.requests / benchmark_run.elapsed_time} requests per second. #{benchmark_run.requests} requests in #{benchmark_run.elapsed_time} seconds by #{benchmark_run.visitors} visitors."
18
17
 
19
18
  puts
20
19
  benchmark_run.benchmarks.each do |trans|
@@ -11,13 +11,14 @@ module CelluloidBenchmark
11
11
  attr_accessor :ended_at
12
12
  attr_accessor :logger
13
13
  attr_accessor :started_at
14
+ attr_accessor :visitors
14
15
  attr_reader :thresholds
15
16
 
16
17
  def initialize
17
18
  if !Dir.exists?("log")
18
19
  FileUtils.mkdir "log"
19
20
  end
20
-
21
+
21
22
  # Could replace with Celluloid.logger
22
23
  @logger = ::Logger.new("log/benchmark.log")
23
24
  @thresholds = Hash.new
@@ -27,11 +28,11 @@ module CelluloidBenchmark
27
28
  time = end_time - start_time
28
29
  response_times[label] << time
29
30
  response_codes[label] << http_status_code.to_i
30
-
31
+
31
32
  if threshold
32
33
  thresholds[label] = threshold
33
34
  end
34
-
35
+
35
36
  logger.info "#{http_status_code} #{time} #{label}"
36
37
  end
37
38
 
@@ -42,25 +43,25 @@ module CelluloidBenchmark
42
43
  def response_codes
43
44
  @response_codes ||= Hash.new { |hash, value| hash[value] = [] }
44
45
  end
45
-
46
+
46
47
  def requests
47
48
  response_times.values.compact.map(&:size).reduce(0, &:+)
48
49
  end
49
-
50
+
50
51
  def benchmarks
51
52
  response_times.map do |label, response_times|
52
53
  CelluloidBenchmark::Benchmark.new label, thresholds[label], response_times, response_codes[label]
53
54
  end
54
55
  end
55
-
56
+
56
57
  def mark_start
57
58
  @started_at = Time.now
58
59
  end
59
-
60
+
60
61
  def mark_end
61
62
  @ended_at = Time.now
62
63
  end
63
-
64
+
64
65
  def elapsed_time
65
66
  if started_at && ended_at
66
67
  (ended_at - started_at).to_f
@@ -68,7 +69,7 @@ module CelluloidBenchmark
68
69
  0
69
70
  end
70
71
  end
71
-
72
+
72
73
  def ok?
73
74
  benchmarks.all?(&:ok?)
74
75
  end
@@ -7,37 +7,49 @@ Celluloid.logger = nil
7
7
  module CelluloidBenchmark
8
8
  # Run a scenario in several Visitors and return a BenchmarkRun
9
9
  class Runner
10
- def self.run(session_path, duration = 10, visitors = nil)
10
+ def self.run(session_path, duration = 20, visitors = nil)
11
11
  raise("session_path is required") unless session_path
12
12
  raise("'#{session_path}' does not exist") unless File.exists?(session_path)
13
13
 
14
14
  require session_path
15
15
 
16
16
  VisitorGroup.run!
17
- set_visitors_pool_size visitors
17
+ set_visitor_pool_size visitors
18
+ visitors = visitors_count(visitors)
19
+
18
20
  benchmark_run = Celluloid::Actor[:benchmark_run]
21
+ benchmark_run.visitors = visitors
19
22
 
20
23
  benchmark_run.mark_start
21
- futures = run_sessions(benchmark_run, duration)
24
+ futures = run_sessions(benchmark_run, duration, visitors)
22
25
  futures.map(&:value)
23
26
  benchmark_run.mark_end
24
27
 
25
28
  benchmark_run
26
29
  end
27
30
 
28
- def self.run_sessions(benchmark_run, duration)
29
- visitors = Celluloid::Actor[:visitor_pool]
31
+ def self.run_sessions(benchmark_run, duration, visitors)
32
+ pool = Celluloid::Actor[:visitor_pool]
30
33
  futures = []
31
- (visitors.size - 2).times do
32
- futures << visitors.future.run_session(benchmark_run, duration)
34
+ visitors.times do
35
+ futures << pool.future.run_session(benchmark_run, duration)
33
36
  end
34
37
  futures
35
38
  end
36
39
 
37
- def self.set_visitors_pool_size(size)
40
+ def self.set_visitor_pool_size(size)
38
41
  if size && size.to_i > 0
39
42
  Visitor.pool.size = size.to_i + 2
40
43
  end
41
44
  end
45
+
46
+ def self.visitors_count(count)
47
+ count = count || (Visitor.pool.size - 2)
48
+ if count > 1
49
+ count
50
+ else
51
+ 1
52
+ end
53
+ end
42
54
  end
43
55
  end
@@ -1,3 +1,3 @@
1
1
  module CelluloidBenchmark
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  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.1.4
4
+ version: 0.1.5
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-06-13 00:00:00 Z
12
+ date: 2014-06-19 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid
@@ -62,14 +62,6 @@ dependencies:
62
62
  version: "1.25"
63
63
  type: :runtime
64
64
  version_requirements: *id005
65
- - !ruby/object:Gem::Dependency
66
- name: os
67
- prerelease: false
68
- requirement: &id007 !ruby/object:Gem::Requirement
69
- requirements:
70
- - *id006
71
- type: :runtime
72
- version_requirements: *id007
73
65
  description: |-
74
66
  Celluloid Benchmark realistically load tests websites. Write expressive, concise load tests in Ruby. Use Rubinius and Celluloid
75
67
  forpec high concurrency. Use Mechanize for a realistic (albeit non-JavaScript) browser client.