Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are multithreaded apps bound to a single core?

I'm running a .NET remoting application built using .NET 2.0. It is a console app, although I removed the [STAThread] on Main.

The TCP channel I'm using uses a ThreadPool in the background.

I've been reported that when running on a dual core box, under heay load, the application never uses more than 50% of the CPU (although I've seen it at 70% or more on a quad core).

Is there any restriction in terms of multi-core for remoting apps or ThreadPools?

Is it needed to change something in order to make a multithreaded app run on several cores?

Thanks

like image 368
pablo Avatar asked Jun 30 '09 01:06

pablo


1 Answers

There shouldn't be.

There are several reasons why you could be seeing this behavior:

  1. Your threads are IO bound.

    In that case you won't see a lot of parallelism, because everything will be waiting on the disk. A single disk is inherently sequential.

  2. Your lock granularity is too small

    Your app may be spending most of it's time obtaining locks, rather than executing your app logic. This can slow things down considerably.

  3. Your lock granularity is too big

    If your locking is not granular enough, your other threads may spend a lot of time waiting.

  4. You have a lot of lock contention

    Your threads might all be trying to lock the same resources at the same time, making them inherently sequential.

  5. You may not be partitioning your threads correctly.

    You may be running the wrong things on multiple threads. For example, if you are using one thread per connection, you may not be taking advantage of available parallelism within the task you are running on that thread. Try splitting those tasks up into chunks that can run in parallel.

  6. Your process may not have a lot of available parallelism

    You might just be doing stuff that can't really be done in parallel.

I would try and investigate each one to see what the cause is.

like image 55
Scott Wisniewski Avatar answered Oct 04 '22 22:10

Scott Wisniewski