处理大量数据时,Parallel.ForEach引发异常 [英] Parallel.ForEach throws exception when processing extremely large sets of data

查看:169
本文介绍了处理大量数据时,Parallel.ForEach引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题集中在一些曾经成功运行的Parallel.ForEach代码上,现在我们的数据库已增长到原来的5倍,它几乎会定期中断.

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 );
} );

ComputeTipDown()方法获取该符号的所有每日库存数据,并进行每天迭代,获取昨天的数据并进行一些计算,然后将其每天插入数据库中.

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.

例外是:

我们要访问的数据库具有16 gig的ram,并且是双四核的,在我重新计算时没有人使用该系统.运行该应用程序以重新生成代码的计算机是一台笔记本电脑,该笔记本电脑具有12 gig的ram和超线程八核.因此,没有明显的资源争用.

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.

这是我尝试使用.NET 4和并行处理的尝试,所以我想知道是否缺少某些内容.任何想法都将受到欢迎.

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.

推荐答案

这似乎是您收到的 AggregateException ,如果任何循环体方法引发异常,Parallel.ForEach都会引发这种异常.

This looks like you received an AggregateException, which is what Parallel.ForEach will raise if any of the loop body methods raise an exception.

如果您对此进行调试,则应该能够查看 InnerExceptions 查看引发的实际异常.看来ComputeTipDown在您的一个或多个迭代中引发了异常,导致这种情况发生.

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.

这篇关于处理大量数据时,Parallel.ForEach引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆