“重线程环境”的定义是什么?

发布于 2024-10-09 19:54:56 字数 132 浏览 4 评论 0原文

我在一段代码上使用。尽管临界区很小,但许多线程会到达那里(大约每秒 100 个线程)。在一些文章中,我看到此方法不适合繁重的线程环境

我的问题是我们称之为重线程环境的速率是多少?

I'm using a lock over a section of code. Although the critical section is small, many threads would reach there (about 100 threads per second). In some articles I see this method is not suitable for heavy threading environments.

My question is at what rate we call an environment heavy threaded ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扎心 2024-10-16 19:54:56

不幸的是,我认为重线程没有任何具体的数字定义。一些快速的谷歌搜索向我展示了最近的上下文切换基准数字,引用上下文切换成本介于 1us30us。悲观地假设 30us,这意味着:

(30 us/switch * 100 switch/sec) == 3ms/sec == 0.3% context-switch overhead

每秒执行您提到的 100 次上下文切换。不用担心,但上下文切换并不是全部:您还必须考虑互斥体争用的成本,我建议在您自己的应用程序中以及您正在使用的特定互斥体实现中进行测量。

最重要的是,如果您的应用程序获得了可接受的吞吐量,那么以这些速率使用此模式就可以了。我的猜测是,互斥锁争用可能占主导地位,因此关键部分的运行时间(以及运行时间的可变性)可能会决定是否为您工作。

Unfortunately, I don't think there's any specific, numerical definition of heavy threaded. Some quick Googling showed me recent context switch benchmark numbers quoting context-switching costs as somewhere between 1us and 30us. Pessimistically assuming 30us, this means:

(30 us/switch * 100 switch/sec) == 3ms/sec == 0.3% context-switch overhead

for doing the 100 context switches per second you mention. No worry there, but context switches aren't the whole story: you'll also have to consider the costs of mutex contention, which I'd recommend measuring in your own application and with the specific mutex implementation you're using.

The bottom line is that if you get acceptable throughput for your app, it's fine to use this pattern at these rates. My guess is that mutex contention is likely to dominate, and thus that the running time (and variability of running time) of your critical section could make the difference between this working for you and not working for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文