http icon indicating copy to clipboard operation
http copied to clipboard

Extract asynchronous I/O layer (e.g. for Celluloid::IO support)

Open tarcieri opened this issue 8 years ago • 14 comments

I'd like to use this as a master tracking ticket for all feature requests/regressions related to the asynchronous I/O layer/timeout implementation.

I think this is one of the most interesting parts of this gem (thanks @zanker) and the two of us have discussed extracting it into a separate gem:

https://github.com/zanker/socketry

The addition of this feature broke Celluloid::IO support. Once upon a time several people suggested to me Celluloid::IO support was the only interesting feature of this gem. I hope we've proved them wrong!

I would still like to support Celluloid::IO as a timeout backend, but it needs the work to add it to the existing timeout framework.

I am tagging this as a milestone 2.0 option for two options:

  1. I don't think anyone plans on working on it soon
  2. It would arguably be a breaking API change

tarcieri avatar Dec 13 '15 01:12 tarcieri

Yea I'd like to work on Socketry but it looks like I'll not have time for a while :(

zanker avatar Dec 14 '15 04:12 zanker

I was following #225 but without much familiarity with the history I feel a little short on context from the description of this new ticket—I've swiftly browsed what code exists in the Socketry repo, but since it lacks specs and a high-level README description at this point, would you guys mind expanding a little either there or here on it when you have time? I.e. what is the intended focus/scope of Socketry? From @tarcieri's remarks above it sounds to me something like "uniform interface abstraction layer for Ruby asynchronous I/O", but "Socket wrapper around Ruby" sounds a bit conceptually different from that, so not sure that I understand correctly.

Would the idea be that httprb uses the Socketry API, then adapters can be implemented for Socketry to be backed with Celluloid::IO, EventMachine, perhaps Cool.io if someone has a legacy case to support, etc.?

ches avatar Dec 21 '15 09:12 ches

@ches it'd basically be a wholesale extraction of the current timeout code, which has a synchronous API, but async I/O for implementing timeouts.

It would work with core Ruby and Celluloid::IO. It could not work with EventMachine and Cool.io, because they're callback-driven.

Right now it is very difficult to implement I/O with timeouts in Ruby without using core timeout.rb, which is unsafe due to its use of threads/Thread#raise.

The timeout code in this library implements them safely by using IO.select to wait for I/O readiness or a timeout.

Celluloid::IO does something similar using nio4r selectors.

tarcieri avatar Dec 21 '15 18:12 tarcieri

We've actually went for this gem strictly because of Celluloid::IO support, and seeing it removed from v1.0 is a major issue for us. I'm not looking for commitments, just some general info to have a good understanding of the situation. Is there any rough timeframe for v2.0? Are there any alternatives / workarounds for making the gem work with Celluloid::IO?

msufa avatar Jan 11 '16 12:01 msufa

@tarcieri do you remember what broke with Celluloid::IO? I thought it was due to the timeout portions, we could just make a Celluloid timeout class for people to use I think.

zanker avatar Jan 11 '16 14:01 zanker

Yeah, we'd need a Celluloid::IO timeout backend

tarcieri avatar Jan 11 '16 17:01 tarcieri

It's pretty easy to do, but I'm probably not going to have time to do it this week. I can take a look next week @msufa.

zanker avatar Jan 11 '16 17:01 zanker

Excellent! Thanks for the support and swift response @zanker

msufa avatar Jan 11 '16 17:01 msufa

@zanker did you get around to looking at it? I'm currently trying to assess the near-future state of Celluloid Support for this gem.

ccoenen avatar Aug 31 '16 15:08 ccoenen

I've started working on it. I should have the basic pieces of it relatively soon

tarcieri avatar Aug 31 '16 15:08 tarcieri

Here's a WIP: https://github.com/celluloid/socketry/pull/3

tarcieri avatar Sep 04 '16 03:09 tarcieri

Socketry is shaping up now: https://github.com/socketry/socketry

It's mostly feature complete at this point. Still a little work to do.

I started trying to convert http.rb to use it. Note that it only provides an equivalent of HTTP::Timeout::PerOperation, so HTTP::Timeout::Global will need to stay in this library. But that makes sense (I think), because those timeouts need to have knowledge of the request lifecycle.

tarcieri avatar Sep 12 '16 18:09 tarcieri

Thank you for the work on this. Is there any experimental version yet to try this out? -- If not, can you recommend any high level HTTP library that works inside of Celluloid::IO?

Socketry looks great, but presumably it is pure access to the socket rather than an HTTP library.

tetherit avatar Feb 16 '17 00:02 tetherit

You can try the socketry branch (from #377) although there's a bit more work involved to make it fully Celluloid::IO compatible.

tarcieri avatar Feb 16 '17 00:02 tarcieri