TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Java Virtual Threads: A Case Study

167 点作者 mighty_plant11 个月前

9 条评论

pron10 个月前
Virtual threads do one thing: they allow creating lots of threads. This helps throughput due to Little&#x27;s law [1]. But because this server here saturates the CPU with only a few threads (it doesn&#x27;t do the fanout modern servers tend to do), this means that no significant improvements can be provided by virtual threads (or asynchronous programming, which operates on the same principle) <i>while keeping everything else in the system the same</i>, especially since everything else in that server was optimised for over two decades under the constraints of expensive threads (such as the deployment strategy to many small instances with little CPU).<p>So it looks like their goal was: try adopting a new technology without changing any of the aspects designed for an old technology and optimised around it.<p>[1]: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;07V08SB1l8c" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;07V08SB1l8c</a>
评论 #40991568 未加载
评论 #40990752 未加载
评论 #40988438 未加载
cayhorstmann10 个月前
I looked at the replication instructions at <a href="https:&#x2F;&#x2F;github.com&#x2F;blueperf&#x2F;demo-vt-issues&#x2F;tree&#x2F;main">https:&#x2F;&#x2F;github.com&#x2F;blueperf&#x2F;demo-vt-issues&#x2F;tree&#x2F;main</a>, which reference this project: <a href="https:&#x2F;&#x2F;github.com&#x2F;blueperf&#x2F;acmeair-authservice-java&#x2F;tree&#x2F;main">https:&#x2F;&#x2F;github.com&#x2F;blueperf&#x2F;acmeair-authservice-java&#x2F;tree&#x2F;ma...</a><p>What &quot;CPU-intensive apps&quot; did they test with? Surely not acmeair-authservice-java. A request does next to nothing. It authenticates a user and generates a token. I thought it at least connects to some auth provider, but if I understand it correctly, it just uses a test config with a single test user (<a href="https:&#x2F;&#x2F;openliberty.io&#x2F;docs&#x2F;latest&#x2F;reference&#x2F;config&#x2F;quickStartSecurity.html" rel="nofollow">https:&#x2F;&#x2F;openliberty.io&#x2F;docs&#x2F;latest&#x2F;reference&#x2F;config&#x2F;quickSta...</a>). Which would not be a blocking call.<p>If the request tasks don&#x27;t block, this is not an interesting benchmark. Using virtual threads for non-blocking tasks is not useful.<p>So, let&#x27;s hope that some of the tests were with tasks that block. The authors describe that a modest number of concurrent requests (&lt; 10K) didn&#x27;t show the increase in throughput that virtual threads promise. That&#x27;s not a lot of concurrent requests, but one would expect an improvement in throughput once the number of concurrent requests exceeds the pool size. Except that may be hard to see because OpenLiberty&#x27;s default is to keep spawning new threads (<a href="https:&#x2F;&#x2F;openliberty.io&#x2F;blog&#x2F;2019&#x2F;04&#x2F;03&#x2F;liberty-threadpool-autotuning.html" rel="nofollow">https:&#x2F;&#x2F;openliberty.io&#x2F;blog&#x2F;2019&#x2F;04&#x2F;03&#x2F;liberty-threadpool-au...</a>). I would imagine that in actual deployments with high concurrency, the pool size will be limited, to prevent the app from running out of memory.<p>If it never gets to the point where the number of concurrent requests significantly exceeds the pool size, this is not an interesting benchmark either.
pansa210 个月前
Are these Virtual Threads the feature that was previously known as “Project Loom”? Lightweight threads, more-or-less equivalent to Go’s goroutines?
评论 #40983332 未加载
评论 #40989370 未加载
评论 #40989787 未加载
评论 #40983323 未加载
exabrial10 个月前
What is the virtual thread &#x2F; event loop pattern seeking to optimize? Is it context switching?<p>A number of years ago I remember trying to have a sane discussion about “non blocking” and I remember saying “something” will block eventually no matter what… anything from the buffer being full on the NIC to your cpu being at anything less than 100%. Does it shake out to any real advantage?
评论 #40982768 未加载
评论 #40982625 未加载
评论 #40982970 未加载
评论 #40982586 未加载
评论 #40983884 未加载
评论 #40982931 未加载
评论 #40983933 未加载
评论 #40990756 未加载
评论 #40982854 未加载
bberrry10 个月前
I don&#x27;t understand these benchmarks at all. How could it possibly take virtual threads 40-50 seconds to reach maximum throughput when getting a number of tasks submitted at once?
LinXitoW10 个月前
From my very limited exposure to virtual threads and the older solution (thread pools), the biggest hurdle was the extensive use of ThreadLocals by most popular libraries.<p>In one project I had to basically turn a reactive framework into a one thread per request framework, because passing around the MDC (a kv map of extra logging information) was a horrible pain. Getting it to actually jump ship from thread to thread AND deleting it at the correct time was basically impossible.<p>Has that improved yet?
评论 #40989517 未加载
评论 #40984005 未加载
评论 #40983677 未加载
davidtos10 个月前
I did some similar testing a few days ago[1]. Comparing platform threads to virtual threads doing API calls. They mention the right conditions like having high task delays, but it also depends on what the task is. Threads.sleep(1) performs better on virtual threads than platform threads but a rest call taking a few ms performs worse.<p>[1] <a href="https:&#x2F;&#x2F;davidvlijmincx.com&#x2F;posts&#x2F;virtual-thread-performance-api-calls&#x2F;" rel="nofollow">https:&#x2F;&#x2F;davidvlijmincx.com&#x2F;posts&#x2F;virtual-thread-performance-...</a>
taspeotis10 个月前
My rough understanding is that this is similar to async&#x2F;await in .NET?<p>It’s a shame this article paints a neutral (or even negative) experience with virtual threads.<p>We rewrote a boring CRUD app that spent 99% of its time waiting the database to respond to be async&#x2F;await from top-to-bottom. CPU and memory usage went way down on the web server because so many requests could be handled by far fewer threads.
评论 #40983101 未加载
评论 #40983637 未加载
评论 #40983202 未加载
评论 #40983312 未加载
评论 #40983335 未加载
评论 #40984175 未加载
评论 #40983291 未加载
tzahifadida10 个月前
Similarly the power of golang concurrent programming is that you write non-blocking code as you write normal code. You don&#x27;t have to wrap it in functions and pollute the code but moreover, not every coder on the planet knows how to handle blocking code properly and that is the main advantage. Most programming languages can do anything the other languages can do. The problem is that not all coders can make use of it. This is why I see languages like golang as an advantage.
评论 #40983190 未加载
评论 #40982898 未加载
评论 #40986695 未加载