Faraday parallelism support #1386
Replies: 4 comments 19 replies
-
https://github.com/socketry/async-http-faraday already solves this problem with no changes to the current interface. The only complexity is the per-thread mapping of connections since we don't support multi-thread reactor in Async as a matter of design. I would personally just remove any kind of concurrency/parallelism "manager"/ |
Beta Was this translation helpful? Give feedback.
-
@ioquatix Isn't |
Beta Was this translation helpful? Give feedback.
-
A note on implementation. Some times ago, I started working on making the retry middleware work in parallel. However, the major issue I encountered was when I was starting to add multiple middlewares, especially the Raise Error Middleware is a pain since it shortcuts any other one and forces another middleware implementation to be aware of its existence. I think this tight coupling makes developers less likely to contribute and errors more likely to happen due to the improved complexity. And of course, maintainance is also harder. IMHO, this is mostly due to:
The point being: nowaday, Faraday is a bit too complete to support parallelism AND keep its simplicity. I think you mentioned at some point that you wanted to refactor the middleware chain. This would be a better time to introduce parallelism IMHO. |
Beta Was this translation helpful? Give feedback.
-
Found back the thread were I was weighting creating a gem dedicated to parallel requests: typhoeus/typhoeus#182 (comment) |
Beta Was this translation helpful? Give feedback.
-
Introduction
One of the objectives of our Faraday 3.0 Wishlist is to "Revisit pipelining or parallel requests".
With the advent of
Async
, Ruby 3.0 has really pressed on the accelerator when it comes to parallelism and concurrency, and the community is expecting more and more libraries to make this a big focus in the coming months and years.Faraday has always supported requests parallelism for compatible adapters via a "parallel manager", but this was written years ago and does not really reflect the current state of the Ruby world.
We should take this opportunity to revisit how parallelism is managed in faraday, how middleware/adapters can opt-in to it and how developers can easily use it in their projects.
Async and a new concurrency style
Async
has really shaken the Ruby world, so much so that it gained official support in Ruby 3.0.The promises are really high: allow Ruby engineers to run concurrent tasks in Ruby without having to worry about callbacks or making distinctions between sync and async methods (JS developers will know!).
Interestingly enough, Faraday's default adapter
net_http
already supportsAsync
, as the following snippet shows:This opens up to the possibility of supporting parallel requests without even the need to use complex "parallel managers" or similar hacks. On the flip side, this relies on the underlying library support for Async, which may not be offered by all HTTP libraries.
Issues with the current parallel interface
The current interface looks simple and powerful at first glance:
However it does have some setbacks:
support_parallel?
method or reading it's documentation.call
oron_request/on_complete
is cause for confusion.An alternative implementation
Ideally a better, easier implementation would bring the following benefits:
cc @avmnu-sng, @BuonOmo, @ioquatix
Beta Was this translation helpful? Give feedback.
All reactions