<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Aptos;}
@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:12.0pt;
font-family:"Aptos",sans-serif;
mso-ligatures:standardcontextual;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#96607D;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="en-SE" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hey,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I believe I have found a bug with JDK 25 and virtual threads, but will need some guidance in what information I need to provide in order to file a bug.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Short version: after changing from JDK 21 to JDK 25, doing Thread.sleep(1) in a virtual thread now sometimes takes up to 60 seconds (!).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Long version:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I recently updated an application from Java 21 to 25 and started seeing a very negative performance impact.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The application in question runs ca 20 long running virtual threads which basically does the following:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">while (true) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> doTrivialWork();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Thread.sleep(1);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> semaphore.acquire();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I.e. do trivial work, sleep 1 ms, wait on a semaphore to be <span lang="en-SE">
woken</span> by another thread, and then <span lang="en-SE">loop</span> again. After long investigation I finally realized that it was the Thread.sleep that sometimes took significantly longer with Java 25 than Java 21.<o:p></o:p></p>
<p class="MsoNormal">So I timed it, basically just this:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">while (true) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> doTrivialWork();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> var start = System.nanoTime();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> Thread.sleep(1);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> var end = System.nanoTime();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> System.out.println("delay=" + (end - start));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""> semaphore.acquire();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">And let it run >1 million times.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">With JDK 21 and either virtual threads or platform threads, or with latest JDK 25 and platform threads, it works fine and the Thread.sleep(1) finishes according to the following:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">99,5% finish within 2 ms<o:p></o:p></p>
<p class="MsoNormal">0,4% finish within 4 ms<o:p></o:p></p>
<p class="MsoNormal">Worst case 80 ms<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But with latest JDK 25 and virtual threads, it’s significantly worse:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">98,0% finish within 2 ms<o:p></o:p></p>
<p class="MsoNormal">0,3% finish within 4 ms<o:p></o:p></p>
<p class="MsoNormal">0,5% taking over 1000 ms<o:p></o:p></p>
<p class="MsoNormal">A few hundred occurrences over 60 seconds (!)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The only change between these runs is JDK version and platform vs virtual threads.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Increasing <span lang="en-SE">jdk.virtualThreadScheduler.parallelism</span> and
<span lang="en-SE">jdk.virtualThreadScheduler.timerQueues</span><span lang="en-SE">
</span>makes no difference.<o:p></o:p></p>
<p class="MsoNormal">There are no jdk.VirtualThreadPinned or jdk.VirtualThreadSubmitFailed events in JFR.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Additional information:<o:p></o:p></p>
<p class="MsoNormal">The application is running in a pod on k8s with 1 CPU allocated to it.<o:p></o:p></p>
<p class="MsoNormal">No additional arguments for the JDK.<o:p></o:p></p>
<p class="MsoNormal">CPU utilization is less than 15%.<o:p></o:p></p>
<p class="MsoNormal">GC happens very infrequently (many minutes apart).<o:p></o:p></p>
<p class="MsoNormal"><span lang="en-SE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-ligatures:none"> <o:p></o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse">
<tbody>
<tr style="height:217.75pt">
<td width="74" valign="top" style="width:55.65pt;padding:2.4pt 3.75pt 2.4pt 2.4pt;height:217.75pt">
<p class="MsoNormal"><span lang="en-SE"><a href="http://volvocars.com/"><span lang="en-SE" style="font-family:"Calibri",sans-serif;color:blue"><img border="0" width="66" height="66" style="width:.6875in;height:.6875in" id="Picture_x0020_1" src="cid:image001.gif@01DC5B03.00804CB0" alt="VOLVO CAR CORPORATION"></span></a></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-ligatures:none"><o:p></o:p></span></p>
</td>
<td width="187" valign="top" style="width:140.3pt;padding:2.4pt 2.4pt 2.4pt 12.75pt;height:217.75pt">
<p class="MsoNormal" style="margin-bottom:10.0pt"><span style="font-size:14.0pt;font-family:"Calibri",sans-serif;color:black;mso-ligatures:none">Christian<br>
Fredriksson</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-ligatures:none"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Calibri",sans-serif;color:black;mso-ligatures:none"><br>
T +46 734 63 71 06<br>
<u><a href="mailto:christian.fredriksson.2@volvocars.com"><span style="color:black">christian.fredriksson.2@volvocars.com</span></a></u><br>
<br>
VOLVO CAR CORPORATION<br>
Connected Car Cloud<br>
<u><a href="volvocars.com"><span style="color:black">volvocars.com</span></a></u></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-ligatures:none"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:10.0pt"><span style="font-size:8.0pt;font-family:"Calibri",sans-serif;color:#7F7F7F;mso-ligatures:none">Registered Office Göteborg, Sweden<br>
Registration No. 556074-3089</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;mso-ligatures:none"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-family:"Times New Roman",serif;mso-ligatures:none"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Times New Roman",serif;mso-ligatures:none"> </span><span lang="en-SE"><o:p></o:p></span></p>
</div>
</body>
</html>