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

sunhux G sunhux at gmail.com
Tue Apr 6 06:49:51 UTC 2010


Thanks very much, Mr Simpson.


Have a few clarifications :

A)
Can I use a sub-second as the intervals, say, eg, run for 0.2 sec &
pause for 0.1 sec  so that any slowed response will not be noticeable
to users, eg, in the case of a web server.
  stutter 0.2 0.1 busy-command...
(sorry can't test out  'sleep sub-second' currently as I don't have

B)
Can the stutter script be used on a currently running pid, ie
  stutter 2 1 pid_of_a_running_process

C)
Which Shell copes the best?
Suppose a script or app is started from Bash, but I used root, switch
to say a Bourne shell ("sh") & run the stutter script, would this enable
the process to cope better?

D)
Would it cope better if the line below is replaced as follows, ie replace
  while kill -STOP "$cmdpid" 2>/dev/null
              with
  while trap "sigstop received, pausing" $SIGSTOP; kill -STOP "$cmdpid"
2>/dev/null



Thanks again
Sun

On Tue, Apr 6, 2010 at 12:33 PM, Cameron Simpson <cs at zip.com.au> wrote:

> 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
>
> --
> redhat-list mailing list
> unsubscribe mailto:redhat-list-request at redhat.com?subject=unsubscribe
> https://www.redhat.com/mailman/listinfo/redhat-list
>



More information about the redhat-list mailing list