Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-blocking IO support with Ruby 3.x fiber scheduler #211

Open
dbackeus opened this issue Mar 23, 2022 · 1 comment
Open

Non-blocking IO support with Ruby 3.x fiber scheduler #211

dbackeus opened this issue Mar 23, 2022 · 1 comment

Comments

@dbackeus
Copy link

dbackeus commented Mar 23, 2022

No idea about the feasibility of this but would be really nice if ethon could enable non-blocking IO when using a Ruby 3.x fiber scheduler the same way as Ruby's native IO libraries.

For example the following will execute in ~2 seconds:

require "fiber_scheduler"
require "open-uri"

Fiber.set_scheduler(FiberScheduler.new)

Fiber.schedule do
  URI.open("https://httpbin.org/delay/2")
end

Fiber.schedule do
  URI.open("https://httpbin.org/delay/2")
end

While using ethon will block on each HTTP request and execute in ~4 seconds:

require "fiber_scheduler"
require "ethon"

Fiber.schedule do
  Ethon::Easy.new(url: "https://httpbin.org/delay/2").perform
end

Fiber.schedule do
  Ethon::Easy.new(url: "https://httpbin.org/delay/2").perform
end

These examples assume using Ruby 3.1.x with the fiber_scheduler gem installed.

Supporting non blocking IO will be important for eg. typhoeus to remain popular while more and more Ruby code migrates towards using fibers for more efficient IO.

@hanshasselberg
Copy link
Member

Ethon is a little bit different because it is a wrapper for libcurl. Libcurl however already supports parallel requests and so does Ethon via Multi: https://rubydoc.info/github/typhoeus/ethon/Ethon/Multi. And Typhoeus via Hydra: https://github.com/typhoeus/typhoeus/#making-parallel-requests.

I don't think we can add support for fiber. But I might be wrong and I am would be happy to learn about a way to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants