Class: RequestPool
- Includes:
- EventMachine::Deferrable
- Defined in:
- ext/puppet-load.rb
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#max_request ⇒ Object
readonly
Returns the value of attribute max_request.
-
#repeat ⇒ Object
readonly
Returns the value of attribute repeat.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#sizes ⇒ Object
readonly
Returns the value of attribute sizes.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
- #add(index, conn) ⇒ Object
- #all_responses ⇒ Object
-
#initialize(concurrency, repeat, parameters) ⇒ RequestPool
constructor
A new instance of RequestPool.
- #spawn_request(index) ⇒ Object
Constructor Details
#initialize(concurrency, repeat, parameters) ⇒ RequestPool
Returns a new instance of RequestPool.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'ext/puppet-load.rb', line 249 def initialize(concurrency, repeat, parameters) @parameters = parameters @current_request = 0 @max_request = repeat * concurrency @repeat = repeat @concurrency = concurrency @requests = [] @responses = {:succeeded => [], :failed => []} @times = {} @sizes = {} # initial spawn (1..concurrency).each do |i| spawn end end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
247 248 249 |
# File 'ext/puppet-load.rb', line 247 def concurrency @concurrency end |
#max_request ⇒ Object (readonly)
Returns the value of attribute max_request.
247 248 249 |
# File 'ext/puppet-load.rb', line 247 def max_request @max_request end |
#repeat ⇒ Object (readonly)
Returns the value of attribute repeat.
247 248 249 |
# File 'ext/puppet-load.rb', line 247 def repeat @repeat end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
246 247 248 |
# File 'ext/puppet-load.rb', line 246 def requests @requests end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
246 247 248 |
# File 'ext/puppet-load.rb', line 246 def responses @responses end |
#sizes ⇒ Object (readonly)
Returns the value of attribute sizes.
246 247 248 |
# File 'ext/puppet-load.rb', line 246 def sizes @sizes end |
#times ⇒ Object (readonly)
Returns the value of attribute times.
246 247 248 |
# File 'ext/puppet-load.rb', line 246 def times @times end |
Instance Method Details
#add(index, conn) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'ext/puppet-load.rb', line 286 def add(index, conn) @requests.push(conn) conn.stream { |data| @sizes[index] += data.length } conn.callback { @times[index] = Time.now - @times[index] code = conn.response_header.status if code >= 200 && code < 300 Puppet.debug("Client #{index} finished successfully") @responses[:succeeded].push(conn) else Puppet.debug("Client #{index} finished with HTTP code #{code}") @responses[:failed].push(conn) end check_progress } conn.errback { Puppet.debug("Client #{index} finished with an error: #{conn.error}") @times[index] = Time.now - @times[index] @responses[:failed].push(conn) check_progress } end |
#all_responses ⇒ Object
314 315 316 |
# File 'ext/puppet-load.rb', line 314 def all_responses @responses[:succeeded] + @responses[:failed] end |
#spawn_request(index) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'ext/puppet-load.rb', line 267 def spawn_request(index) @times[index] = Time.now @sizes[index] = 0 nodeidx = index % $options[:node].size node = $options[:node][nodeidx] EventMachine::HttpRequest.new("https://#{$options[:server]}:#{$options[:masterport]}/production/catalog/#{node}").get( :port => $options[:masterport], :query => @parameters[nodeidx], :timeout => $options[:timeout], :head => { "Accept" => "pson, yaml, b64_zlib_yaml, marshal, dot, raw", "Accept-Encoding" => "gzip, deflate" }, :ssl => { :private_key_file => $options[:key], :cert_chain_file => $options[:cert], :verify_peer => false } ) do @times[index] = Time.now @sizes[index] = 0 Puppet.debug("starting client #{index} for #{node}") end end |