1754899 Members
3971 Online
108827 Solutions
New Discussion юеВ

CPU Utilization o HPUX

 
Sai Krishna_1
Occasional Contributor

CPU Utilization o HPUX

Dear friends,
I am running an OLTP application on 4 CPU 1GHZ HPUX 11i machine.I have a query
When I do online monitoring using glance utility i can see that ps command is using around 20% of the CPU utilization. The ps command utility is used in the C code written for the application.Can anyone suggest as to how to sort out this problem(i.e tuning kernel parameters or any efficient way to enhance the code to reduce the CPU utilization for ps command.

Regards
Sai Krishna
5 REPLIES 5
B. Hulst
Trusted Contributor

Re: CPU Utilization o HPUX

Hi,

Do you need to use glance?

There is also the unix command sar to measure utilization of the system resources.

With these amount of details it is difficult to tell why it is taking 20%.

- Bob
Bill Hassell
Honored Contributor

Re: CPU Utilization o HPUX

DOes the ps command go away if you stop the C program? If not, it sounds like a runaway copy of ps. IF so, what is the command being used by the C program? ps does require a fair amount of CPU time to track down information on all the programs, and it would certainly ue a lot of time if ps is run several times per second. If the ps program is being run with the -H option, this will definitely require a lot of time in a busy system.


Bill Hassell, sysadmin
Steven E. Protter
Exalted Contributor

Re: CPU Utilization o HPUX

Might want to kill that ps process and take a look at your code to see if its not causing the problem.

Please post the options being used by the ps command from your code. Consider changing the options to something less CPU intensive.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Sai Krishna_1
Occasional Contributor

Re: CPU Utilization o HPUX

Dear Friends,
I will tell you what exactly happens
In the C program this shell command is invoked
sh -c ps -p 22364 |grep um.scs 2>&1 >/dev/null
um.scs is the application whic runs in the background.This forks around 250 ps processes if I observe through glance. It also invokes lot of sh commands. Both of these amounts to 20%-25% of the CPU.Through glance i have set the parm file where
application = PS
file = ps

Friends, I do not know whether so much information is enough. But this is a major bottleneck in our application. Please do suggest a good approach whether i can use any other option in the code or any way to optimize the kernel parameters to reduce the CPU utilization.Please treat this as urgent.
Regards
Sai.

Bill Hassell
Honored Contributor

Re: CPU Utilization o HPUX

250 copies of ps? This application is in serious need of a redesign! First off, the ps command has -p -p 22364 which is a specific process number. One and onlt one process will every have this number and when the process terminates, it will be unused until enough new processes are created to reuse this PID. Therefore, the grep is totally useless (as it is under most circumstances). If ps is supposed to locate a process called um.scs, this is completely the wrong way to do this. Note that the redirection: 2>&1 > /dev/null is incorrect. stderr (the 2>) is redirected to the current file descriptor for stdout and then stdout is changed to /dev/null. stderr will NOT be changed to /dev/null--it remains with the original file handle. And finally, all the information from ps is being thrwon away so it looks like goal is to monitor um.scs by looking at the return code for ps.

So the questions are: why is the code running so many copies of ps? Does the code blindly run ps over and over as fast as it can? (bad programming) Is this code monitoring a process that is supposed to be running but crashes and needs a restart? If so, the correct solution is to fix the broken process, not keep trying to kickstart the um.scs over and over again.

Assuming that there is no way to fix the broken process, change the C code to use the following syntax:

sh -c UNIX95= ps -C um.scs > /dev/null 2>&1

What this will do is to eliminate grep (ALWAYS a good thing with ps), return all processes with the name um.scs (and NOT um.scs.1 or bum.scs, etc which is what grep would do), then change stdout to /dev/null, and finally redirect stderr to the current filehandle for stdout which is now /dev/null. Finally, this ps command should be run every 5 or 10 seconds and should complete within a few hundred milliseconds. But don't test this in the program until you test it manually from the command line. Start by running just the command without the redirection (and check the return code), as in:

UNIX95= ps -C um.sc
echo $?

After each run, the echo $? will be 0 for success in finding at least one match for um.scs, non-zero (typically 1) if the program cannot is not running.


Bill Hassell, sysadmin