Log in

View Full Version : Setting Affinity for Hyper-threaded or Dual-core CPUs


HardwareGeek
27th May 2006, 09:08
Comment, not a question.

Those of you who have hyper-threaded or dual-core CPUs, and who do alot of encoding or transcoding, can set affinity for an encoding / transcoding program, so that just one of the two cores carries out the encoding. Cores can be real or simulated. i.e. dual-core or hyper-threaded.

Setting affinity can come in useful if you need to use your computer while you have an encoding or transcoding job underway. As we all know, encoding hammers the CPU, taking up practically 100% of the CPU resources at times. This can be frustrating, if you have a job going on, while you are trying to do work on your computer.

However, if you set affinity to one or the other core, only 50% of your processor resources will encode, leaving you the other 50% to do your work. As opposed to the encoding taking up 100%, leaving you with very little CPU with which to work.

To set affinity, call up Task Manager, go to the Processes tab, right click on the process or thread that represents your encoding program, Select "Set Affinity", then deselect one of the two cores.

mod
27th May 2006, 09:40
BES (http://mion.faireal.net/BES/) lets you decide the % usage of cpu. It's useful if you want to use the pc but also don't loose too much encoding speed.
Of course there's always the "idle" way.. :)

Doom9
27th May 2006, 11:45
Idle priority all the way. If you don't fill your PC with crap that eats up CPU cycles then idle won't affect encoding speed when you don't touch your machine.. and if you do, you can use up all CPU cycles for whatever apps you have running.

CPU Affinity only makes sense if you have an application that has issues with multiple CPUs.. those apps normally can't even make use of the second core anyway.

HardwareGeek
27th May 2006, 17:41
Idle priority all the wayUnfortunately, idle priority either doesn't work or is not an option on some encoding / transcoding tools, on some systems. E.g. FairUse Wizard & DVD Shrink. This is the case with all of the tools that I use. Too bad. I think that idle priority used to work on my previous system for some reason. But it doesn't work with my current rig. CPU Affinity only makes sense if you have an application that has issues with multiple CPUs.. those apps normally can't even make use of the second core anyway.I am sure that what you say is true. Way back when Autogordian Knot was having trouble with hyper-threading, I wish that I had known about setting affinity.

However, I would ever so slightly change to read "CPU Affinity makes sense ..." or "CPU Affinity also makes sense ..." Setting the affinity is the best way that I have discovered for usefully using my computer while encoding. I haven't tried the BES program that mod was kind enough to mention. It sounds great, too.

Thx for the feedback from both of you.

Shinigami-Sama
27th May 2006, 17:44
Unfortunately, idle priority either doesn't work or is not an option on some encoding / transcoding tools, on some systems.
ctrl+alt+del
task man, set it there

HardwareGeek
27th May 2006, 18:12
ctrl+alt+del
task man, set it thereIf you mean going to the Processes tab of Task Mgr, right clicking the process and selecting Set Priority / Low, it doesn't work. CPU still goes full bore on encoding / transcoding.

Shinigami-Sama
27th May 2006, 18:14
thats because it uses all the idle time, but will back off if anything else wants to use the cpu with a higher priority, which is basicly everything

Eretria-chan
27th May 2006, 18:55
Task manager doesn't allow idle. Only low. You should use a 3rd party program, ie process explorer.
I find affinity useful for some things that eats up cpu even when using idle. This can be some defragmentation utilities, for example. And of course, for programs which reacts negatively to dual cores.

mod
28th May 2006, 01:06
You should use a 3rd party program
Here (http://www.aldostools.com/speedup.html) you can find a nice tool: Aldo's SpeedUp.

http://img84.imageshack.us/img84/6660/speedup5ub.png

Works really good, also with command line :)

HardwareGeek
28th May 2006, 01:24
[CPU still goes full bore with thread priority set to low] thats because it uses all the idle time, but will back off if anything else wants to use the cpu with a higher priority, which is basicly everythingHi Shinigami-sama

As the Fairy Godmother said to Harold, the Frog Prince, you force me to do something I really didn't want to do.

I ran some preliminary benchmarks to try to quantify somewhat the effects of setting thread priority to low and setting affinity to one core--a simulated core in my case, since my CPU is hyper-threaded, but not genuine dual-core. Unless one has actually done benchmarks, one will not know how much tedious work is involved. Hats off to Anand, Loyd, & anyone else who does benchmarks on a regular basis.

My preliminary results show that setting the thread priority of an encoding job to low helps a foreground application. While this is logical, I was somewhat surprised, because I have set the priority of my encoding thread to low before and not been able to notice any change in the sluggishness of my OS and other applications while the encode was in progress. This may be because my test scenario does not accurately reflect my computer usage, where I typically have lots of programs, windows, & browser tabs open at one time.

Preliminary test results also show that setting affinity to one core, for an encoding application in the background, helps the foreground application more than setting thread priority to low.

I also did the test, setting both the affinity to one core and the priority to low. Not surprisingly, this helps even more.

Here are my scores (http://www.askaboutcomputers.com/benchmark_results.html). Values are in seconds. Not all of the results make sense. But I think the overall picture does. First I tested with no Shrink running in the background, then with Shrink thead priority set to Normal, the default, then with priority set to low, then with affinity set to just one of the cores, then, finally, with both affinity set and low priority set. Applications that I tested with were SharpReader, OpenOffice, Outlook Express, & Firefox. I took the web page from off my hard drive to eliminate probable Internet and web-server factors from influencing the result.

For each run, I rebooted, then ran the command "rundll32.exe advapi32.dll,ProcessIdleTasks" in order to execute all background idle tasks to completion, then waited a minute. I also let Shrink run for a minute in order to get the CPU pinned at 100%, or 50% for when the affinity was set to just one core. Was unable to defragment each time. Sorry. That would have taken too long.

My testbed: Pentium 4, 630, 1GB of dual-channel DDR2-533 (PC4200); 2 Seagate SATA-150 drives with NCQ in RAID 0 setup, Intel D925 motherboard. WXP x64. Bla, bla, bla ...

foxyshadis
28th May 2006, 06:22
Real dual-cores have less issues because a hyperthreaded core is only about 1/4 of a real core, depending on the application, and isn't as well designed as the true dual-core systems (let alone the 8 core sparcs), being somewhat shoehorned into the chip.

Dual sockets on the other hand can see real application performance go down significantly because of all the motherboard switching and latency, as well as cache flushes, maintaining cache coherency and bus-locking memory writes (dual/quad Opterons with hypertransport get to totally bypass the chipset so they don't have as much of an issue), so setting affinity for intensive single-threaded apps can help quite a bit.

In my personal experience: Running encodes on idle (by preference setting or using "start /low" causes very minor latencies working on other apps on single-cpu pentium m laptop and AXP server. On the 2-way dual-core opteron servers, there's zero slowdown, and on the Core Duo there's also zero slowdown, even when I'm gaming or compiling while the encode is going and trying to do other things as well.

So while this might be useful for P4-HT, Xeon, and maybe PD, probably not many others who are going to need it.

HardwareGeek
28th May 2006, 06:43
Real dual-cores have less issues ...Don't rub it in. I'm slobbering for a real dual-core. :)

@foxyshadis

I found your post very interesting. I fear I'm behind the curve of many who post in this forum, in many ways.

It looks like the setting affinity while encoding is primarily (solely?) of value to folks with an HT CPU, a shrinking percentage.

Eretria-chan
28th May 2006, 10:48
If you set the affinity of an encoding app to one core, it will be limited to 50%. But if you set it to idle, it will consume whatever resources are available, so I'd rather think Idle is better than one core.
@ mod: For me, I find Process Explorer to be a handy tool. It acts as a task manager but allows you to terminate processes that just don't want to die in the real task manager. That, and some other functions of course, among them affinity.

mod
28th May 2006, 11:04
If you set the affinity of an encoding app to one core, it will be limited to 50%. But if you set it to idle, it will consume whatever resources are available, so I'd rather think Idle is better than one core.
Agree 100%, also if deciding the % of cpu used by a process helps limiting the temperature if you have a notebook and it's summer ;)
@ mod: For me, I find Process Explorer to be a handy tool. It acts as a task manager but allows you to terminate processes that just don't want to die in the real task manager. That, and some other functions of course, among them affinity.
Just reporting another nice one :)

HardwareGeek
28th May 2006, 19:06
I'd rather think Idle is better than one core.
Agree 100%, also if deciding the % of cpu used by a process helps limiting the temperature if you have a notebook and it's summer
Setting thread priority of an encoding app to idle will not help keep the temperature down if the thread is still allowed to consume the rest of a CPU's available resources. The greater the CPU utilization, the greater the heat.

This is a case where setting affinity to one core should help more. If affinity is set to one core, it throttles the thread at 50%. If set to Idle, thead can still go up to 100%, if I understand correctly.

If you set the affinity of an encoding app to one core, it will be limited to 50%. But if you set it to idle, it will consume whatever resources are available, so I'd rather think Idle is better than one core.Point taken. However, I can't set my encoding apps to idle without resorting to third party utilities, which some of your were good enough to mention some and / or post links to. Thx, BTW. However, setting an encoding thread's affinity to one core on CPUs that do hyper-theading enables one to work with other applications noticeably better than setting the thread's priority to low. This only seems to apply to CPUs that have hyper-threading, and not to dual-core CPUs, judging from feedback above.

Doom9
28th May 2006, 20:10
If set to Idle, thead can still go up to 100%, if I understand correctly.That's not correct.. a thread runs on a single core.. that's why you need multithreaded apps to make use of multiple cores.. Ideally, if you have two cores you have two threads that use the same amount of CPU cycles.. then your CPU will be fully used. If the load isn't the same, you'll have a lower than 100% total CPU use. This explains why you only have 50% CPU use when using a non SMP capable encoder.. unless you're using VDub which has two threads - one for encoder and one for input reader.. depending on the encoding complexity such a setup can make good use of a dual core setup.

And if your box can't withstand the temperatures in summer.. it's bad engineering.. a couple degrees more shouldn't cause any device to overheat.

mod
28th May 2006, 23:33
Agree 100%, also if deciding the % of cpu used by a process helps limiting the temperature if you have a notebook and it's summer
Sorry for my bad english. I was meaning "..also if I think that having the possibility to decide.."

And if your box can't withstand the temperatures in summer.. it's bad engineering.. a couple degrees more shouldn't cause any device to overheat.
I agree, but s*** happens (hey, not to me!) .. :)

HardwareGeek
28th May 2006, 23:50
If set to Idle, thead [thread] can still go up to 100% ...That's not correct.. a thread runs on a single core ...That may be. I was confusing threads with processes.

Allow me to rephrase. If an application's process is set to Idle, it can still consume all remaining CPU resources available, so much so that CPU utilizaiton can be pinned at 100%. Click here (http://www.askaboutcomputers.com/process_explorer.gif) for a snapshot of a process set to idle, nevertheless consuming all available CPU resources.

Many if not most encoding applications are multithreaded and so can take advantage of two cores. Click here (http://www.askaboutcomputers.com/dvd_shrink_threads.gif) for a snapshot of many threads in flight by one DVD Shrink process. If affinity is set to just one core, the total amount of CPU that process can use is throttled at about 50%, which better frees up the other core for other chores, more so than setting priority to idle. This appears to only matter with CPUs that have hyper-threading and not genuine dual-core chips, according to the responses above.

if your box can't withstand the temperatures in summer.. it's bad engineeringThermal management of laptops has always been a challenge. Not sure we can attribute this to poor engineering. But regardless. If someone has a poorly engineered computer, setting affinity to one core strikes me as a legitimate technique for managing heat. It's not the only technique. I downloaded and installed the BES (Battle Encoder Shirase) (http://mion.faireal.net/BES/) program that mod mentioned above, & it allows one to exercise alot more control over how much CPU a process uses.

I'm sure Aldo's SpeadUp (mentioned above) is a fine program, but it doesn't want to work on my x64 OS. Process Explorer (http://www.sysinternals.com/Utilities/ProcessExplorer.html) (also mentioned above) is really cool, but it doesn't seem to limit CPU usage of processes.

mod
28th May 2006, 23:56
I downloaded and installed the BES (Battle Encoder Shirase) (http://mion.faireal.net/BES/) program that mod mentioned above, & it allows one to exercise alot more control over how much CPU a process uses.
Happy to hear you tried it :)
I'm sure Aldo's SpeadUp (mentioned above) is a fine program, but it doesn't want to work on my x64 OS.
Damn..

HardwareGeek
29th May 2006, 00:15
Happy to hear you tried it :)Tried it and like it.

Also like Process Explorer (http://www.sysinternals.com/Utilities/ProcessExplorer.html), which Eretria-chan pointed out.

mod
29th May 2006, 00:20
Also like Process Explorer (http://www.sysinternals.com/Utilities/ProcessExplorer.html), which Eretria-chan pointed out.
Yes, really nice tool.

Mug Funky
29th May 2006, 07:29
there's a free program called "startaffinity" (google will find this easier than my posting a link) that can help a lot on old programs that don't like 2 CPUs, real or virtual.

DVDMaestro is one of these, and though nobody should really be using it anymore, it's still often used because it's successor DVD Studio Pro is pretty crap and only on the mac. anyhoo, it wont compile properly unless set to 1 CPU, so re-routing your shortcut via StartAffinity can help things a bit.

apart from that, and programs like it, setting priority to low shouldn't affect the speed of the program in front. if it does the program should probably be set to it's own CPU and the encode on the other - this fixes it most of the time.

HardwareGeek
29th May 2006, 17:13
setting priority to low shouldn't affect the speed of the program in frontHi

Thanks for your suggestions.

Setting an encoding thread priority to low does help speed up other applications. See my preliminary benchmarks results here (http://www.askaboutcomputers.com/benchmark_results.html).