Organizational Research By

Surprising Reserch Topic

parallel foreach returns less results on azure webjobs using -'azure,parallel-processing,azure-webjobs,parallel.foreach'


parallel foreach returns less results on azure webjobs  using -'azure,parallel-processing,azure-webjobs,parallel.foreach'

Running the following code on my local machine

Console.WriteLine("Loaded: " + records.Count);

        Parallel.ForEach(records, record =>
        {
            try
            {
                var client = new HttpClient();
                var response = client.SendAsync(new HttpRequestMessage(HttpMethod.Head, Http + record.DomainName)).Result;
                if (!response.IsSuccessStatusCode || !response.RequestMessage.RequestUri.Host.EndsWith("domain.com"))
                    return;
                var finalDomain = response.RequestMessage.RequestUri.Host.Replace(Www, null);
                if (_resultsList.Add(finalDomain))
                    Console.WriteLine("Added: " + finalDomain);
            }
            catch (Exception)
            {
                // ignored
            }
        });

Console.WriteLine("Added: " + _resultsList.Count);


Writes the following to console

Loaded: 3556
Added: 1550


But when I upload it, and run it as an Azure Webjob I get a lot less domains returning.

Loaded: 3556
Added: 308


Replacing Parallel.ForEach() with a regular foreach returns the same number of domains on both, but it takes a lot longer. Why is Parallel.ForEach() not returning the same number of results on Azure Webjobs, as on my own machine?
    
asked Sep 7, 2015 by rajesh
0 votes
8 views



Related Hot Questions



Government Jobs Opening


...