11
Dev.to Kotlin
作者:netfishx
發布:03-19 05:35
Same API in Java, Go, Rust, and Kotlin — a 4-language benchmark
Reimplementing the same backend API across Java, Go, Rust, and Kotlin shows Rust leading on throughput and memory, while Kotlin nearly matches Go thanks to JIT and virtual threads.
重點摘要
Rust achieved highest throughput (210K QPS) and smallest memory (≈33 MB at 500 concurrency)
Kotlin (Ktor + JVM 21 Virtual Threads) reached ~99K QPS, close to Go (100K), but had higher p99 latency and larger memory
Author chose Rust (Axum) for production to reduce infrastructure cost; offers recommendations for Go, Kotlin, Rust, and Java
After 21 years of Java development the author rebuilt a short-video platform backend with the same API in Java, Go, Rust, and Kotlin (Ktor) and benchmarked throughput, latency, memory, cold start, and build time. Rust showed the best overall resource efficiency and throughput (210K QPS) with minimal memory growth under load (~19 MB idle to 33 MB at 500 concurrent). Kotlin surprisingly matched Go’s throughput (~99K vs 100K) due to JIT and JVM virtual threads, but had higher p99 latency (~15 ms) and much larger RSS (~650 MB). Go delivered the fastest cold start (69 ms) and short build times; Rust’s cold start was 153 ms and clean builds took ~98 s. The author chose Rust (Axum) for production primarily to cut infrastructure costs (fewer instances), but recommends Go for fast team productivity, Kotlin for JVM modernization, and Java/Spring for entrenched enterprise ecosystems.
相同 API 在 Java、Go、Rust 与 Kotlin 的四語言基準測試
在四种语言上重写相同后端后,Rust 在吞吐与内存效率上表现最佳,Kotlin 在 JIT 与虚拟线程下吞吐接近 Go。
重點摘要
Rust 吞吐最高(210K QPS),500 并发下内存约 33 MB
Kotlin 吞吐接近 Go(99K vs 100K),但 p99 延迟与内存更高
作者为节省基础设施成本选用 Rust (Axum),并为不同场景给出语言建议
作者在 21 年 Java 经验后,将短视频平台后端以相同 API 重写为 Java、Go、Rust、Kotlin 并做基准测试:Rust 在吞吐(210K QPS)与内存使用上最优(空闲约 19 MB、500 并发约 33 MB),没有 GC 导致的内存波动;Kotlin 借助 JIT 与 JVM 虚拟线程吞吐几乎追上 Go(99K vs 100K),但 p99 延迟与 RSS(约 650 MB)偏高;Go 拥有最快冷启动(69 ms)与较短的构建时间;Rust 构建慢(干净构建约 98 s)但代码量最少。作者最终选用 Rust(Axum)以减少 EC2 成本,同时建议根据团队速度、现有 JVM 投资与性能需求在 Go、Kotlin、Rust、Java 之间取舍。
相同 API 的 Java、Go、Rust 與 Kotlin 比 benchmark
在四種語言上重寫相同後端後,Rust 在吞吐量與記憶體效率上領先,Kotlin 在 JIT 與虛擬執行緒下接近 Go 的吞吐量。
重點摘要
Rust 吞吐最高(210K QPS),500 連線時記憶體近 33 MB
Kotlin 吞吐接近 Go(99K vs 100K),但 p99 延遲與記憶體較高
作者以 Rust (Axum) 上線以降低基礎設施成本,並針對不同需求提出選擇建議
作者在 21 年 Java 經驗後,將短影片平台後端以相同 API 重寫為 Java、Go、Rust、Kotlin 並對比效能:Rust 在吞吐量(210K QPS)與記憶體使用上表現最佳(idle 約 19 MB、500 連線約 33 MB),且 p99 延遲較低;Kotlin(Ktor + JVM21 虛擬執行緒)靠 JIT 幾乎追上 Go 的吞吐,但 p99 延遲與 RSS(約 650 MB)較高;Go 有最快冷啟動(69 ms)與短建置時間;Java 與 Kotlin 在 JVM 生態與建置支援上仍有痛點。最終作者選擇 Rust(Axum)作為生產環境以降低 EC2 成本,但針對團隊速度、JVM 投資與效能關鍵服務,分別推薦 Go、Kotlin、Rust。