?

Log in

No account? Create an account

MultiCore, CPU, how about limiting this?

« previous entry | next entry »
Mar. 19th, 2007 | 12:40 am

Dear Lazyweb,

Anyone have an idea on how to limit the number of processors a given process can use? I have a 2 proc/4 core machine... but what I would like to do is tune up the number of processors on a given process to find thread contention issues.

Any thoughts?

Thanks!

Link | Leave a comment | Share

Comments {6}

dormando

(no subject)

from: dormando
date: Mar. 19th, 2007 08:13 am (UTC)
Link

taskset is a start... "schedutils" and/or "schedtools".

Unsure if this applies to threads at all. haven't tested that yet, just been moving around whole processes and locking them to CPUs or sets of CPUs.

Reply | Thread

Lumiere

(no subject)

from: lumiere
date: Mar. 19th, 2007 02:05 pm (UTC)
Link

What OS? Programmatically within the program? From a helper program that launches your program? Or interactively using a tool, post-launch?

Reply | Thread

Brian "Krow" Aker

(no subject)

from: krow
date: Mar. 19th, 2007 04:30 pm (UTC)
Link

I mainly work in Linux.... heh, I hadn't even thought to put in OS.

Reply | Parent | Thread

Lumiere

On Windows

from: lumiere
date: Mar. 19th, 2007 06:06 pm (UTC)
Link

To do this programmatically, use the SetProcessAffinityMask API. Use GetSystemInformation to get the available maximum affinity mask.

Now, programs designed for multiprocessors may call such APIs internally. To prevent them from doing so to increase the processors they are able to use, create the process in a Job object and limit the processors available to the Job, using SetInformationJobObject; this will overrule the process APIs. If the process creates child processes, and you want the limitation to apply to the child processes as well, then use Job objects rather than the process affinity mask directly.

Or, use the /NUMPROC flag in boot.ini, or the equivalent on Vista/"Longhorn" Server with bcdedit or msconfig, to limit the processors used by the whole OS. This is the closest you can come to seeing the true behavior on fewer processors without an appropriate hypervisor or alternative hardware.

I don't know of helper programs offhand, but one would be straightforward to write. Task Manager will allow editing a process' affinity mask interactively.

Reply | Parent | Thread

Roy Corey

(no subject)

from: xerhino
date: Mar. 19th, 2007 02:31 pm (UTC)
Link

In Solaris 10 you can create resourse pools of cpus and limit processes that way. It's part of the Container (used to be called a Zone) that lets you create virtual machines within your server. Linux can't be too far behind, but i don't know for sure.

Hmm, I just looked binding CPUs and there were some articles on processor affinity. Not sure how well it works never having used it, but:

from http://www.linuxjournal.com/article/6799

If you are not a programmer, or if you cannot modify the source for whatever reason, you still can bind processes. Listing 1 is the source code for a simple command-line utility to set the CPU affinity mask of any process, given its PID. As we discussed above, you must own the process or be root to do this.

Listing 1. bind

Usage is simple; once you learn the decimal equivalent of the CPU mask, you need:

usage: bind pid cpu_mask

As an example, assume we have a dual computer and want to bind our Quake process (with PID 1600) to processor two. We would enter the following:

bind 1600 2

Reply | Thread

Brian "Krow" Aker

(no subject)

from: krow
date: Mar. 19th, 2007 04:46 pm (UTC)
Link

Hi!

Thank you, that was exactly what I was looking for. I need to work out how to add this to MySQL long term, I suspect users would be interested in being able to do this.

Reply | Parent | Thread