As of `http-body` 0.4.1 its has had a `BoxBody` type similar to
`tonic::body::BoxBody`. It also has `Empty` and `Body::map_{data,err}`.
That means all the custom body things we had in tonic can basically be
replaced with that.
Note that this is a breaking change so we should merge this next time we
decide to ship a breaking release.
The breaking changes are:
- `tonic::body::Body` has been removed. I think its fine for users to
depend directly on `http-body` if they need this trait.
- `tonic::body::BoxBody` is now just a type alias for
`http_body::combinators::BoxBody<Bytes, Status>`. So the methods it
previously had are gone. The replacements are
- `tonic::body::Body::new` -> `http_body::Body::boxed`
- `tonic::body::Body::map_from` -> `http_body::Body::map_data` and
`http_body::Body::map_err` depending on which part you want to map.
- `tonic::body::Body::empty` -> `http_body::Empty`
Additionally a `Sync` bound has been added to a few methods. I actually
don't think this is a breaking change because the old
`tonic::body::Body` trait had `Sync` as a supertrait meaning the `Sync`
requirement was already there.
Fixes https://github.com/hyperium/tonic/issues/557
Criterion benchmarks for Tonic
Running the benchmarks
From the root Tonic directory, cargo bench
After running, the reports can be found in tonic/target/criterion/report/index.html
Gnuplot is required for graph generation. If gnuplot is not installed, Criterion will display: Gnuplot not found, disabling plotting at the console.
Notes
- Currently, these benchmarks only test the performance of constructing Tonic Requests and Responses, not over-the-wire throughput.
- The
thrptvalue generated by Criterion is simply a measure of bytes consumed by the target function. - As we are not testing tonic-build compile time, the tests reference pre-compiled .rs files in 'benchmarks/compiled_protos'.
- The original proto files are in the
protodirectory for reference. - This used the Criterion 3.0
Criterion Groupfunctionality. Details here: https://docs.rs/criterion/0.3.0/criterion/
Interpreting Results
Criterion is particularly useful for establishing a first-run baseline and then comparing after code-changes - e.g. Performance has regressed below.
Request_Response/request/100000
time: [2.7231 us 2.7588 us 2.7969 us]
thrpt: [33.298 GiB/s 33.758 GiB/s 34.200 GiB/s]
change:
time: [+16.073% +17.871% +19.980%] (p = 0.00 < 0.05)
thrpt: [-16.653% -15.162% -13.847%]
Performance has regressed.
Found 3 outliers among 100 measurements (3.00%)
1 (1.00%) high mild
2 (2.00%) high severe