I have a structure of nested Parallel.For and PLINQ statements in my small console app that basically performs network-bound operation(performing http requests) like following:
a list of users is filled from DB where then I do following:
Parallel.For(0,users.count(), index=>{
// here I try to perform HTTP requests for multiple users
});
Then inside this for loop I perform a plinq statement for fetching this user's info via HTTP requests.
So that now in total I get two nested loops like following:
Parallel.For(0,users.count(), index=>{
// Some stuff is done before the PLINQ statement is called...
newFilteredList.AsParallel().WithDegreeOfParallelism(60).ForAll(qqmethod =>
{
var xdocic = new XmlDocument();
xdocic.LoadXml(SendXMLRequestToEbay(null, null, qqmethod.ItemID, true, TotalDaysSinceLastUpdate.ToString(), null));
int TotalPages = 0;
if (xdocic.GetElementsByTagName("TotalNumberOfPages").Item(0) != null)
{
TotalPages = Convert.ToInt32(xdocic.GetElementsByTagName("TotalNumberOfPages").Item(0).InnerText);
}
if (TotalPages > 1)
{
for (int i = 1; i < TotalPages + 1; i++)
{
Products.Add(SendXMLRequestToEbay(null, null, qqmethod.ItemID, false, TotalDaysSinceLastUpdate.ToString(), i.ToString()));
}
}
else
{
Products.Add(SendXMLRequestToEbay(null, null, qqmethod.ItemID, false, TotalDaysSinceLastUpdate.ToString(), "1"));
}
});
});
I tried using the outer for loop just as a regular one ,and I noticed that it was performing much faster and better than like this.
What worries me here mostly is that I was checking the utilization of CPU when running the console app like this, it's always nearby 0.5-3% of total CPU power...
So the way I'm trying to perform HTTP requests is like this:
15 users at a time * amount of HTTP requests for those 15 users.
What am I doing wrong here?