<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<br class="">
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On 11 Jul 2022, at 22:13, Rob Bygrave <<a href="mailto:robin.bygrave@gmail.com" class="">robin.bygrave@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class=""></div>
<div class=""><i class="">> An existing application that migrates to using virtual threads doesn’t replace its platform threads with virtual threads</i></div>
<div class=""><br class="">
</div>
<div class="">What I have been confident about to date based on the testing I've done is that we can use Jetty with a Loom based thread pool and that has worked very well. That is replacing current platform threads with virtual threads. I'm suggesting this
will frequently be sub 1000 virtual threads. Ron, are you suggesting this isn't a valid use of virtual threads or am I reading too much into what you've said here?<br class="">
</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">The throughput advantage to virtual threads comes from one aspect — their *number* — as explained by Little’s law. A web server employing virtual thread would not replace a pool of N platform threads with a pool of N virtual threads, as that does
not increase the number of threads required to increase throughput. Rather, it replaces the pool of N virtual threads with an unpooled ExecutorService that spawns at least one new virtual thread for every HTTP serving task. Only that can increase the number
of threads sufficiently to improve throughput.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div dir="ltr" class="">
<div dir="ltr" class="">
<div class=""><br class="">
</div>
</div>
<div dir="ltr" class=""><br class="">
</div>
<div dir="ltr" class="">> <i class=""><b class="">unusual</b></i> for an application that has any virtual threads to have fewer than, say, 10,000</div>
<div class=""><br class="">
</div>
<div class="">In the case of http server use of virtual thread, I feel the use of
<i class=""><b class="">unusual</b></i> is too strong. That is, when we are using virtual threads for application code handling of http request/response (like Jetty + Loom), I suspect this is frequently going to operate with less than 1000 concurrent requests
per server instance. <br class="">
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">1000 concurrent requests would likely translate to more than 10,000 virtual threads due to fanout (JEPs 425 and 428 cover this). In fact, even without fanout, every HTTP request might wish to spawn more than one thread, for example to have one
thread for reading and one for writing. The number 10,000, however, is just illustrative. Clearly, an application with virtual threads will have some large number of threads (significantly larger than applications with just platform threads), because the ability
to have a large number of threads is what virtual threads are for.</div>
</div>
<div class=""><br class="">
</div>
<div class="">The important point is that tooling needs to adapt to a high number of threads, which is why we’ve added a tool that’s designed to make sense of many threads, where jstack might not be very useful.</div>
<div class=""><br class="">
</div>
<div class="">— Ron</div>
<br class="">
</div>
</body>
</html>