I am not pro in utilizing resources to the best hence am seeking the best way for a task that needs to be done in parallel and efficiently.
We have a scenario wherein we have to ping millions of system and receive a response. The response itself takes no time in computation but the task is network based.
My current implementation looks like this -
Parallel.ForEach(list, ip =>
{
try
{
// var record = client.QueryAsync(ip);
var record = client.Query(ip);
results.Add(record);
}
catch (Exception)
{
failed.Add(ip);
}
});
I tested this code for
- 100 items it takes about 4 secs
- 1k items it takes about 10 secs
- 10k items it takes about 80 secs
- 100k items it takes about 710 secs
I need to process close to 20M queries, what strategy should i use in order to speed this up further