tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.79k stars 2.47k forks source link

Restructure documentation from the ground up #13

Closed alexcrichton closed 6 years ago

alexcrichton commented 7 years ago

One of the most frequent pieces of feedback we get about futures and Tokio in Rust is "it's confusing!" While https://tokio.rs has some great content it doesn't seem to have stood well against the test of time. It's time we rewrite/restructure our documentation from the ground up. I hope to use this issue to track this work and provide a location to discuss it as well!

@aturon and I talked a bit today about how to start structuring docs, and we came initially to some high-level conclusions:

Other than that, here's the thinking for an outline so far:

Compare and contrast sync and async

Behind the curtain: Futures

I/O with futures


There's definitely quite a bit to fill out here! We'll try to do that over time.

carllerche commented 7 years ago

Here is my current (rough) outline for docs:

carllerche commented 7 years ago

Re: Async / await, I strongly feel that the documentation should be built off stable Rust by default. Examples can have both stable & async / await versions and docs can reference / explain async / await & link to external resources on it, but the flow should not be based on it until it hits stable.

carllerche commented 7 years ago

It should also be plausible to work on the docs incrementally vs. a long lived branch.

Ixrec commented 7 years ago

Take this with a grain of salt since I haven't had an opportunity to use tokio (or any other Rust code) for any serious projects, but I did experience some confusion back when I read the tokio docs "cover to cover". I believe that was primarily because of the counterintuitiveness of the poll method/the Future trait, but also partially because a large portion of it simply wasn't useful information for writing high-level applications. Some concrete suggestions:

Everything else I can think of (e.g., more examples!) is already in the OP post.

skinowski commented 7 years ago

I know you have already noted this above, but yes, could you please strive towards more real world examples?

Such as:

alexcrichton commented 7 years ago

Some notes from a chat earlier today:

We'll probably want an FAQ or otherwise style page about maintaining state with futures. Right now most futures are 'static but idiomatic methods in Rust already are &self, and this causes quite the tension when you say, want to use &self inside of an and_then closure.

Today you need to restort to using self and threading ownership or to use Rc or some other reference-counted sharing solution likely. We should document this explicitly and explore the various tradeoffs as well.

qmx commented 6 years ago

something I just stumbled upon, it would be nice to have an example where you pass down a &msg down to a spawn_fn - pretty desirable when you're parsing binary data from things like kafka

00imvj00 commented 6 years ago

I struggled a lot while learning futures/tokio, I will note down reasons, this might help you guys to give some perspective from a normal newcomer.

1) Hello, world. But, simple, describe how to get data from stream clearly, and how to send data through sink clearly, instead of using Copy or some abstract method.

2) How to work with raw byte streams instead of using abstract framed on socket and then use encoder, decoder. Why this? because, if I am coming from another language, I will be familiar with byte streams, so it will be a little bit confusing for me to understand encoder and decoder at first, no doubt they are really cool features.

3) Is single thread enough for C10K problem? This is I get allot in my mind, will single threaded loop will be able to handle such a big connection pool, (Why? because I don't know that many lower level details and it has always been taught to me that multithreaded applications are always good and all, so, just clarifying on that will relax new users on how Tokio is really cool for building applications.)

4) Simple Example on how to scale Tokio in terms of big applications, like how to architect code and all the modules. What should be a standard way of handling functions and returning values.

5) If possible, small example on how to create multiple reactors on different threads and then provide work to those threads from other threads.

6) Simple standard to build client applications. 7) Simple standard to build server applications.

point 6, 7 are not in terms of giving traits and implement them, just with example if you guys can demonstrate that, if you were to build Tokio servers, this is how you would build. This may boost a lot of confidence in newcomers.

It's not much, but I hope my input help grow Tokio.

aturon commented 6 years ago

Thanks @0freeman00! I'm working actively on a small book for async programming in Rust, and have already taken into account many of the suggestions you present. Talking specifically about the C10K problem (or similar), though, in an interesting twist; I'll give it some thought.

00imvj00 commented 6 years ago

@aturon waiting for the book to come out then. :)

HadrienG2 commented 6 years ago

Just saw a great source of inspiration for "advanced user"/"reference" documentation passing by in TWIR: https://cafbit.com/post/tokio_internals/ .

carllerche commented 6 years ago

@aturon do you have any updates on the book?

carllerche commented 6 years ago

There has been miscommunication and @aturon has not been planning on writing this book as documentation, so this is still an open issue.

aturon commented 6 years ago

An extremely early version is up here, but it's based on a bunch of changes to the relevant crates that have since seen further iteration. I've been holding off further work on it until the dust settles a bit on the design.