CLR ThreadPool 中繁忙工作线程的数量是否会影响 I/O 线程的性能?

发布于 2024-10-11 12:39:46 字数 653 浏览 5 评论 0原文

我们有一个Windows 服务,它托管许多WCF 服务,并且在应用程序的不相关部分中广泛使用TPL < code>Task 类异步执行相对较短的工作。

据我了解,WCF 使用 ThreadPool 中的托管 I/O 线程来执行请求。我注意到,在部署显着提高应用程序对任务的使用以及 ThreadPool 工作线程的使用的功能后,一些 Web 服务的性能变得非常慢。我们谈论的是几分钟而不是不到一秒钟。任何一次实际尝试运行的任务数量可能在 20 到 1000 之间,这让我认为任何需要一些 CPU 时间的新(最后进入)工作都可能被迫等待相当长的时间。时间。

繁忙的 ThreadPool 工作线程数量(在我的情况下非常大)是否会影响 ThreadPool 的托管 I/O 线程?这两者有什么联系吗?或者我应该开始寻找其他地方......

谢谢!

编辑:我刚刚对应用程序的实时部署进行了抽查,同时尝试调用一个长时间运行的 Web 服务,这是非常典型的:正在运行 70 个任务,Windows 服务进程有大约 150 个线程,平均 CPU 使用率 30-60%。我所说的“典型”是指 CPU 使用率一般在 40% 左右,很少超过 80%,但是有大量的任务在运行,进程使用的线程也很多。

We have a Windows Service which hosts a number of WCF services and, in an unrelated part of the app, makes extensive use of the TPL Task class to asynchronously do relatively short bits of work.

It is my understanding that WCF uses managed I/O threads from the ThreadPool to execute requests. I noticed that after deploying a feature which significantly raised the applications use of Tasks, and as such the use of ThreadPool worker threads as well, performance of a couple of web services has become very slow. We're talking minutes instead of less than a second. The number of Tasks actually trying to run at any one time can range between 20 and 1000, which makes me think that any new (last in) work needing some CPU time could be forced to wait for quite some time.

Does the (in my case extremely large) number of busy ThreadPool worker threads affect the ThreadPool's managed I/O threads? Could these two be connected in any way? Or should I start looking elsewhere...

Thanks!

EDIT: I just did a spot check on a live deployment of the app while trying to call one of the long running web services which is quite typical: 70 Tasks running, Windows Service process has about 150 threads, average CPU usage 30-60%. By typical I mean that CPU usage is generally around 40% and rarely exceeds 80%, however there are a large number of Tasks running and threads used by the process.

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

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

发布评论

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

评论(2

英雄似剑 2024-10-18 12:39:47

注意:我以前从未回答过自己的问题,所以我希望这是合适的。请随意发表评论或不同意,但看起来其他人都没有回答这个问题。

因此,导致我们性能问题的问题是完全不相关的,现在已经解决了。

解决此问题后,Web 服务再次开始及时响应。这使我得出结论,您可以同时运行相当多的 TPL 任务(如我的示例中的数百个),并且即使大量使用线程池工作线程,WCF 仍然能够使用线程池的托管 I /O 线程有效地处理您的 Web 服务请求。

Note: I've never answered my own question before so i hope this is appropriate. Feel free to comment or disagree, but it is looking like this isn't getting answered by anyone else.

So, the problem causing our performance issues was something completely unrelated and is now solved.

After this was resolved, the web services began responding in a timely manner again. This leads me to conclude that you can have quite a lot of TPL Tasks running concurrently (like the hundreds in my example) and, even with their heavy usage of Thread Pool worker threads, WCF will still be able to use the Thread Pool's managed I/O threads efficiently to handle your web service requests.

嗫嚅 2024-10-18 12:39:46

如果您的任务花费任意时间休眠或等待 I/O,您可能会受益于使用 TaskCreationOptions.LongRunning 启动任务。
这会导致线程池创建更多线程,而不是等待排队的线程完成。

    task = Task.Factory.StartNew(() =>
   {
       DoLongRunningWork();
   }, TaskCreationOptions.LongRunning);

如果你想测试这个概念,有一个实验这里您可能会发现有帮助。

If your tasks spend any amount of time sleeping or waiting for I/O, you might benefit from starting your tasks with TaskCreationOptions.LongRunning.
This causes the thread pool to create more threads, rather than waiting for queued threads to complete.

    task = Task.Factory.StartNew(() =>
   {
       DoLongRunningWork();
   }, TaskCreationOptions.LongRunning);

If you want to test the concept, there is an experiment here which you might find helpful.

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