Recently, we acquired a piece of software, which will be used to improve performance of our internal business processes. However, the development licenses covers only 2 CPU’s (or, in this case, a CPU with 2 cores), causing an issue with running the software on my Mac, as it’s a 4-core i7.
So, I needed a way to down-throttle my Mac, when running this software.
A few ways around this issue (That really don’t cut it)
First up, when this problem arose, there were a few solutions that came to mind:
taskset allows you to set cpu affinity to a single processor for a given process. Surely this would be the case in Mac OS ?
Unfortunately not. The
taskset command is not available for Mac OS. This was my first attempt at a solution, to no avail.
I’ve seen a “Processors” preference pane, allowing for deselecting processors on-the-fly
Also, no luck. The Processors preference pane existed, and was used until a couple of years ago. It was part of the CHUD (Computer Hardware Understanding Developer) tools included in Xcode. However, I’ve had no luck getting this up and running in Mountain Lion, either due to the OS, or due to the fact that my processor may not be supported.
Also, from Apple’s Developer pages, it seems CHUD hasn’t been developed for 3+ years.
So, if you’re using an older Mac running something before OS X Lion, this is a viable solution.
It should be possible to limit the amount of CPU’s in OS X’s kernel
It is. This is one of the solutions I’ve seen most times online, and it does work. Using
nvram you can force the CPU cores to be unavailable to the kernel. For more info, take a look at this artice for instance: http://reviews.cnet.com/8301-13727_7-57372761-263/boot-argument-options-in-os-x/.
However, this solution requires rebooting AND limits the system until you set the limit back to normal.
The best solution for OS X Lion (and forward)
Note: This fix requires Xcode. But since you’re interested in CPU limits, I assume you’re a developer.
First up, after installing Xcode, locate it in Finder, right-click and select “Show Package Contents”. You should now see the contents of the Xcode app., as shown below.
Here, what you want to do, is select and run
Contents -> Applications -> Instruments. Instruments is a diagnostic tool for debugging and profiling OS X apps., and provides a large number of tools for doing so. One of these, is the possibility to run tests on a limited system.
So, what we’re interested in here, is setting the number of cores available, not actually running any profiling.
Anyway, Select Instruments’ preferences (In the Instruments menu), and the following should be shown:
As you can see, in the bottom you’re able to limit the amount of active cores, as well as disable Multi-Threading (Which may also come in handy, especially for running old, old apps.).
Anyway, set the slider to whatever you need, and the change takes place immediately. In my case, I’ve set this to two cores, and the software runs perfectly. When you’re done testing, or whatever you’re limiting CPU’s for, just set the slider again, and your system is back at full force. Also, if you reboot or sleep your Mac, the CPU setting will be back to normal.