News for hackers. Stuff that matters.
Re:Java Virtual Threads: A Case Study by immibis on Wednesday July 17, 2024 @05:22AM (#40983916)
Why can't virtual threads overcommit CPU use? If I have 4 CPUs and 4000 virtual threads running CPU-bound code, is that not overcommit? A system without overcommit would refuse to create the 5th thread.
Re:Java Virtual Threads: A Case Study by detinho on Wednesday July 17, 2024 @10:44AM (#40986471)
I think parent is saying overcommit with OS threads. 4k requests = 4k OS threads. That would lead to the problems parent is talking about.
Re:Java Virtual Threads: A Case Study by immibis on Wednesday July 17, 2024 @02:24PM (#40988805)
Why wouldn't 4k virtual threads lead to the same problems?
Re:Java Virtual Threads: A Case Study by troupo on Wednesday July 17, 2024 @04:36PM (#40990092)
Because they don't create 4k real threads, and can be scheduled on n=CPU Cores OS threads
Re:Java Virtual Threads: A Case Study by immibis on Thursday July 18, 2024 @10:25AM (#40995855)
4k "real" threads can also be scheduled on 4 CPU cores. What's the difference?
Re:Java Virtual Threads: A Case Study by troupo on Thursday July 18, 2024 @11:33AM (#40996569)
Real threads are extremely expensive both in terms of memory and CPU time compared to virtual threads. I think the main issue is not even that but context switching when switching threads which is also very expensive.

Virtual threads usually require significantly fewer resources to spawn and run. And, if the underlying system is implemented with them in mind, they can use fewer context switches, and possibly even fewer cache misses etc.