One feature that has been available in Windows for a long time now has been setting processor affinity for your applications. However, not a lot of users know about it because quite frankly, it’s not really needed at all! Setting processor affinity allows you to adjust the amount and specifically which CPU cores an application can use. If you have a dual core CPU, that means you have two logical processors within a single physical CPU chip. If you have a quad-core CPU, then you have four logical processors within a single physical CPU chip. An application designed to take advantage of these extra cores obviously runs faster and allows you to complete tasks much faster. Just recently, a good friend needed a way to manually convert his huge DVD library into a much more compact file that can be played on his tablet. Each of his DVD consists of about four 1GB VOB files. Technically, he could just ram those files onto a SD card and call it a day but his DVD collection is huge. Therefore, it wasn’t efficient. So we then had to find the best way possible to convert those video files into a much smaller size and more importantly, retain as much quality as possible. We tried various conversion formats via Format Factory, one of my favorite conversion utility, but my friend wasn’t satisfied. He wanted the conversion to be more faster and retain more quality. I then tried out Handbrake and it was perfect. However, there was just one problem. This utility really puts a work on your CPU and with that comes extreme heating issues.You can download Handbrake from here.
Handbrake is one of the more popular conversion utilities out there to help users convert their video files into a compatible format for their Apple devices (iPhone, iPad, iPod). However, its not just for users with Apple devices. Many tablets and similar devices like to support the .MP4 video format and so a video converted within Handbrake will play on Apple devices as well as any other device that supports the format. What I like about Handbrake is that it is very fast in conversion, especially when encoding via H.264. This is so because Handbrake will just squeeze the life out of your CPU! It will maximize all cores of your CPU. The beauty of this is that your conversion job will finish faster than other conversion utilities that isn’t designed to take advantage of the multiple cores in your CPU. The bad news is that maximizing your CPU will increase the temperature. If you have a lot of files to convert or if you have a very large video file, having your CPU temperature so high for long periods might not be a good thing down the road depending on how you look at it. Well, my friend thinks this is a problem. You’re probably now thinking if my friend can get any more irritating! True, but my job is to advise and improvise on the spot and since he didn’t want to overwork his CPU to death, I had to come up with another solution.
A Note Before We Begin…
As I mentioned earlier, there is a good chance that you may have never heard of setting processor affinity. This is fine because you normally wouldn’t have to worry about this. Your operating system, Windows in my case here, would usually take care of allocating resources to your different applications. In fact, that is one of the main purposes of an OS. It’s a platform for you to launch your applications and programs and then helps you automatically maintain the resources to keep the application up and running. Whether its CPU, memory, network or hard disk resources, the operating system will take care of it for you. In some very special scenarios, a user can choose how an application utilize processor resources. Typically, a system administrator will usually perform this sort of customization on heavy duty servers with multiple physical processors installed. This allows them to better dedicate specific CPU processors for mission critical applications. On a typical home computer or laptop, although a CPU can be very fast, the computer is still equipped with just one physical processor. It may have anywhere from 2 to 4 or even 6 logical cores within it but its still just one physical CPU chip. What is the meaning of all this? Honest be told, not much for the average user. I am just documenting this for users who have never heard of this feature before in Windows.
Assigning processor affinity limits how many and which logical CPU cores an application can utilize. If you have multiple physical processors installed, then you can also control on which physical processor the application can utilize. Why is this important for my situation? Well, my friend’s awesome Dell laptop has a Intel Core i5 processor with four logical processors inside. When using Handbrake for video conversion, all four of the logical processors are maximized at 100%. This basically means that the physical processor itself is being worked full time for the duration of the conversion process. Because the CPU is being worked at 100% utilization until the video conversion is completed (which can take a while depending in your situation), this full workload causes the CPU temperature to rise. If you’re even remotely familiar with electronics, you will know that heat is generally the worst enemy for the innards of a computer system. As I explained this to my friend, he got really concerned. As you can see, I was in a dilemma. He needed the conversion process for a video file to be relatively fast yet he’s concerned about the heat issue. The only way to convert faster is to utilize all cores of his CPU. The higher and longer you utilize the CPU, the hotter it gets. The only solution I had was to make a slight compromise.I’m writing this blog post on my Intel dual-core CPU laptop. Therefore, I only have two logical CPU cores as opposed to four cores on my friend’s laptop. As far as the procedure goes for setting the processor affinity though, it is identical. Because his CPU is so much more powerful, our results differ.
In order to be able to compare how adjusting processor affinity can help in our situation, I need to monitor my internal CPU temperature before and after the change. There are a couple of free Windows utilities that will allow us to monitor our internal CPU temperature using different sensors. Be mindful that these utilities may not 100% accurately relay back CPU temperature information! Two such utilities include both Speedfan and Core Temp. I chose the latter.You can download Speedfan from here and Core Temp from here.
OK so first I checked what my CPU idle temperature (all temperature readings are in Celsius format) was at prior to starting this simple experiment. My CPU hovered at around the low 40 degrees. Once I got this down, I then proceeded to perform the conversion on my laptop using both CPU cores. I allowed the conversion process to run for about 7 minutes straight and then I took the temperature reading of both cores. You can see the results below. The first picture is of task manager showing that both my CPU cores were being utilized 100%. The second picture shows Core Temp with the temperature readings of both CPU cores after the 7 minutes was up.
Setting Processor Affinity
Now I’m going to set the process affinity for the Handbrake conversion process so that it can only use CPU #0. First I have to head over to Task Manager. You can easily do this by pressing the keyboard combination of Ctrl+Shift+Esc. If you are using either Windows XP or Windows 7, head over to the Processes tab. If you are using the Windows 8 Release Preview like I am doing here, you have to head over to the Details tab instead.
Next I’ll have to select the actual process to set the affinity on. In my scenario, it is the HandBrakeCLI.exe process. Right-click on the process and select the Set Affinity option.
Finally, in the Processor Affinity window, deselect the cores that you do not want the selected process to utilize. In my case, I will uncheck CPU #1.
Once I have the process configured, it was only a matter of restarting the conversion process. Below, you can see another Task Manager screenshot but this time around, you can clearly see that only one of the cores is being utilized to its maximum potential. The other core is just being idle.
After waiting for another 7 minutes or so, I took another shot of Core Temp and here are the resulting temperatures:
Having a processor run hot for long periods of time is never good. While you may not notice anything in the short term, it can slowly degrade the CPU reliability and stability over time. With advance technology at our disposal today, I’m sure this is less of an issue than before but it is still something to be concerned with. In fact, many businesses spend big bucks just to keep their servers running cool.
In the End…
I’ll repeat for the third time here that setting processor affinity for your applications is not something you need to concern yourself with! However, there are some useful cases for performing such a procedure. One that immediately comes to mind is helping an older legacy application continue to function on a multi-core processor when it was originally designed to be run on a single core system only. Setting processor affinity might be able to trick the application into thinking it is running in the ideal environment when it really isn’t.
If you find that your processor’s temperature is above what you think it should be in, then there are some things you can do. The simplest thing to do first is to just use Task Manager and see which processes are going bananas with CPU utilization. A constantly utilized CPU even though you aren’t doing anything on the system can either mean you have a lot of crapware running in the background or worst case, you have malware on your system.
A CPU gets cooled due to a combination of a heat sink and fan clamped on top of the CPU itself. The heat gets transferred to the metal heat sink while the fan on top of it cools it down. There is a special thermal compound that sits between the physical CPU and the heat sink. In rare cases, you’ll need to detach the heat sink and re-apply new thermal compound so that the heat can be better transferred. If you have high CPU temperature, you might also want to consider purchasing an after market heat sink and fan. The stock unit that comes with your computer might not be able to handle the rising temperature. Simply give Youtube a visit and you’ll find all sorts of instructional videos telling you of how to perform this procedure.