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instance Attribute Summary collapse
-
#failed_requests ⇒ Object
Returns the value of attribute failed_requests.
-
#successfull_requests ⇒ Object
Returns the value of attribute successfull_requests.
Instance Method Summary collapse
- #concurrent_users=(num) ⇒ Object
- #follow_links=(flag) ⇒ Object
-
#initialize ⇒ Requester
constructor
A new instance of Requester.
- #num_of_requests=(num) ⇒ Object
- #print_stats ⇒ Object
- #proceed ⇒ Object
- #url=(link) ⇒ Object
Constructor Details
#initialize ⇒ Requester
Returns a new instance of Requester.
20 21 22 23 24 25 26 27 28 |
# File 'lib/requester.rb', line 20 def initialize @response_length = 0 @total_time = 0.0 @threads = [] @mutex = Mutex.new @failed_requests = 0 @successfull_requests = 0 @follow_links = false end |
Instance Attribute Details
#failed_requests ⇒ Object
Returns the value of attribute failed_requests.
12 13 14 |
# File 'lib/requester.rb', line 12 def failed_requests @failed_requests end |
#successfull_requests ⇒ Object
Returns the value of attribute successfull_requests.
11 12 13 |
# File 'lib/requester.rb', line 11 def successfull_requests @successfull_requests end |
Instance Method Details
#concurrent_users=(num) ⇒ Object
30 31 32 |
# File 'lib/requester.rb', line 30 def concurrent_users=(num) @concurrent_users = num end |
#follow_links=(flag) ⇒ Object
38 39 40 41 42 |
# File 'lib/requester.rb', line 38 def follow_links=(flag) @follow_links = flag # we could follow links on the pages if there's --follow-links=2 option require 'nokogiri' if @follow_links end |
#num_of_requests=(num) ⇒ Object
34 35 36 |
# File 'lib/requester.rb', line 34 def num_of_requests=(num) @num_of_requests = num end |
#print_stats ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/requester.rb', line 49 def print_stats puts print "Failed requests: #{@failed_requests}\n" print "Succeeded requests: #{@successfull_requests}\n\n" print "Total response length: #{@response_length} bytes\n" if @successfull_requests > 0 print "Recieved characters per one page: #{@response_length / @successfull_requests} bytes\n\n" end printf "Total time: %.03f s\n", @total_time printf "Average time per request: %.03f s\n", @total_time / @successfull_requests.to_f printf "Requests per second: %.01f rps\n", 1.0 / (@total_time / @successfull_requests.to_f) end |
#proceed ⇒ Object
64 65 66 67 |
# File 'lib/requester.rb', line 64 def proceed prepare_queue start_threads end |
#url=(link) ⇒ Object
44 45 46 47 |
# File 'lib/requester.rb', line 44 def url=(link) @url = URI.parse(link) @url.path = '/' if @url.path == "" # ensure we requesting main page (if url is like http://google.com) end |