Class: Drnbench::HttpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/drnbench/client/http.rb

Direct Known Subclasses

HttpDroongaClient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, config) ⇒ HttpClient

Returns a new instance of HttpClient.



24
25
26
27
28
# File 'lib/drnbench/client/http.rb', line 24

def initialize(params, config)
  @requests = params[:requests]
  @result   = params[:result]
  @config   = config
end

Instance Attribute Details

#requestsObject (readonly)

Returns the value of attribute requests.



22
23
24
# File 'lib/drnbench/client/http.rb', line 22

def requests
  @requests
end

#resultsObject (readonly)

Returns the value of attribute results.



22
23
24
# File 'lib/drnbench/client/http.rb', line 22

def results
  @results
end

#waitObject (readonly)

Returns the value of attribute wait.



22
23
24
# File 'lib/drnbench/client/http.rb', line 22

def wait
  @wait
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/drnbench/client/http.rb', line 30

def run
  @thread = Thread.new do
    loop do
      request = @requests.pop
      request = fixup_request(request)

      client = Droonga::Client.new(:protocol => :http,
                                   :host => request["host"],
                                   :port => request["port"])
      request["headers"] ||= {}
      request["headers"]["user-agent"] = "Ruby/#{RUBY_VERSION} Droonga::Benchmark::Runner::HttpClient"
      start_time = Time.now
      response = client.request(request)
      @result << {
        :request => request,
        :status => response.code,
        :elapsed_time => Time.now - start_time,
      }
      sleep @config.wait
    end
  end
  self
end

#stopObject



54
55
56
# File 'lib/drnbench/client/http.rb', line 54

def stop
  @thread.exit
end