Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / June 2005

Tip: Looking for answers? Try searching our database.

threaded application not using all processors

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cbenmichael@yahoo.com - 30 May 2005 18:22 GMT
I have written a server application, that will eventually be deployed
as a windows service.  Currently, I am testing it as a console
application.  I have a main thread that gets requests using remoting,
and then spawns worker threads (currently limited to 4),  which run a
long running non-linear regression analysis.  All the worker threads
seem to be running in a single processor.

I have set the environment variable "COMPLUS_BuildFlavor", and have
verified that the process is using the mscorsvr.dll.

I read somewhere that if the threads are running in a .net form, then
the they will always run in a single processor this is not the case.
- Are there other parts of the framework which would cause all the
threads to run in one processor?
- Why is this happening and how can I fix :)?

- I am using a dual Xeon, with 2 virtual processors, on a Dell machine.
- environment: VS2003
- language: vb.net

cb
Ian Griffiths [C# MVP] - 31 May 2005 18:33 GMT
> I have a main thread that gets requests using remoting, and then
> spawns worker threads (currently limited to 4),  which run a
> long running non-linear regression analysis.

How are you spawning the threads?  Can you show us a code snippet?

>  All the worker threads seem to be running in a single processor.

How are you determining this?  Are you looking at the CPU usage in task
manager or are you doing something more sophisticated?

Are you certain that all 4 threads are actually running simultaneously?
Have you checked to make sure they are all making progress, and that there
isn't some synchronization issue making them take it in turns?  I'd use
something like Process Explorer (a free tool from www.sysinternals.com ) to
look at the per-thread CPU usage.

> I have set the environment variable "COMPLUS_BuildFlavor", and have
> verified that the process is using the mscorsvr.dll.

That should really only affect your GC behaviour.  The workstation version
of the CLR is perfecly capable of using multiple CPUs, so long as it's your
code that's doing the actual work.

> I read somewhere that if the threads are running in a .net form,
> then the they will always run in a single processor

Err, no.  It sounds like that message got badly garbled somewhere along the
way.

In a Windows Forms application, it is vitally important that any access to
the UI is done on the same *thread*.  But there are no limitations as to
which processor that thread runs on.  And you're welcome to have as many
worker threads as you like so long as they don't try to update the UI.  So
it's entirely possible for a Windows Forms app to make use of multiple CPUs.

> - Are there other parts of the framework which would cause all
> the threads to run in one processor?

There's a Windows feature: thread affinity.  It's possible to tell Windows
to

> - Why is this happening and how can I fix :)?

No idea.

Here's some simple code that fires up two threads, and which does pointless
busy work that consumes 100% of the CPU on my dual-proc system (i.e. it is
using both CPUs completely) for a minute or two:

using System;
using System.Threading;

class app
{
 static void DoWork()
 {
   int i = 0;
   double total = 0;
   while (i < 1000000000)
   { ++i; total += 1.0 / i; }
   Console.WriteLine(total);
 }

 static void Main()
 {
   ThreadStart threadProc = new ThreadStart(DoWork);
   Thread t1 = new Thread(threadProc);
   Thread t2 = new Thread(threadProc);

   t1.Start();
   t2.Start();
   Console.WriteLine("Both threads running.");
   t1.Join();
   t2.Join();
   Console.WriteLine("Done");
 }
}

So I suggest you start by comparing that with your code to see how it
differs.

I compiled this with no special flags.  I didn't do anything special to the
environment.  I just ran the code on a Windows Server 2003 box with version
1.1 of the .NET Framework installed.

Signature

Ian Griffiths - http://www.interact-sw.co.uk/iangblog/ 

john conwell - 15 Jun 2005 18:05 GMT
Are you running under a DEBUG or RELEASE build?  I have noticed (though not
consistantly) that my multi-threaded apps seem to have all their threads run
on one proc (on a quad proc machine).  when i make a RELEASE build, the
threads are always distributed across all procs.

I'm curious if there is something in the CLR that sets processor affinity
when under a debug build

> I have written a server application, that will eventually be deployed
> as a windows service.  Currently, I am testing it as a console
[quoted text clipped - 17 lines]
>
> cb
Ajit - 24 Jun 2005 18:28 GMT
Check for the following in machine.config file:

MaxConnection                   =    12 * #CPUs
MaxIOThreads                   =      100
maxWorkerThreads            =       100
MinFreeThreads                    =    88 * #CPUs
MinLocalRequestFreeThreads   = 76 * #CPUs

Regards,
Ajit

> I have written a server application, that will eventually be deployed
> as a windows service.  Currently, I am testing it as a console
[quoted text clipped - 17 lines]
>
> cb

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.