On-the-fly throttle of CPU consumption of a process

Cameron Simpson cs at zip.com.au
Tue Apr 6 04:33:08 UTC 2010


On 06Apr2010 11:30, sunhux G <sunhux at gmail.com> wrote:
| Q1:
| When a running process hogs a CPU, I would like to be able to reduce its %
| CPU
| consumption, say to 50%.  Is there a command to do this or this is possible
| in
| Redhat (& CentOS & HP-UX if anyone knows) ?

I'm not sure about constraining its CPU use "evenly", but you can
SIGSTOP/SIGCONT it from outside - ceasing execution and then resuming
later. I wrote a script called stutter for this purpose:

  http://www.cskk.ezoshosting.com/cs/css/bin/stutter

which you might invoke thus:

  stutter 10 10 busy-command...

to run for 10 seconds, sleep 10 seconds and so forth.

Of course that presumes you're prepared for this in advance.
But a:

  kill -STOP pid-of-busy-process        # pause execution
  kill -CONT pid-of-busy-process        # continue execution

can be done to an existing process from outside. Note that some shells
(I think even bash, regrettably) don't cope well if you do this to
their children, which has caused me a little trouble with the stutter
script above. They should recognise "stopped from SIGSTOP" as a "quietly
ignore" event, but they sometimes don't.

This is all very crude, too. There may be other OS tuning facilities
similar to the "nice" facility for getting what you ask.

| Q2:
| One thought : can a running app (eg Websphere, Weblogic, Tomcat, Oracle
| instances)
| be set such that it uses only a specific processor in a multiple processor
| environment :

The term you're looking for is "processor affinity". I believe it can be
done but don't know what you need to do to effect it, nor whether it can
be done to a process from outside.

| the averaged value of all the processors can then show a lower average CPU
| utilization.
| The other lower CPU hungry process can be shifted to one processor and those
| savage ones restricted to 1 or 2 processors : I'm not sure if this manual
| reshuffling
| is more efficient that letting the system manages it on its own but just
| soliciting views.

It will probably be less efficient except in unusual circumstances, though
some things benefit from using processor affinity to avoid moving the
CPU state to the other CPUs, which can be costly if the process context
switches a lot and thus ends up on several processors successively in
a short space of time due to naive OS job scheduling.

Processor affinity definitely has benefits in particular circumstances;
you'll have to see if it helps you (even if only to fiddle the
accounting/warning numbers:-)

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Sometimes you just need to look reality in the eye, and deny it.
        - Garrison Keillor




More information about the redhat-list mailing list