mirror of
https://github.com/NetworkCats/rustyip.git
synced 2026-11-13 16:17:46 +00:00
Cache the serialized /json fields per MMDB record. Every field except `ip` depends only on the record, and many IPs share one record, so the response is now the cached fields with the address prepended. The cache is keyed by data-section offset, capped at 16 MiB, and owned by the loaded database so a hot-swapped DB never serves stale entries. A hit costs ~0.27us instead of ~2.5us for decode + serialize; a miss is no slower than before thanks to a pre-sized serialization buffer. Trim per-request framework overhead shared by all endpoints: - Dispatch by Host with a plain HostRouter service instead of an outer Router wrapping a service_fn, skipping a second route match and box. - Apply security headers via tower's MapResponseLayer instead of middleware::from_fn, and reserve header capacity up front. - Add a RequestedIp extractor that reads headers in place instead of cloning the whole HeaderMap. On a 1 CPU / 1 GB Alpine (musl) container, /json throughput rose from 76.5k to 123.5k rps for a single IP (+61%) and from 84.9k to 130.5k rps across 20k random IPs (+54%); p50 latency fell from 0.85ms to 0.52ms. Responses are byte-identical to before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
881 B
TOML
38 lines
881 B
TOML
[package]
|
|
name = "rustyip"
|
|
version = "0.1.0"
|
|
edition = "2024"
|
|
|
|
[dependencies]
|
|
axum = "0.8.8"
|
|
tower = { version = "0.5", features = ["util"] }
|
|
tokio = { version = "1.49.0", features = ["rt-multi-thread", "macros", "net", "signal", "time", "fs", "io-util"] }
|
|
askama = "0.15.4"
|
|
maxminddb = "0.27.3"
|
|
serde = { version = "1", features = ["derive"] }
|
|
serde_json = "1"
|
|
arc-swap = "1"
|
|
reqwest = { version = "0.13", default-features = false, features = ["rustls"] }
|
|
tracing = "0.1"
|
|
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
|
dotenvy = "0.15"
|
|
urlencoding = "2"
|
|
tokio-util = "0.7"
|
|
static-files = "0.3.1"
|
|
quick_cache = "0.7"
|
|
|
|
[build-dependencies]
|
|
static-files = "0.3.1"
|
|
|
|
[dev-dependencies]
|
|
http-body-util = "0.1"
|
|
tower = { version = "0.5", features = ["util"] }
|
|
tempfile = "3"
|
|
|
|
[profile.release]
|
|
opt-level = 3
|
|
lto = true
|
|
codegen-units = 1
|
|
strip = true
|
|
panic = "abort"
|