0

Inside a Parallel Foreach I'm calling a service that gives me all information about an article, If I try to take the information about only one it takes 6 seconds.

My questions about that:

  • If I want to take the information about 4 articles, how long will it take? +- 6 seconds??

  • Actually doing that it takes 27 seconds, There's an easy way to check if it's working on parallel ??

Working with C# MVC3

Code:

   private void PopulateArticleDictionary()
    {
        List<Article> tmpArticleFirstLevel = new List<Article>();
        Parallel.ForEach<Article>(ArticlesFirstLevel,
            article =>
            {
                var articleInDepth = ArticleService.SearchByCode(article.Code, article.Code18, article.Quantity, "ES", "EUR");
                if (articleInDepth == null)
                {
                    tmpArticleFirstLevel.Add(article);
                }
                else
                {
                    tmpArticleFirstLevel.Add(articleInDepth);
                }                   

            }
            );            
        ArticlesFirstLevel = tmpArticleFirstLevel;
    }

Thank's !

tereško
  • 58,060
  • 25
  • 98
  • 150
user1520494
  • 1,134
  • 2
  • 11
  • 27

1 Answers1

0

How many cores do you have? The Parallel libraries won't spin up extra threads if you don't have the extra processors to take advantage of it. Also there is some overhead, doing parallel on 4 articles probably isn't really worth it unless you have a lot of crunching going on.

Also are you sure your service isn't a bottle neck?

Try this and see if there is an improvement

   System.Net.ServicePointManager.DefaultConnectionLimit = 1000;

You could have a bottleneck connecting to your service as .NET out of the box only allows 2 concurrent HTTP pipes to the same host.

Matt
  • 3,638
  • 2
  • 26
  • 33
  • You're right! :D first of all thank's for your fast response, the service was configurated syncro and the provider have to change it.. -.-' now It's time to dance gangnam style. Regards!! – user1520494 Oct 23 '12 at 09:09