<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="">
Little’s law tells us what the relationship between concurrency, throughput and latency is if the system is stable. It tells us that if latency doesn’t decrease, then concurrency rises with throughput (again, if the system is stable). Therefore, to support
 high throughput you need a high level of concurrency. Since the Java platform’s unit of concurrency is the thread, to support high throughput you need a high number of threads. There might be other things you also need more of, but you *at least* need a high
 number of threads.
<div class=""><br class="">
</div>
<div class="">The number of threads is an *upper bound* on concurrency, because the platform cannot make concurrent progress on anything without a thread (with the caveat in the next paragraph). There might be other upper bounds, too (e.g. you need enough memory
 to concurrently store all the working data for your concurrent operations), but the number of threads *is* an upper bound, and the one virtual threads are there to remove.<br class="">
<div class=""><br class="">
</div>
<div class="">Of course, as JEP 425 explains, you could abandon threads altogether and use some other construct as your unit of concurrency, but then you lose platform support. </div>
<div class=""><br class="">
</div>
<div class="">In any event, virtual threads exist to support a high number of threads, as Little’s law requires, therefore, if you use virtual threads, you have a high number of them.</div>
<div class=""><br class="">
</div>
<div class="">— Ron<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 14 Jul 2022, at 08:12, Alex Otenko <<a href="mailto:oleksandr.otenko@gmail.com" class="">oleksandr.otenko@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="auto" class="">Hi Ron,
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">It looks you are unconvinced. Let me try with illustrative numbers.</div>
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">The users opening their laptops at 9am don't know how many threads you have. So throughput remains 100k ops/sec in both setups below. Suppose, in the first setup we have a system that is stable with 1000 threads. Little's law tells
 us that the response time cannot exceed 10ms in this case. Little's law does not prescribe response time, by the way; it is merely a consequence of the statement that the system is stable: it couldn't have been stable if its response time were higher.</div>
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">Now, let's create one thread per request. One claim is that this increases concurrency (and I object to this point alone). Suppose this means concurrency becomes 100k. Little's law says that the response time must be 1 second. Sorry,
 but that's hardly an improvement! In fact, for any concurrency greater than 1000 you must get response time higher than 10ms we've got with 1000 threads. This is not what we want. Fortunately, this is not what happens either.</div>
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">Really, thread count in the thread per request design has little to do with concurrency level. Concurrency level is a derived quantity. It only tells us how many requests are making progress at any given time in a system that experiences
 request arrival rate R and which is able to process them in time T. The only thing you can control through system design is response time T.</div>
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">There are good reasons to design a system that way, but Little's law is not one of them.</div>
</div>
<br class="">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 13 Jul 2022, 14:29 Ron Pressler, <<a href="mailto:ron.pressler@oracle.com" class="">ron.pressler@oracle.com</a>> wrote:<br class="">
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;line-break:after-white-space" class="">
<div class="">The application of Little’s law is 100% correct. Little’s law tells us that the number of threads must *necessarily* rise if throughput is to be high. Whether or not that alone is *sufficient* might depend on the concurrency level of other resources
 as well. The number of threads is not the only quantity that limits the L in the formula, but L cannot be higher than the number of threads. Obviously, if the system’s level of concurrency is bounded at a very low level — say, 10 — then having more than 10
 threads is unhelpful, but as we’re talking about a program that uses virtual threads, we know that is not the case.</div>
<div class=""><br class="">
</div>
<div class="">Also, Little’s law describes *stable* systems; i.e. it says that *if* the system is stable, then a certain relationship must hold. While it is true that the rate of arrival might rise without bound, if the number of threads is insufficient to
 meet it, then the system is no longer stable (normally that means that queues are growing without bound).<br class="">
<div class="">
<div class="">
<div class=""><br class="">
</div>
<div class="">— Ron</div>
<div class=""><br class="">
<blockquote type="cite" class="">
<div class="">On 13 Jul 2022, at 14:00, Alex Otenko <<a href="mailto:oleksandr.otenko@gmail.com" target="_blank" rel="noreferrer" class="">oleksandr.otenko@gmail.com</a>> wrote:</div>
<br class="">
<div class="">
<div dir="auto" class="">This is an incorrect application of Little's Law. The law only posits that there is a connection between quantities. It doesn't specify which variables depend on which. In particular, throughput is not a free variable.
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">Throughput is something outside your control. 100k users open their laptops at 9am and login within 1 second - that's it, you have throughput of 100k ops/sec.</div>
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">Then based on response time the system is able to deliver, you can tell what concurrency makes sense here. Adding threads is not going to change anything - certainly not if threads are not the bottleneck resource. Threads become the
 bottleneck when you have hardware to run them, but not the threads.</div>
</div>
<br class="">
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, 12 Jul 2022, 15:47 Ron Pressler, <<a href="mailto:ron.pressler@oracle.com" target="_blank" rel="noreferrer" class="">ron.pressler@oracle.com</a>> wrote:<br class="">
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;line-break:after-white-space" class="">
<div style="word-wrap:break-word;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" rel="noreferrer noreferrer" target="_blank" class="">robin.bygrave@gmail.com</a>> wrote:</div>
<br class="">
<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>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</body>
</html>