Java Virtual Threads Performance Benchmark: Platform vs Virtual Threads

🚀 Exploring Java Virtual Threads (Project Loom) — A Simple Benchmark Recently, I wanted to see (not just read about) the impact of virtual threads in Java. So I built a small Spring Boot application and ran a quick benchmark using Apache Bench (ab). 🧪 Test Setup: Endpoint simulating blocking work (Thread.sleep(1000)) 100 requests with concurrency = 20 Compared: 🔹 Platform Threads (traditional thread pool) 🔹 Virtual Threads (Executors.newVirtualThreadPerTaskExecutor()) 📊 Results: 👉 Platform Threads: Total Time: ~21.2 sec Throughput: ~4.7 req/sec Avg Latency: ~4.2 sec 👉 Virtual Threads: Total Time: ~6.1 sec Throughput: ~16.3 req/sec 🚀 Avg Latency: ~1.2 sec ⚡ 💡 What I Observed: Virtual threads handled requests almost concurrently Latency dropped close to the actual task time (~1 second) Platform threads became a bottleneck due to limited thread pool 🧠 Key Takeaway: Virtual threads don’t make your code faster — they make blocking scalable. They are especially powerful for: ✔️ I/O-heavy applications (DB calls, REST APIs) ✔️ High-concurrency systems ✔️ Simplifying reactive-style code without complexity ⚠️ Not a silver bullet: No major benefit for CPU-bound tasks Really interesting to see how Java is evolving to handle concurrency in a much simpler and scalable way. Have you tried virtual threads in your applications yet? 🤔 🔗 GitHub Repo: https://lnkd.in/gFzpnkp6 Feel free to explore and try it out! #Java #SpringBoot #VirtualThreads #ProjectLoom #BackendDevelopment #Performance #Concurrency

  • text

nice benchmark with actual numbers, those results line up with what we saw after switching our I/O heavy services to virtual threads. one thing worth noting though - if you're using synchronized blocks anywhere in the hot path, virtual threads will pin to carrier threads and you lose most of the benefit. we had to swap a few synchronized sections with ReentrantLock before the throughput gains actually showed up. also curious if you tested with higher concurrency like 200+ requests, thats where the difference gets really dramatic since platform threads hit the pool ceiling hard

To view or add a comment, sign in

Explore content categories