Class: Typhoeus::Hydra
- Inherits:
-
Object
- Object
- Typhoeus::Hydra
- Includes:
- Before, BlockConnection, EasyPool, Memoizable, Queueable, Runnable, Stubbable
- Defined in:
- lib/typhoeus/hydra.rb,
lib/typhoeus/hydra/before.rb,
lib/typhoeus/hydra/runnable.rb,
lib/typhoeus/hydra/easy_pool.rb,
lib/typhoeus/hydra/queueable.rb,
lib/typhoeus/hydra/stubbable.rb,
lib/typhoeus/hydra/memoizable.rb,
lib/typhoeus/hydra/easy_factory.rb,
lib/typhoeus/hydra/block_connection.rb
Overview
Callbacks are going to delay the request execution.
Hydra manages making parallel HTTP requests. This is achieved by using libcurls multi interface: curl.haxx.se/libcurl/c/libcurl-multi.html The benefits are that you don’t have to worry running the requests by yourself.
Hydra will also handle how many requests you can make in parallel. Things will get flakey if you try to make too many requests at the same time. The built in limit is 200. When more requests than that are queued up, hydra will save them for later and start the requests as others are finished. You can raise or lower the concurrency limit through the Hydra constructor.
Regarding the asynchronous behavior of the hydra, it is important to know that this is completely hidden from the developer and you are free to apply whatever technique you want to your code. That should not conflict with libcurls internal concurrency mechanism.
Defined Under Namespace
Modules: Before, BlockConnection, EasyPool, Memoizable, Queueable, Runnable, Stubbable Classes: EasyFactory
Instance Attribute Summary collapse
- #max_concurrency ⇒ Object readonly
- #multi ⇒ Object readonly private
Class Method Summary collapse
-
.hydra ⇒ Typhoeus::Hydra
deprecated
Deprecated.
This is only for convenience because so much external code relies on it.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Hydra
constructor
Create a new hydra.
Methods included from Before
Methods included from Stubbable
Methods included from BlockConnection
Methods included from Memoizable
Methods included from Runnable
Methods included from Queueable
#abort, #queue, #queued_requests
Methods included from EasyPool
#easy_pool, #get_easy, #release_easy
Constructor Details
#initialize(options = {}) ⇒ Hydra
Create a new hydra. All Ethon::Multi#initialize options are also available.
91 92 93 94 95 |
# File 'lib/typhoeus/hydra.rb', line 91 def initialize( = {}) @options = @max_concurrency = @options.fetch(:max_concurrency, 200) @multi = Ethon::Multi.new(.reject{|k,_| k==:max_concurrency}) end |
Instance Attribute Details
#max_concurrency ⇒ Object (readonly)
52 53 54 |
# File 'lib/typhoeus/hydra.rb', line 52 def max_concurrency @max_concurrency end |
#multi ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 |
# File 'lib/typhoeus/hydra.rb', line 55 def multi @multi end |
Class Method Details
.hydra ⇒ Typhoeus::Hydra
This is only for convenience because so much external code relies on it.
Returns a memoized hydra instance.
68 69 70 |
# File 'lib/typhoeus/hydra.rb', line 68 def hydra @hydra ||= new end |