Parallel.ForEach 在处理极大的数据集时抛出异常
我的问题集中在一些 Parallel.ForEach 代码上,这些代码过去可以正常工作,现在我们的数据库已经增长到原来的 5 倍,它几乎经常崩溃。
Parallel.ForEach<Stock_ListAllResult>( lbStockList.SelectedItems.Cast<Stock_ListAllResult>(), SelectedStock =>
{
ComputeTipDown( SelectedStock.Symbol );
} );
ComputeTipDown() 方法获取该交易品种的所有每日股票波动数据,并迭代每一天,获取昨天的数据并进行一些计算,然后将它们插入每天的数据库中。
当公式更改时,我们很少使用它来重新计算静态数据值。
例外是这样的:
我们正在访问的数据库有 16 GB 内存,是双四核,没有人当我重新计算时正在使用该系统。运行应用程序以重新生成代码的机器是一台笔记本电脑,具有 12 GB 内存和超线程八进制核心。所以不存在明显的资源争夺。
这是我尝试使用 .NET 4 和并行处理,所以我想知道我是否遗漏了一些东西。任何想法都会受到欢迎。
My question centers on some Parallel.ForEach code that used to work without fail, and now that our database has grown to 5 times as large, it breaks almost regularly.
Parallel.ForEach<Stock_ListAllResult>( lbStockList.SelectedItems.Cast<Stock_ListAllResult>(), SelectedStock =>
{
ComputeTipDown( SelectedStock.Symbol );
} );
The ComputeTipDown() method gets all daily stock tic data for the symbol, and iterates through each day, gets yesterday's data and does a few calculations and then inserts them into the database for each day.
We use this rarely to recalculate static data values when a formula changes.
The exception is this:
The database we are hitting has 16 gigs of ram and is a dual quad-core and nobody was using the system while I was recalculating. The machine running the application to regenerate the code is a laptop with 12 gigs of ram with a hyper-threaded octal-core. So there was no obvious resource contention.
This is my foray into using .NET 4 and parallel processing, so I am wondering if there is something I am missing. Any thoughts would be welcomed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您收到了 AggregateException,这就是 Parallel。如果任何循环体方法引发异常,ForEach 都会引发异常。
如果您对此进行调试,您应该能够查看 InnerExceptions< /a> 查看实际抛出的异常。看起来
ComputeTipDown
在一次或多次迭代中引发了异常,从而导致了这种情况的发生。This looks like you received an AggregateException, which is what Parallel.ForEach will raise if any of the loop body methods raise an exception.
If you debug this, you should be able to look at the InnerExceptions to see the actual exceptions thrown. It looks like
ComputeTipDown
raised an exception in one or more of your iterations, causing this to occur.