News for hackers. Stuff that matters.
Re:Java Virtual Threads: A Case Study by chipdart on Wednesday July 17, 2024 @02:21AM (#40983092)
> So... What is it seeking to optimize?

The goal is to maximize the number of tasks you can run concurrently, while imposing on the developers a low cognitive load to write and maintain the code.

> Why did you need a thread pool before but not any more?

You still need a thread pool. Except with virtual threads you are no longer bound to run a single task per thread. This is specially desirable when workloads are IO-bound and will expectedly idle while waiting for external events. If you have a never-ending queue of tasks waiting to run, why should you block a thread consuming that task queue by running a task that stays idle while waiting for something to happen? You're better off starting the task and setting it aside the moment it awaits for something to happen.

> What resource was exhausted to prevent you from putting every request on a thread?

Re:Java Virtual Threads: A Case Study by riku_iki on Wednesday July 17, 2024 @11:13PM (#40992167)
> why should you block a thread

if creating gazillion threads on modern hardware is super cheap why not? I have transparency and debuggability what threads are running, can check stacktrace of each and what are they blocked on.

virtual threads adds lots of magic under the hood, and if there will be some bug or lib in your infra with no vthreads support it is absolutely not clear how to debug it.

Re:Java Virtual Threads: A Case Study by stoperaticless on Thursday July 18, 2024 @03:48AM (#40993423)
Each thread adds overhead.

Some usage types don’t care, some do.

From what I gather virtual threads are an alternative to “callback-hell” (js) or async coloring (python).

Re:Java Virtual Threads: A Case Study by riku_iki on Thursday July 18, 2024 @10:57AM (#40996168)
> Some usage types don’t care, some do.

I suspect if you care about threads overhead, you won't pick Java, because there will be overhead in other areas too

> From what I gather virtual threads are an alternative to “callback-hell” (js) or async coloring (python).

there is also existing ExecutorService and futures in Java

Re:Java Virtual Threads: A Case Study by stoperaticless on Friday July 19, 2024 @12:38AM (#41002038)
> there is also existing ExecutorService and futures in Java

Yes, virtual threads are an alternative also to those. (Kind of)

Re:Java Virtual Threads: A Case Study by riku_iki on Friday July 19, 2024 @01:30AM (#41002209)
And my frustration is that java had that API for 20 years, it is used everywhere and absolutely battle tested, and now they are adding those virtual threads which break third party libs and make JVM more complicated with various degradations in exchange of benefits most will not notice..
Re:Java Virtual Threads: A Case Study by chipdart on Thursday July 18, 2024 @09:25AM (#40995354)
> if creating gazillion threads on modern hardware is super cheap why not?

Virtual threads are a performance improvement over threads, no matter how cheap to create threads are. Virtual threads run on threads. If threads become cheaper to create, so do virtual threads. They are not mutually exclusive.

Virtual threads are on top of that a developer experience improvement. Code is easier to write and maintain.

Virtual threads improve throughput because the moment a task is waiting for anything like IO, the thread is able to service any other task in the queue.

Re:Java Virtual Threads: A Case Study by riku_iki on Thursday July 18, 2024 @10:59AM (#40996198)
> Virtual threads are on top of that a developer experience improvement. Code is easier to write and maintain.

except now you need to prove somehow that all 100 libs in your project support virtual threads.

> Virtual threads improve throughput because the moment a task is waiting for anything like IO, the thread is able to service any other task in the queue.

from reading similar discussions, linux for example doesn't have true IO async API, you just push lock of Java thread to lock of thread in the kernel

Re:Java Virtual Threads: A Case Study by Fulgen on Thursday July 18, 2024 @05:43PM (#41000056)
> linux for example doesn't have true IO async API

io_uring has been around for a few years at this point, with vulnerabilities having been fixed to the point that it's fit for broadband usage.

Re:Java Virtual Threads: A Case Study by riku_iki on Thursday July 18, 2024 @05:46PM (#41000073)
In this discussion people claim io_uring is not real async IO, but just another kernel level threadpool: https://news.ycombinator.com/item?id=38919659