[Mono-list] Threading and IO problem

Glen Ford glen.a.ford at gmail.com
Thu Mar 6 14:46:40 EST 2008


What does top or vmstat tell you?  Are you getting IOWait?  System CPU?

Do you have 8 CPUs or 8 cores?

Multicore processors often have to compete for the memory bandwidth -
on one project we had to move from quad-core to multiple dual-core
because of this.



On Thu, Mar 6, 2008 at 5:50 PM, Yanko Hernández Álvarez
<yhdezalvarez at gmail.com> wrote:
> I've made a small program to use all processors on a system to analyze N
> text files. But when it's run on a 8 CPU PC, the CPU time stays around
> 70%-80% and the idle time between 20-30%.
>
> I  made a small program to illustrate the problem, it was simplified it to
> the point it doesn't process anything. It just creates a thread for every
> processor on the system and every thread just reads an entire file passed as
> parameter:
>  ------------------------------------
> using System;
> using System.IO;
> using System.Threading;
>
> namespace MultipleReader
> {
>     class Program
>     {
>         static void Main(string[] args)
>         {
>             Thread[] Threads = new Thread[Environment.ProcessorCount];
>             for (int Idx = 0; Idx < Threads.Length; Idx++)
>             {
>                 MyThread T = new MyThread(args[0]);
>                 Threads[Idx] = new Thread(new ThreadStart(T.Process));
>             }
>             foreach (Thread T in Threads)
>                 T.Start();
>             foreach (Thread T in Threads)
>                 T.Join();
>         }
>     }
>
>     class MyThread
>     {
>         private string FileName;
>
>         public MyThread(string FileName)
>         {
>             this.FileName = FileName;
>         }
>
>         public void Process()
>         {
>             string Str;
>             using (StreamReader SR = new StreamReader(FileName))
>                 while ((Str = SR.ReadLine()) != null) ;
>         }
>     }
> }
> ------------------------------------
> When this program is run using a large text file as a parameter (a ~600 megs
> file, to make the reading last in the order of tens of seconds) the same
> behavior is observed. Is this normal? What is causing this behavior? Is
> there any way to use all the processors at full capacity?
>
> The file is fully cached (cat file /dev/null) on RAM (4G RAM on this PC)
> before the program is started.
>
>     Yanko
>
> _______________________________________________
>  Mono-list maillist  -  Mono-list at lists.ximian.com
>  http://lists.ximian.com/mailman/listinfo/mono-list
>
>


More information about the Mono-list mailing list