ProcessThread.ProcessorAffinity performance impact?

I am wondering about the quantitative impact of tuning ProcessThread.ProcessorAffinity property. What are the particular use cases of the such property

In particular, I have a bi-processor machine that support an intensive CPU/Disk .Net application (scientific computing). In this application, I have sereval threads with distinct priorities (basically one thread with high priority, the few other with low priority). Should I manually assign the high priority thread to one processor and the other threads to the second processors

I know that the only certain answer would be to do extensive mesurements. But I would rather have some insights on the theoretical impact of such property before digging in the raw perf mesurements.

Thanks in advance,
Joannes


Answer this question

ProcessThread.ProcessorAffinity performance impact?

  • Mehul Thakkar

    I think Joe is spot on.  I have seen some successful cases with usage of processor affinity, but they are rare.  What I have seen was done in building a queuing network between threads where the advantage comes from having each processor be dedicated to a specific task with dataflow going between CPUs.  That sort of thing required a great deal of experimentation and it was specifically tuned for a particular type of 8-way configuration.

    Ultimately going down this path without extensive testing is likely to result in a big disappointment.

     

  • Radical

    Your intuition is correct--only extensive testing can determine whether setting processor affinity will provide any benefit. It's likely it would do the opposite of what you envisioned. I would recommend this book http://www.amazon.com/exec/obidos/tg/detail/-/0735619174/ for details on soft/hard affinity in Windows.

    Some general advice w/out being privy to the details of your situation: I would recommend simply setting priorities and letting the OS schedule your work accordingly. If you have a runnable high priority thread and 5 lower priority threads, Windows will probably just assign your high priority thread to a processor and let the other 5 round robin on the other (provided anti-starvation doesn't kick in). This--if I understand correctly--is what you desire anyhow. So in all likelihood it will just work for you.

    Windows uses soft affinity on threads automatically. That is, it prefers to run your runnable task on the same processor it ran on last time. This is in an attempt to maintain cache warmth. One example of where affinity might be a good idea beyond this policy, however, is if you're on a dual-core machine and have two tasks that cooperate on the same set of data. In this case, you might want them to share the cache hierarchy; to "force" that, affinity might come in handy.

    If you want to follow up, feel free to email me directly: joedu@microsoft.com.

    Hope this helps.

    Joe Duffy
    Program Manager, CLR Team
    Microsoft

  • ProcessThread.ProcessorAffinity performance impact?