Class: VisitBench
- Inherits:
-
Object
- Object
- VisitBench
- Defined in:
- lib/visit_bench.rb
Overview
Visitbench stresstests your server by simulation real user sessions.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_session {|s| ... } ⇒ Object
add a session with preinitialized values.
-
#initialize(options = {}) {|_self| ... } ⇒ VisitBench
constructor
A new instance of VisitBench.
-
#run(options = {}) ⇒ Object
run the sessions multiple times and run them in parallel.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ VisitBench
Returns a new instance of VisitBench.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/visit_bench.rb', line 11 def initialize( = {}) @host = [:host] || 'localhost' @browser = Mechanize.new @browser.log = Logger.new(STDOUT) if [:debug] [:headers] ||= [] [:headers].each do |k,v| @browser.request_headers[k] = v end @browser.basic_auth([:username], [:password]) if [:username] @sessions = [:sessions] || [] yield self end |
Class Method Details
.benchmark(&block) ⇒ Object
53 54 55 56 57 |
# File 'lib/visit_bench.rb', line 53 def benchmark(&block) begin_time = Time.now yield return Time.now - begin_time end |
Instance Method Details
#add_session {|s| ... } ⇒ Object
add a session with preinitialized values
26 27 28 29 30 |
# File 'lib/visit_bench.rb', line 26 def add_session s = Session.new(:request_options => {:host => @host, :browser => @browser}) yield s @sessions << s end |
#run(options = {}) ⇒ Object
run the sessions multiple times and run them in parallel
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/visit_bench.rb', line 33 def run( = {}) amt_times = [:amt_times] || 10 concurrent_users = [:concurrent_users] || 3 run_times = [] amt_times.times do |i| trs = [] concurrent_users.times do puts "Starting thread" trs << Thread.new do session = @sessions[(@sessions.length - 1) * rand] run_times << session.run end end trs.each {|x| x.join } end run_times end |