hyper: simplify handlers
- move the server header to the router and add it to all responses.
- move the response boxing to the router simplifying the return types of each handler.
https://github.com/hyperium/http-body/pull/150 will simplify the router code even futher to the following:
let mut response = match request.uri().path() {
"/ping" => ping()?.box_body(),
"/json" => json::get()?.box_body(),
"/db" => single_query::get().await?.box_body(),
"/queries" => multiple_queries::get(request.uri().query()).await?.box_body(),
"/fortunes" => fortunes::get().await?.box_body(),
"/plaintext" => plaintext::get()?.box_body(),
_ => not_found_error()?.box_body(),
};
Note: includes commits from #9727. Relevant commit that's only this change is https://github.com/TechEmpower/FrameworkBenchmarks/pull/9728/commits/a50128f137861d9d995acf2a6d52b6af23f0580c
The following frameworks were updated, pinging maintainers:
hyper: @polachok, @seanmonstar, @steveklabnik
Local benchmark results (Macbook Pro M2 Max)
Before the recent hyper changes:
hyper (JSON + Plaintext):
https://www.techempower.com/benchmarks/#section=test&shareid=69e73a28-4d6c-4aa8-821b-27eb62b7e616&hw=ph&test=json
JSON responses per second, (unspecified, hostname = 48c41e9f7187)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper | 196,760 | 508,649 | 624,762 | 729,611 | 727,629 | 811,146 | 811,146 | 0 | Mcr | rs | rs | hyp | lin | rea |
Plaintext responses per second, (unspecified, hostname = 48c41e9f7187)
| Framework | 256 | 1,024 | 4,096 | 16,384 | Best | Errors | Cls | Lng | Plt | FE | Aos | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper | 5,481,306 | 5,887,571 | 5,447,194 | 4,462,003 | 5,887,571 | 0 | Mcr | rs | rs | hyp | lin | rea |
- hyper-db (Fortunes): https://www.techempower.com/benchmarks/#section=test&shareid=5502a537-4af9-4ba6-b1d5-d535309b5304&hw=ph&test=fortune
Fortunes responses per second, (unspecified, hostname = e0169ecd4a21)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper | 80,846 | 177,855 | 129,424 | 141,055 | 147,723 | 149,434 | 177,855 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
After this change:
hyper (current-thread runtime):
https://www.techempower.com/benchmarks/#section=test&shareid=0be4944f-3746-4ff5-a6d5-6537c33df272&hw=ph&test=json
JSON responses per second, (unspecified, hostname = b7f8f718c8cc)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (current-thread runtime) | 207,752 | 470,367 | 598,843 | 692,511 | 821,558 | 872,231 | 872,231 | 0 | Mcr | rs | rs | hyp | lin | rea |
Database-access responses per second, single query, (unspecified, hostname = b7f8f718c8cc)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (current-thread runtime) | 49,527 | 82,542 | 133,047 | 119,479 | 118,664 | 105,070 | 133,047 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
Responses per second, multiple queries, (unspecified, hostname = b7f8f718c8cc)
| Framework | 1 | 5 | 10 | 15 | 20 | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (current-thread runtime) | 115,887 | 30,055 | 15,253 | 10,466 | 7,838 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
Fortunes responses per second, (unspecified, hostname = b7f8f718c8cc)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (current-thread runtime) | 45,863 | 80,784 | 122,626 | 113,597 | 111,767 | 108,218 | 122,626 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
Plaintext responses per second, (unspecified, hostname = b7f8f718c8cc)
| Framework | 256 | 1,024 | 4,096 | 16,384 | Best | Errors | Cls | Lng | Plt | FE | Aos | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (current-thread runtime) | 4,498,684 | 5,150,947 | 5,067,568 | 4,265,876 | 5,150,947 | 0 | Mcr | rs | rs | hyp | lin | rea |
hyper (multi-thread runtime):
https://www.techempower.com/benchmarks/#section=test&shareid=e44af5ec-34be-4542-bb04-f970a375a62e&hw=ph&test=json
JSON responses per second, (unspecified, hostname = cda50185af70)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (multi-thread runtime) | 136,775 | 205,623 | 280,521 | 351,340 | 517,568 | 681,464 | 681,464 | 0 | Mcr | rs | rs | hyp | lin | rea |
Database-access responses per second, single query, (unspecified, hostname = cda50185af70)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (multi-thread runtime) | 60,558 | 80,468 | 114,034 | 125,198 | 123,046 | 123,854 | 125,198 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
Responses per second, multiple queries, (unspecified, hostname = cda50185af70)
| Framework | 1 | 5 | 10 | 15 | 20 | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (multi-thread runtime) | 124,719 | 31,089 | 16,536 | 11,172 | 8,463 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
Fortunes responses per second, (unspecified, hostname = cda50185af70)
| Framework | 16 | 32 | 64 | 128 | 256 | 512 | Best | Errors | Cls | Lng | Plt | FE | Aos | DB | Dos | Orm | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (multi-thread runtime) | 57,991 | 79,421 | 110,869 | 120,830 | 121,191 | 119,472 | 121,191 | 0 | Mcr | rs | rs | hyp | lin | Pg | lin | raw | rea |
Plaintext responses per second, (unspecified, hostname = cda50185af70)
| Framework | 256 | 1,024 | 4,096 | 16,384 | Best | Errors | Cls | Lng | Plt | FE | Aos | IA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hyper (multi-thread runtime) | 4,216,747 | 4,716,550 | 4,561,864 | 4,090,954 | 4,716,550 | 0 | Mcr | rs | rs | hyp | lin | rea |
There's definitely a performance degradation in the results, and I haven't investigated why yet. The goal of the changes was to make the source a bit more maintainable, and then work on improving the perf aspects on top of that in ways where the code which impacts performance can be a bit more obvious and measured (with test variants). Because hyper is also the base for many of the rust frameworks, having numbers for each of the tests allows this to be used as the framework overhead in those tests (using the "versus" field in the configs", which would help show which parts of the perf are just pure hyper and which are from framework overhead (or in some cases improvements).
This PR now has conflicts due to the force-rm PR that was merged this morning. Much of it is likely also out of date. Closing for grooming - feel free to reopen once all issues are addressed.