【发布时间】:2011-12-11 11:52:24
【问题描述】:
我正在分析一个使用不同数量的允许线程运行的多线程程序。以下是相同输入工作的 3 次运行的性能结果。
1 thread:
Total thread time: 60 minutes.
Total wall clock time: 60 minutes.
10 threads:
Total thread time: 80 minutes. (Worked 33% longer)
Total wall clock time: 18 minutes. 3.3 times speed up
20 threads
Total thread time: 120 minutes. (Worked 100% longer)
Total wall clock time: 12 minutes. 5 times speed up
由于做同样的工作需要更多的线程时间,我觉得线程一定在争夺资源。
我已经检查了应用程序机器和数据库服务器上的四大支柱(cpu、内存、diskIO、网络)。内存是最初的竞争资源,但现在已经修复(始终超过 1G 可用)。在 20 线程测试中,CPU 徘徊在 30% 到 70% 之间,所以很多。 diskIO 在应用程序机器上几乎没有,在数据库服务器上几乎没有。网络真的很棒。
我还使用 redgate 进行了代码分析,发现没有等待锁的方法。它有助于线程不共享实例。现在我正在检查更细微的项目,例如数据库连接建立/池(如果 20 个线程尝试连接到同一个数据库,它们是否必须相互等待?)。
我正在尝试识别和解决资源争用问题,以便 20 线程运行如下所示:
20 threads
Total thread time: 60 minutes. (Worked 0% longer)
Total wall clock time: 6 minutes. 10 times speed up
我应该查看哪些最有可能的来源(除了四大来源)以找到这种争用?
每个线程执行的代码大概是:
Run ~50 compiled LinqToSql queries
Run ILOG Rules
Call WCF Service which runs ~50 compiled LinqToSql queries, returns some data
Run more ILOG Rules
Call another WCF service which uses devexpress to render a pdf, returns as binary data
Store pdf to network
Use LinqToSql to update/insert. DTC is involved: multiple databases, one server.
WCF 服务在同一台机器上运行,并且是无状态的,能够同时处理多个请求。
机器有 8 个 CPU。
【问题讨论】:
-
建议您发布您尝试并行化的代码/算法
-
你的机器有多少个 CPU?
-
你的操作大多是IO绑定的,这些IO调用是异步的吗?如果不尝试让它们异步,然后看看你是否有任何好处
-
好吧,我很感激这种能帮助我“解决”性能问题的本能。在这个阶段,衡量问题先于解决方案。我要求测量更多的东西。
-
在此过程中进行一些堆栈转储,您将自己看到争用。
标签: .net multithreading profiling contention