0

I have a Process that invoke Multiple threads( say 6 Thread) . What will be the impact of its performance once If I run it on a server machine with 6 CPU OR 4 CPU

What is the relation between Threads CPU and Cores inside each CPU.

I have read that, threads run in only different cores inside one CPU.is that true?

Jobs
  • 1,257
  • 2
  • 14
  • 27
  • That's not quite accurate. One CPU can divide and run multiple threads, basically it's just switching between them on the fly, as opposed to running one task from start to end. This is of course, much more efficient with multi-core CPU's, as each thread can actually be directly bound against a single CPU core, and thus ran from start to end. If you were to run 6 threads on a 4 core machine, you might end up taking a slight performance hit, depending on how intensive the process is that's running. – user2366842 Dec 04 '13 at 16:56

1 Answers1

5

It depends.

If your tasks are CPU-bound with no pipeline stalls, then you'll get the best performance from spawning one thread per physical CPU core.

If your CPU-bound tasks have pipeline stalls from cache misses, branch mispredictions, dependencies, etc, then you can take advantage of Hyperthreading and spawn one thread per virtual core. On a CPU without Hyperthreading the number of virtual cores is equal to the number of physical cores.

If your tasks block for IO, then you can benefit from spawning many more threads than CPU cores. The Apache web server is an example of this approach.

japreiss
  • 11,111
  • 2
  • 40
  • 77
  • My Process is both Io and CPU bound . ( It is a Mapreduce Program running as standalone). – Jobs Dec 04 '13 at 17:03
  • Depending on the programming language, you may be able to very easily determine the number of logical processors (this accounts for both physical cores and hyperthreading), take a look at this: http://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c it's an example for C#, but i'm sure it's very doable in other languages as well. – user2366842 Dec 04 '13 at 17:04
  • I am really confused with CPU and Cores. in my system I have 6 CPU and each CPU contain 4 cores. ( total 24 cores) . My program invoke 6 or more threads at a time. Where these threads gets executed ? 4 in one cpu and 2 in another cpu? – Jobs Dec 04 '13 at 17:06
  • Most modern machines will have one CPU (this is the number of physical processors -- you only usually see multiple on servers) , multiple cores (usually 4-8) and depending if it's hyperthreaded (Intel only, I believe) the number of logical processors gets effectively doubled. In your case if you actually DO have 24 cores (sounds like it's running a pretty powerful server) you should be using 24 threads, if of course, that's the only machine it'll be running on. Running more than this might speed up the IO stuff, however it could potentially bottleneck other code. – user2366842 Dec 04 '13 at 17:08
  • Also, it's sorta hard to say where exactly where the threads will get executed with a setup like that......it could switch between runs of the program even. – user2366842 Dec 04 '13 at 17:15