-1

I developed a console application which takes the ipaddress as input and provides the uptime of the devices in the log file. Totally 27000 ipaddress are there. it takes nearly 2 days to give the output.

Please help how can i make speed my application using multi therading.

jinnah
  • 1
  • 2
  • You will not be able to read all those lines anyway so I would suggest saving to file. Console output is pretty slow – Michał Apr 06 '14 at 10:00
  • 1
    Also, try this: http://stackoverflow.com/questions/5272177/console-writeline-slow – Michał Apr 06 '14 at 10:01

1 Answers1

0
public static class Program
{
    internal static string Result(string ip)
    {
       // your function here
    }

    internal static void Main()
    {
        const int ParallelJobs = 100;

        var ips = File.ReadAllLines("your.data");

        var results = ips.AsParallel().WithDegreeOfParallelism(ParallelJobs ).Select(Result).ToList();

        File.WriteAllLines("your.results", results);
    }
}

Basically, that's it. Now it runs in parallel. Your jobs seem to be I/O bound with a lot of idle waiting time, so I would set the degree of parallelism quite high. "Waiting" can be done in huge batches :)

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • For network I/O you'll want to add a MaxDegereeOfParalle option. – H H Apr 06 '14 at 10:05
  • @HenkHolterman yes, indeed. But you cannot with PLinq, that's why I specifically mentioned the other methods, where you can. – nvoigt Apr 06 '14 at 10:10
  • 1
    `AsParallel().WithDegreeOfParallelism(8).Select(...)` – H H Apr 06 '14 at 10:13
  • @HenkHolterman woaw, never saw that. Looked for a parameter but never found it. That's damn cool. Thanks a lot! – nvoigt Apr 06 '14 at 10:15