Skip to content

Commit

Permalink
Docs nits
Browse files Browse the repository at this point in the history
  • Loading branch information
reu committed Jan 30, 2025
1 parent 8d701fb commit 0256c91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Touché shares a lot of similarities with Hyper:
- "Low level"
- Uses the [http crate](https://crates.io/crates/http) to represent HTTP related types
- Allows fine-grained implementations of streaming HTTP bodies
- A simple and easy to read implementation and examples

But also has some key differences:

Expand Down Expand Up @@ -220,35 +221,38 @@ You can find other examples in the [examples directory](https://github.com/reu/t
While the primary focus is having a simple and readable implementation, the library
shows some decent performance.

A simple benchmark of the hello_world.rs example gives the following result:
A simple benchmark of the hello-world.rs example gives the following result:

```sh
$ cat /proc/cpuinfo | grep name | uniq
model name : AMD Ryzen 5 5600G with Radeon Graphics
model name : 13th Gen Intel(R) Core(TM) i7-13700K

$ wrk --latency -t6 -c 200 -d 10s http://localhost:4444
Running 10s test @ http://localhost:4444
6 threads and 200 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 153.37us 391.20us 19.41ms 99.37%
Req/Sec 76.11k 13.21k 89.14k 82.67%
Latency 51.73us 450.03us 29.59ms 99.81%
Req/Sec 251.58k 52.42k 366.43k 70.15%
Latency Distribution
50% 126.00us
75% 160.00us
90% 209.00us
99% 360.00us
4544074 requests in 10.01s, 225.35MB read
Requests/sec: 454157.11
Transfer/sec: 22.52MB
50% 36.00us
75% 47.00us
90% 71.00us
99% 115.00us
15089728 requests in 10.10s, 1.25GB read
Requests/sec: 1494130.41
Transfer/sec: 126.82MB
```

The result is on par with Hyper's hello world running on the same machine.

## Disclaimer

This library is by no means a critique to Hyper or to async Rust. I **really** love both of them.

The main motivation I had to write this library was to be able to introduce Rust to my co-workers
(which are mainly web developers). A synchronous library is way more beginner friendly than an
async one, and by having an API that ressembles the "canonical" HTTP Rust library, people can
learn Rust concepts in a easier way before adventuring through Hyper and async.
(which are mainly web developers).

Most of HTTP server libraries in Rust are async, which makes sense for the problem domain, but with
that some additional complexity comes together, which can be overwhelming when you are just getting
start with the language.

The ideia is to provide an API that ressembles the "canonical" HTTP Rust library, so people can
learn its concepts in a easier way before adventuring through Hyper and async Rust.
10 changes: 4 additions & 6 deletions src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//!
//! Bodies are not buffered by default, so applications don't use memory they don't need.
//!
//! As [hyper](https://docs.rs/hyper) this module has two important pieces:
//!
//! - The [`HttpBody`] trait, which describes all possible bodies. This allows custom
//! implementation if you need fine-grained control on how to stream and chunk the data.
//! - The [`Body`] concrete type, which is an implementation of [`HttpBody`] returned by touche
Expand Down Expand Up @@ -60,8 +58,8 @@ impl BodyChannel {
.map_err(|_| io::Error::new(io::ErrorKind::Other, "body closed"))
}

/// Send a trailer header. Note that trailers will be buffered, so you are not required to send
/// them only after sending all the chunks.
/// Send a trailer header. Note that trailers are buffered, and are only sent after the last
/// chunk is sent
pub fn send_trailer<K, V>(
&self,
header: K,
Expand All @@ -78,8 +76,8 @@ impl BodyChannel {
Ok(self.send_trailers(trailers)?)
}

/// Sends trailers to this body. Not that trailers will be buffered, so you are not required to
/// send then only after sending all the chunks.
/// Sends trailers to this body. Note that trailers are buffered, and are only sent after the
/// last chunk is sent
pub fn send_trailers(&self, trailers: HeaderMap) -> io::Result<()> {
self.0
.send(Ok(Chunk::Trailers(trailers)))
Expand Down

0 comments on commit 0256c91

Please sign in to comment.