Skip to content

Commit 44a869e

Browse files
feat: upgrade axum & dependencies, refactor, and add code and build optimisations (#9237)
1 parent b8c31e2 commit 44a869e

38 files changed

+1741
-1476
lines changed

frameworks/Rust/axum/Cargo.lock

Lines changed: 827 additions & 609 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/Rust/axum/Cargo.toml

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
2-
name = "axum"
3-
version = "0.2.0"
2+
name = "axum-techempower"
3+
version = "0.2.1"
44
authors = ["Dragos Varovici <[email protected]>"]
55
edition = "2021"
66

@@ -28,28 +28,63 @@ path = "src/main_mongo_raw.rs"
2828
name = "axum-pg"
2929
path = "src/main_pg.rs"
3030

31+
[features]
32+
default = []
33+
simd-json = [
34+
"dep:simd-json",
35+
"dep:axum-core",
36+
"dep:mime",
37+
"dep:bytes",
38+
"dep:serde_path_to_error",
39+
]
40+
3141
[dependencies]
32-
axum = { version = "0.6.16", default-features = false, features = ["json", "query", "http1", "tokio"] }
33-
deadpool = { version = "0.10.0", features = ["rt_tokio_1", "serde", "async-trait", "managed" ] }
34-
deadpool-postgres = "0.12.1"
42+
axum = { version = "0.7.5", default-features = false, features = [
43+
"json",
44+
"query",
45+
"http1",
46+
"tokio",
47+
] }
48+
deadpool = { version = "0.12.1", features = ["rt_tokio_1", "serde", "managed"] }
49+
deadpool-postgres = { version = "0.14.0", features = ["rt_tokio_1", "serde"] }
3550
dotenv = "0.15.0"
36-
futures = "0.3.25"
37-
futures-util = "0.3.25"
38-
hyper = { version = "0.14.23", features = ["http1", "server"] }
39-
mongodb = { version = "2.3.1", features = ["zstd-compression", "snappy-compression", "zlib-compression"] }
40-
num_cpus = "1.14.0"
51+
futures = "0.3.30"
52+
futures-util = "0.3.30"
53+
mongodb = { version = "2.8.0", features = [
54+
"zstd-compression",
55+
"snappy-compression",
56+
"zlib-compression",
57+
] }
58+
num_cpus = "1.16.0"
4159
rand = { version = "0.8.5", features = ["small_rng"] }
42-
serde = { version = "1.0.149", features = ["derive"] }
43-
serde_json = "1.0.89"
44-
sqlx = { version = "0.7.3", features = ["postgres", "macros", "runtime-tokio-native-tls"] }
45-
tokio = { version = "1.24.2", features = ["full"] }
46-
tokio-pg-mapper = "0.2.0"
47-
tokio-pg-mapper-derive = "0.2.0"
48-
tokio-postgres = "0.7.7"
49-
tower = { version = "0.4.13", features = ["util"] }
50-
tower-http = { version = "0.4.0", features = ["set-header"] }
60+
serde = { version = "1.0.196", features = ["derive"] }
61+
serde_json = "1.0.127"
62+
sqlx = { version = "0.7.3", features = [
63+
"postgres",
64+
"macros",
65+
"runtime-tokio",
66+
"tls-rustls",
67+
] }
68+
tokio = { version = "1.39.3", features = ["full"] }
69+
tokio-pg-mapper = { version = "0.2.0" }
70+
tokio-pg-mapper-derive = { version = "0.2.0" }
71+
tokio-postgres = { version = "0.7.11" }
72+
tower = { version = "0.5.0", features = ["util"] }
73+
tower-http = { version = "0.5.2", features = ["set-header"] }
5174
yarte = "0.15.7"
75+
simd-json = { version = "0.13.8", optional = true }
76+
axum-core = { version = "0.4.3", optional = true }
77+
mime = { version = "0.3.17", optional = true }
78+
bytes = { version = "1.5.0", optional = true }
79+
serde_path_to_error = { version = "0.1.15", optional = true }
80+
moka = { version = "0.12.8", features = ["future"] }
81+
socket2 = "0.5.7"
82+
hyper = { version = "1.4", features = ["server", "http1"] }
83+
hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] }
84+
5285

5386
[profile.release]
54-
lto = true
87+
lto = "fat"
5588
codegen-units = 1
89+
strip = true
90+
opt-level = 3

frameworks/Rust/axum/README.md

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
2-
# [Axum](https://github.com/tokio-rs/axum) - Ergonomic and modular web framework built with Tokio, Tower, and Hyper
1+
# [Axum](https://github.com/tokio-rs/axum)
32

43
## Description
54

6-
Axum is a web application framework that focuses on ergonomics and modularity.
7-
8-
* [User Guide](https://docs.rs/axum/0.3/axum/)
9-
* [API Documentation](https://docs.rs/axum/0.3/axum/)
10-
* Cargo package: [axum](https://crates.io/crates/axum)
5+
Axum is a web application framework that focuses on ergonomics and modularity,
6+
built with Tokio, Tower, and Hyper.
117

12-
## Database
8+
- [User Guide](https://docs.rs/axum/latest/axum/)
9+
- [API Documentation](https://docs.rs/axum/latest/axum/)
10+
- [Cargo Package (`axum`)](https://crates.io/crates/axum)
1311

14-
PostgreSQL
12+
## Variants
1513

16-
* Raw using [sqlx](https://github.com/launchbadge/sqlx)
14+
- PostgreSQL using `SQLx`, `tokio_postgres`, and `deadpool`.
15+
- MongoDB with `mongodb`.
1716

1817
## Test URLs
1918

20-
### Test 1: JSON Encoding
21-
22-
http://localhost:8000/json
23-
24-
### Test 2: Single Row Query
25-
26-
http://localhost:8000/db
27-
28-
### Test 3: Multi Row Query
29-
30-
http://localhost:8000/queries?q=20
31-
32-
### Test 4: Fortunes (Template rendering)
33-
34-
http://localhost:8000/fortunes
35-
36-
### Test 5: Update Query
37-
38-
http://localhost:8000/updates?q=20
39-
40-
### Test 6: Plaintext
41-
42-
http://localhost:8000/plaintext
19+
- Plaintext: http://localhost:8000/plaintext
20+
- JSON Encoding: http://localhost:8000/json
21+
- Single Row Query: http://localhost:8000/db
22+
- Multi Row Query: http://localhost:8000/queries?q=20
23+
- Fortunes: http://localhost:8000/fortunes
24+
- Update Query: http://localhost:8000/updates?q=20
25+
- Cached Query: http://localhost:8000/cached-queries?q=20
26+
27+
## Notable Points (both performance and build)
28+
29+
- Use of `async`.
30+
- Use of most recent versions of Rust, `axum` and dependencies.
31+
- (Disabled by default) Compile-time swap-in of `simd-json` instead of `serde_json` for faster JSON serialization.
32+
- Release binaries are stripped and compiled with CPU native.
33+
- Sockets configured with TCP_NODELAY and to support an increased number of pending connections.
34+
- Server configured to serve HTTP/1 only, with no need for websockets.
35+
- Separation of build and deployment containers using multi-stage builds.
36+
- Deployment into Google's minimal `distroless-cc` container.
37+
- Use of pipelined database queries (where supported).
38+
- Streaming database queries (where supported).
39+
- Use of PostgreSQL prepared statements cache (where supported).
40+
- Use of PostgreSQL arrays to execute multi-row database updates with a single `UPDATE` query.
41+
- This is permitted by the [test requirements](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview#database-updates), step (ix).
42+
- In version 0.7.6 (as yet unreleased), a native API to set TCP_NODELAY will be included.
43+
- https://github.com/tokio-rs/axum/pull/2653/
44+
- https://github.com/tokio-rs/axum/issues/2521
45+
- More performance improvements are to be expected in version 0.8:
46+
- https://github.com/tokio-rs/axum/issues/1827

frameworks/Rust/axum/axum-mongo-raw.dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

frameworks/Rust/axum/axum-mongo.dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

frameworks/Rust/axum/axum-pg-pool.dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

frameworks/Rust/axum/axum-pg.dockerfile

Lines changed: 0 additions & 23 deletions
This file was deleted.

frameworks/Rust/axum/axum-sqlx.dockerfile

Lines changed: 0 additions & 26 deletions
This file was deleted.

frameworks/Rust/axum/axum.dockerfile

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
FROM rust:1.75-slim-buster
1+
FROM docker.io/rust:1.80-slim-bookworm AS builder
22

33
RUN apt-get update && apt-get install -y --no-install-recommends \
44
pkg-config libssl-dev \
55
&& rm -rf /var/lib/apt/lists/*
66

7-
WORKDIR /axum
8-
COPY ./src ./src
9-
COPY ./templates ./templates
10-
COPY ./Cargo.toml ./Cargo.toml
11-
COPY ./Cargo.lock ./Cargo.lock
12-
COPY ./run.sh ./run.sh
13-
RUN chmod +x ./run.sh
14-
7+
WORKDIR /build
8+
COPY ./Cargo.toml ./Cargo.lock /build/
9+
RUN cargo fetch
10+
COPY ./templates/ /build/templates
11+
COPY ./src/ /build/src
1512
ENV RUSTFLAGS "-C target-cpu=native"
1613
RUN cargo build --release
17-
RUN cp ./target/release/axum ./target/release/axum-techempower
1814

15+
FROM gcr.io/distroless/cc-debian12
16+
ENV POSTGRES_URL=postgres://benchmarkdbuser:benchmarkdbpass@tfb-database/hello_world
17+
ENV POSTGRES_MIN_POOL_SIZE=56
18+
ENV POSTGRES_MAX_POOL_SIZE=56
19+
ENV MONGODB_URL=mongodb://tfb-database:27017
20+
ENV MONGODB_MIN_POOL_SIZE=28
21+
ENV MONGODB_MAX_POOL_SIZE=14
22+
COPY --from=builder /build/target/release/axum* /app/
1923
EXPOSE 8000
20-
21-
CMD ["./run.sh"]
24+
CMD ["/app/axum"]

frameworks/Rust/axum/benchmark_config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"tests": [
44
{
55
"default": {
6+
"dockerfile": "axum.dockerfile",
7+
"docker_cmd": "/app/axum",
68
"json_url": "/json",
79
"plaintext_url": "/plaintext",
810
"port": 8000,
@@ -22,8 +24,11 @@
2224
"versus": "None"
2325
},
2426
"sqlx": {
27+
"dockerfile": "axum.dockerfile",
28+
"docker_cmd": "/app/axum-sqlx",
2529
"db_url": "/db",
2630
"fortune_url": "/fortunes",
31+
"cached_query_url": "/cached-queries?queries=",
2732
"port": 8000,
2833
"approach": "Realistic",
2934
"classification": "Fullstack",
@@ -41,6 +46,8 @@
4146
"versus": "None"
4247
},
4348
"pg": {
49+
"dockerfile": "axum.dockerfile",
50+
"docker_cmd": "/app/axum-pg",
4451
"db_url": "/db",
4552
"fortune_url": "/fortunes",
4653
"query_url": "/queries?queries=",
@@ -62,6 +69,8 @@
6269
"versus": "None"
6370
},
6471
"pg-pool": {
72+
"dockerfile": "axum.dockerfile",
73+
"docker_cmd": "/app/axum-pg-pool",
6574
"db_url": "/db",
6675
"query_url": "/queries?queries=",
6776
"update_url": "/updates?queries=",
@@ -83,6 +92,8 @@
8392
"versus": "None"
8493
},
8594
"mongo": {
95+
"dockerfile": "axum.dockerfile",
96+
"docker_cmd": "/app/axum-mongo",
8697
"db_url": "/db",
8798
"query_url": "/queries?queries=",
8899
"fortune_url": "/fortunes",
@@ -104,6 +115,8 @@
104115
"versus": "None"
105116
},
106117
"mongo-raw": {
118+
"dockerfile": "axum.dockerfile",
119+
"docker_cmd": "/app/axum-mongo-raw",
107120
"db_url": "/db",
108121
"query_url": "/queries?queries=",
109122
"update_url": "/updates?queries=",

0 commit comments

Comments
 (0)