Skip to content

Instantly share code, notes, and snippets.

@ezkl
Created April 1, 2012 07:26
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ezkl/2272636 to your computer and use it in GitHub Desktop.
Save ezkl/2272636 to your computer and use it in GitHub Desktop.
Parallel Requests w/ Faraday + Typhoeus
require "faraday"
require 'typhoeus'
conn = Faraday.new(:url => 'http://httpstat.us') do |builder|
builder.request :url_encoded
builder.response :logger
builder.adapter :typhoeus
end
conn.in_parallel do
# will use Hydra's default settings: max_concurrency: 200, memoization, initial request pool size: 10
end
require "faraday"
require 'typhoeus'
HYDRA = Typhoeus::Hydra.new(:max_concurrency => 5)
HYDRA.disable_memoization
conn = Faraday.new(:url => "http://httpstat.us", :parallel_manager => HYDRA) do |builder|
builder.request :url_encoded
builder.adapter :typhoeus
end
conn.in_parallel do
# Will use user-defined Hydra settings: max_concurrency: 5, no memoization
end
@ezkl
Copy link
Author

ezkl commented Apr 1, 2012

@ezkl
Copy link
Author

ezkl commented Apr 1, 2012

The first example will use Typhoeus::Hydra w/ default settings:

  • max concurrency of 200
  • starting request pool size of 10
  • request memoization

The second example shows how to override Typhoeus::Hydra defaults w/ a custom parallel_manager

See Typhoeus::Hydra

@swistaczek
Copy link

great! Thanks ;)

@tpitale
Copy link

tpitale commented Sep 26, 2014

New location for faraday Parallel requests wiki: https://github.com/lostisland/faraday/wiki/Parallel-requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment