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