Query about heap memory consumption of Virtual Thread

Ron Pressler ron.pressler at oracle.com
Thu Aug 25 15:54:36 UTC 2022


Hi.

The stack representation for virtual threads is currently not as compact as we’d like it to be, and we’re now working on reducing it, possibly drastically. So yes, it is possible that the application will require more heap space, but whether that’s the case, or by how much is very much application-dependent, so you’ll need to track the heap usage and allocate heap space appropriately.

Virtual threads are lightweight in the sense that they consume much less precious resources than platform threads, and that is why you can have many more of them than platform threads. The resource consumption by platform threads is much more constrained than for virtual threads, even in their current state. We expect the heap consumption to be reduced in a future version.

— Ron

On 25 Aug 2022, at 03:31, Anindya Bandopadhyay <anindyabandopadhyay at gmail.com<mailto:anindyabandopadhyay at gmail.com>> wrote:

Hi,
I am just curious about the heap memory consumption of Virtual Threads.

<image.png>
Code Link Here<https://gist.githubusercontent.com/andysundar/6401e20fee5674ae47fd94778d37f752/raw/c95905c45cbae47cbb66c3fe46e48f13dcaf19a9/VirtualThreadScaleExample.java>

In the above code I am switching the thread factory in line number 10. I was just trying to analyze performance statistics and what I discovered is that virtual thread consumes a significant amount of heap memory (may be due to the continuation objects put into heap memory) with respect to platform thread.


  1.  Do we need to increase the size of heap memory if we are using virtual thread?
  2.  What do you mean by "virtual threads are lightweight" ?

<image.png>

Will be eagerly waiting for your reply.

Regards;
Anindya Bandopadhyay
[https://ci3.googleusercontent.com/mail-sig/AIorK4wc7vkRjiByaujRe_sUyynf3O1RAXCYCZ_SVWU_iA6uy5G3XlVt5h7gI-RWITqVnl9eiHFMQgY]<http://www.linkedin.com/in/anindyabandopadhyay>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20220825/e18666ad/attachment.htm>


More information about the loom-dev mailing list