Open withoutboats opened 6 years ago
If I'm reading this correctly, it sounds like romio
at this stage is more about unblocking people for their common cases rather than providing best-possible performance. I'm more or less interpreting that as: "Having APIs available is more important than how well they perform".
tokio-fs
, this seems important to get the API right for. If the existing code is tricky to port, perhaps using a simpler implementation might make more sense (e.g. not using a hashed wheel timer, but something more straight forward).The timer would not be hard to port, seems like a good idea. File system APIs OTOH are much harder because their implementation is currently coupled to tokio-threadpool
.
@withoutboats I'm not deeply familiar with the API surface there, but (riffing on @yoshuawuyts's angle) it seems feasible to provide a more direct/naive implementation that doesn't require this coupling.
We got rid of the spawn API on the context object (now just a waker). I'm not sure how even a more naive implementation could do something like "spawn a blocking read as another task on the current executor" unless we brought the "default spawn API" stuff back either here or in futures. We could just implement them as blocking APIs that look nonblocking, but that seems nonideal.
I'll look more into the implementation in tokio and the APIs we do have in futures, maybe it can inform the executor APIs.
it would be a completely new implementation of async FS IO though, not a port. which is fine!
Ahha I see; I wasn't thinking about needing to have some canonical place to spawn. Of course one option is to just require an executor to be passed in.
FWIW, I feel like this points to an ecosystem-wide problem we should solve, in a way that's independent from any particular I/O stack. Rayon has a pretty nice story here. Probably worth opening an issue on WG-net.
I think it's fine for the fs
APIs to not make the first cut, to be clear.
I'm going to port tokio-timer and not tokio-signal or tokio-fs. Later, I think trying to solve the filesystem situation that led to tokio-fs without tying the impl to a specific executor will have fruitful results for evolving on the executor API.
Similar, tokio-codec defines a set of abstractions for writing network protocols; while these are very valuable they also aren't a part of the "just the async IO primitives" vision that this crate has.
I would port tox-rs to your crate if you implemented a must-have feature codec
. A lot of code depends on Encoder
, Decoder
and Framed
, so if you have an idea of a workaround it would help a lot.
Also I noticed tokio
is not usable on wasm
target. We would love to implement a client in wasm
but we need an async io for WebSocket
. mio
depends on epoll
which is unavailable for wasm
target, but it can be done by integrating web_sys::WebSocket
and wasm_bindgen_futures
(probably).
I think having the functionality of tokio-codec
is definitely going to be important for trying out romio
, but as @withoutboats mentions this isn’t specific to the low-level IO primitives. Since we have the futures-io@0.3
traits this could be implemented as something like futures-io-codec
and work with any async io implementation. @kpp it might be worth bringing it up in an issue on the futures repo as to whether it’s something that should be prototyped there, or as a separate project.
@kpp I recently implemented tokio AsyncRead/AsyncWrite for websockets in WASM. It's quite proof of concept at the moment, but the code base is small, and it can be improved (main issue, the unit tests fail in release mode and I haven't figured out why). For futures 0.1, the wasm-workgroup are implementing a nicer api to websockets in wasm.
@withoutboats would it make sense to implement an equivalent to tokio-codec for the futures::io::AsyncRead from 0.3. Mainly, I wonder is futures::io::AsyncRead the logical successor of tokio AsyncRead? Would that component shift from the tokio crate to the futures crate after async/await stabilizes?
ould it make sense to implement an equivalent to tokio-codec for the futures::io::AsyncRead from 0.3.
I think definitely! I almost have something that can be released under the async WG; if not next week, then probably the week after. Fully with you that it's important to make converting between Async{Read,Write}
and {Sink, Stream}
easy.
I almost have something that can be released under the async WG; if not next week, then probably the week after.
Awesome. tokio codec is the main reason I'm still using futures 0.1 in some places. Looking forward to migrating that out.
btw, is your code in a public repository or is it to early?
@najamelan it's private, but I can send you an invite on it to try out early if you like (: -- still working out some edges before a release, but having another set of eyes to look at it is always helpful!
@yoshuawuyts I'd love to beta test. I have some codecs to write soon, and I'd rather target the future than the past ;) If you have specific review questions, it can help focus on the parts you're not happy with. Thanks for the invitation.
Awesome. tokio codec is the main reason I'm still using futures 0.1 in some places. Looking forward to migrating that out.
It is time to write futures-codec with a modern async/await design and with futures 0.3 support!
@najamelan et. al., I have written a generic codec as part of my ardop_interface
crate. It presently targets futures-preview 0.3.0-alpha.16
. I'm not sure it's good enough to publish on its own, but you are welcome to use it if you need one. Like the old Tokio 0.1 codec, this one depends on bytes
for its API. The examples include a newline framer and a server demo. The crate itself has more complicated framers internally.
@cbs228 there is https://crates.io/crates/futures_codec. Is it enough?
@kpp: That crate escaped my notice when I began development. It very likely will suffice!
@cbs228 alternatively it's also possible to use the codec pattern. This isn't always the right choice, especially when porting older code from e.g. tokio-codec
, but might be a nice tool to use for newer projects.
This port is just supposed to be the core of tokio, to unblock people who want to build on top of async/await. Much of tokio is not included in this for that reason.
For example,
tokio-threadpool
is an executor implemented using a work-stealing threadpool. It's a valuable step up over the executors provided in the futures crate, but not an IO primitive, so not a part of this particular port's vision of itself.Similar,
tokio-codec
defines a set of abstractions for writing network protocols; while these are very valuable they also aren't a part of the "just the async IO primitives" vision that this crate has.However, other parts of tokio are more ambiguous: