r/programming • • 1d ago

Java Virtual Threads vs Elixir: Comparing Memory, CPU, Process Termination

https://www.youtube.com/watch?v=Z_8kVlVCC10
3 Upvotes

4 comments sorted by

6

u/simon_o 1d ago edited 3h ago
  1. The video basically comes down to Java not swapping out a virtual thread from it's underlying carrier thread when it executes a pure, endless loop.

While this is not relevant in practice, I'd prefer if the JVM would change this behavior¹, simply because being able to break Java virtual threads in 10 lines of trivial code is not a useful feature in my book.

2. I don't think bringing up the Netflix problem adds useful context. They hit a documented limitation in the implementation of virtual threads in older versions of the JVM. The server load was not the root cause.

3. Shared memory vs. (partial) heap isolation is a good point mentioned as a trade-off in the video.


¹ Might not even be that expensive, if the loop back-edge already has a GC safe point?

1

u/vips7L 16h ago

WRT your foot note you mean a GC pause? AFAIK that would depend on the GC chosen. Java is moving towards concurrent GCs that do their work in the background, like ZGC which is effectively pauseless. 

1

u/simon_o 4h ago

The runtime already adds points to the code being executed where a check is being made whether execution should be suspended, in that case for garbage collection.

If that endless loop already had that safe point added, it would be trivial and cheap to prevent such virtual threads from rendering the thread pool –on which such virtual threads are executed– from being made inoperable.

If the endless loop lacks that safe point, adding such a safe point would add some overhead that does not exist currently.

2

u/Mediocre_Elephant_73 1d ago

Elixir spoiled me