top | item 40983933

(no title)

frevib | 1 year ago

They indeed optimize thread context switching. Taking the thread on and off the CPU is becoming expensive when there are thousands of threads.

You are right that everything blocks, even when going to L1 cache you have to wait 1 nanoseconds. But blocking in this context means waiting for “real” IO like a network request or spinning disk access. Virtual threads take away the problem that the thread sits there doing nothing for a while as it is waiting for data, before it is context switched.

Virtual threads won’t improve CPU-bound blocking. There the thread is actually occupying the CPU, so there is no problem of the thread doing nothing as with IO-bound blocking.

discuss

order

No comments yet.