Sha256: 5aa7646937f211ab1619d1b7235007a19bac2043c0a3d6274c08db3945f1c2d8

Contents?: true

Size: 926 Bytes

Versions: 2

Compression:

Stored size: 926 Bytes

Contents

module Nacjac
  class Cannon
    def initialize(target_url, thread_num, duration)
      @target_url    = target_url
      @thread_num    = thread_num
      @duration      = duration
      @request_times = []
    end

    def blast
      end_time = Time.now + @duration
      while (Time.now < end_time)
        @request_times << shoot
      end
    end

    def report
      @request_times.flatten!
      total = @request_times.count
      failed = total - @request_times.compact.count
      total_time = @request_times.compact.inject(0){|a, b| a + b}
      puts "Total Requests   : #{total}"
      puts "Failed Requests  : #{failed}"
      puts "Average Time     : #{total_time/total}"
    end

    private
    def shoot
      futures = []
      (1..@thread_num).each do |t|
        @projectile = Projectile.new(@target_url)
        futures << @projectile.future.launch
      end
      futures.map(&:value)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nacjac-0.0.2 lib/nacjac/cannon.rb
nacjac-0.0.1 lib/nacjac/cannon.rb