0

I have created a C++ windows console application using (HANDLE)_beginthreadex() in which 1000 worker threads are controlled using x handler threads.

Initially I thought that 1000 handler threads would result in the quickest time but after testing I have found that using 100 handler threads results in quickest time. The testing was carried out on a quad core intel i7 processor (supports hyperthreading)

I'm not sure what to write for my reasoning of why that number of threads results in the best performance. As my processor can only handle 8 threads simultaneously, I would have thought 8 would have been the best performance.

I'm writing a small report on the application and have to identify the number of threads that results in the best performance and explain why this is the case.

1
  • It's worth noting in this answer stackoverflow.com/questions/12124586/…, that you haven't tested how it is when a % of those threads were actually spread over different cores... Commented Apr 23, 2013 at 20:19

1 Answer 1

3

You want to have 8 active threads at a time ideally. There are many reasons why 8 might not be the ideal number in general, but it's a good bet the work in your threads is not CPU limited. If you have too few threads in that case, you would be wasting time, while too many would, of course, cause undue contention -- and possibly be causing too many context switches.

Sign up to request clarification or add additional context in comments.

3 Comments

IOW, profile the app to see where the threads are waiting for non-CPU-work to complete. (+1)
In my application, I start my 1000 worker threads first then my handler threads second, does it matter the order they are started? Would the program run better if the handler threads started first and were ready to handle the worker threads when they have finished their task?
Once you get past some stuttering the OS scheduler will dominate, so it probably doesn't matter after a few seconds. Of course the only way to know for sure would be to profile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.