1992.12.22
SUBJECT: CPU Performance Tuning & Accounting
STATUS OF THIS MEMO:
System Performance Tuning과 관련하여 CPU Performance의 측정과 시스템 Resource의
usage를 Accounting하기 위한 utility를 정리한 것임
CONTENTS:
1. CPU Performance
2. Cron Facility
3. Accounting
1) BSD Accounting Utilities
2) /usr/etc/sa
3) 관련 FILE
4) A Script to Collect Accounting Data
5) Day-to-Day Management
6) Accounting Reports & Management
DESCRIPTION:
1. CPU Performance
% /bin/tmie application
0.0u 0.1s 0:09 1% 0+256k 4+0io 4pf+0w
- u : User state CPU time ( user 상태에서 사용자의 application을 실행
하는데 소요된 시간, 초단위 계산)
- s : System state CPU time (system상태, 즉 kernel code의 실행에서
소요된 CPU time)
% uptmie
- last 1분, 5분, 15분간의 system load average를 report
- System V의 sar -q와 유사
12:24am up 2 hrs, 1 user, load average: 1.34, 2.28, 2.51
- 15분간의 load average보다 1분간의 load average가 작은것을 falling이라고
하며, 만약 system이 느리지만 load average가 falling이면 시간이 지남에
따라 problem이 해결되는지를 확인하는것이 좋다
% ps -au
USER PID %CPU %MEM SZ RSS TT STAT START TIME COMMAND
hjh 327 0.0 2.0 456 896 p0 R 10:31 0:00 ps -au
hjh 306 0.0 0.8 152 336 p0 S 10:24 0:00 -csh (csh)
- USER : The user who started the process
- PID : The process ID number assigned by the system
- %CPU : The percentage of the CPU time used by this process
- %MEM : ,, system's physical memory used by
this process
- SZ : The amount of nonshered virtual memory, in KByte
- RSS : Real memory (resident set) size of the process (in kilobytes)
- TT : tty name
- STAT : process's status
. R : runnable
. T : currently stopped
. P : waiting for a page-in
. D : ,, disk I/O
. S : sleeping for less than 20 seconds
. I : idle (sleeping for more then 20 seconds)
. Z : terminated but has not died
- TIME : The total amount of CPU time that the program has consumed
% iostat 3 (= vmstat)
- provides a measure of the CPU's idle time
- System V의 sar -u 와 유사
tty sd3 cpu
tin tout bps tps msps us ni sy id
0 11 8 1 0.0 1 0 1 98
0 18 0 0 0.0 6 0 1 92
0 18 0 0 0.0 2 0 1 96
0 18 0 0 0.0 3 0 0 97
0 18 0 0 0.0 2 0 1 96
- us : user 상태에서 running하는 process들에 의해 사용된 CPU %
( default scheduling priority 이상)
- ni : user 상태에서 running하는 process들에 의해 사용된 CPU %
( low scheduling priority )
- sy : system상태에서 사용된 CPU %
(executing system calls, UNIX kernel code, scheduling onerhead등)
- id : percentage of the system spent idle
* 참조
"vmstat -S"를 사용 check시 CPU의 idle time이 50%선이면 안정
2. Cron Facility
- edit the crontab file
minute hour dayofmonth month dayofweek username command
- /var/spool/cron/crontabs directory에 user name으로 crintab file이
존재할 경우 username은 *으로 대체
- *는 wildcard임
- 예) vi /var/spool/cron/crontabs/root
###############################
#Min Hour Day Month Day Command
###############################
15 4 * * * find /var/preserve/ -mtime +7 -a -exec rm -f {} \;
0 23 * * * sh `sed -n 1p /etc/Alis`/janitor
0 * * * * /usr/lib/acct/ckpacct
10 12 * * 1-6 /usr/lib/acct/dodisk
20 12 1 * * /usr/lib/acct/monacct
30 12 * * 1-6 /usr/lib/acct/runacct 2> /var/adm/acct/nite/fd2log
% crontab -l root : Display the current crontab file for root
% crontab -e root : To edit crontab file for root
3. Accounting
1) BSD Accounting Utilities
- accounting system은 account command를 enable함으로서 가능하며
/etc/rc file에 다음을 comment out
/usr/lib/acct/accton /usr/adm/acct OR
/usr/lib/acct/startup
- /usr/acct가 있는 filesystem이 95%이하이면 accounting을 하고
95%가 넘으면 자동적으로 accounting을 stop 한다
- SunOS에서는 kernel에서 SYSACCT configuration option이 포함되어
있어야 한다
- sa command로 report할수 있으며 sa -s 로 /usr/adm/acct의 내용을
compress하고 savacct file로 merge시킨다
2) /usr/etc/sa
% sa
1027 18063.15re 17.11cp 4078avio 4696k
16 1537.32re 6.22cp 1057avio 6258k cmdtool
14 12.79re 3.14cp 265300avio 6377k cp
7 17.18re 1.47cp 618avio 5902k suntetri
51 5.47re 0.69cp 1avio 4373k rm
6 481.65re 0.63cp 0avio 586k update*
37 99.61re 0.56cp 276avio 3443k vi
- leftmost : Total number of times the command was execute
- re : Total real time spent excuting the command
- cp : Total CPU time ,, ,, ,,
- avio : Average number of I/O operations per invocation of the command
- k : Average physical memory usage, in Kbytes
3) 관련 FILE
- /var/adm/pacct raw accounting
- /var/adm/savacct summary by command
- /var/adm/usracct summary by user ID
4) A Script to Collect Accounting Data
#!/bin/sh
filename=`date | awk '{print $2 $3 $6}' -`
sa=/usr/etc/sa
recorddir=/usr/adm/localacct
if [ ! -d $recorddir ]
then
mkdir $recorddir
fi
pathname=$recorddir/$filename
date > $pathname
echo "Day's Activity (command summary)" >> $pathname
$sa -i >> $pathname
echo "Total activity (command summary)" >> $pathname
$sa >> $pathname
# this time, also compress reports into savacct
echo "Per-user activity" >> $pathname
$sa -ms >> $pathname
5) Day-to-Day Management
- /usr/lib/acct/runacct
Generates a set of five daily reports
/usr/adm/acct/sum directory내에 rprtmmdd형의 file로 보관되며
mm은 월, dd는 일을 나타냄
- /usr/lib/acct/dodisk
Gathers disk usage statistics, which are summarized by runacct
- /usr/lib/acct/ckpacct
시스템에 free block이 500이하일 경우 main accounting file
(/usr/adm/acct/pacct)이 계속 증가못하게 함
- /usr/lib/acct/monacct
Convert all daily reports into a monthly report
/usr/adm/acct/fiscal directory내에 fiscrptnn의 file name으로 저장
- /usr/lib/acct/prdaily
Get the accounting statistics for the current date and repoprt
- /usr/lib/acct/shutacct
To disable accounting cleanly, execute the shell script ~/shutacct
6) Accounting Reports & Management
- login name별, application별 Accounting과 last login을 report
% /usr/lib/acct/prdaily mmdd (예, 0908)
- CPU(MINS) : total cpu time
- KCORE-MINS : 분당 사용되는 physical memory
- CONNECT : The total amount of time the user was logged in
- DISK BLOCKS: ,, ,, disk storage that the user is occupying
- #OF PROC : ,, ,, processes the user executed
- #OF SESS : The number of times the user logged in during the day
- NUMBER CMDS : report된 기간동안 수행된 횟수
- TOTAL KCOREMIN : 이 program에 의해 사용된 physical memory(KByte)
- TOTAL CPU : 이 program에 의해 사용된 total cpu time
- TOTAL REAL : 이 program이 invoke된후 경과된 시간의 합
- MEAN SIZE : 이 program에 의해 사용된 평균 memory의 량
- MEAN CPU : 이 program이 실행하는데 소요된 평균CPU time(분)
- HOG FACTOR : program의 CPU효율로 total CPU time을 total 수행시간
(TOTAL REAL)으로 나눈 값
- CHARS TRANSFD : 이 program에 의해 transfer된 total character 수
- BLOCKS READ : 이 command에 의해 read/write된 disk blocks
# generate daily accounting reports (1 a.m)
0 1 * * * /usr/lib/acct/runacct
# update disk usage statistics weekly (2 a.m. Monday)
0 2 * * 1 /usr/lib/acct/dodisk
# manage accounting file size hourly (on the half-hour)
30 * * * * /usr/lib/acct/ckpacct
# generate monthly summaries (2 a.m. on the 1st of the month)
0 2 1 * * /usr/lib/acct/monacct
Revision History
Created on Dec 22 ,1992