Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1086258
  • 博文数量: 143
  • 博客积分: 969
  • 博客等级: 准尉
  • 技术积分: 1765
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-30 12:09
文章分类

全部博文(143)

文章存档

2023年(4)

2021年(2)

2020年(4)

2019年(4)

2018年(33)

2017年(6)

2016年(13)

2014年(7)

2013年(23)

2012年(33)

2011年(14)

我的朋友

分类: LINUX

2013-09-13 10:57:43

HP-UX性能分析

1.性能分析准则

1.1系统性能管理

要对系统进行性能分析和调试,其前提条件是知道好的性能是什么含义,一般我们可以从以下两个角度来衡量系统性能状态:

1)响应时间(Response Time)

从用户的角度来看,系统处于良好的性能状态是指系统能够快速响应用户的请求,即系统响应时间短。 具体地说,响应时间是指发出请求的时刻到用户的请求的相应结果返回用户的时间间隔。

2)吞吐量(Throughput)

系统的吞吐量是系统处于良好的性能状态的指标。 具体地说,吞吐量是在给定时间段内系统完成的交易数量。即系统的吞吐量越大,说明系统在单位时间内完成的用户或系统请求越多, 系统的资源得到充分利用。

1.2资源与瓶颈

要使系统处于良好性能状态,就必须让所有的系统资源协调工作。

1)      系统资源(System Resource)

计算机组成十分复杂,但关键的系统资源不外如下这些:

CPU      

内存

磁盘

输入输出,尤其是网络和串行通信

 

2)      瓶颈(Bottleneck)

在计算机的众多资源中,由于系统配置的原因,某种资源成为系统性能的瓶颈是很自然的事情。当所有用户或系统请求对某种资源的需求超过它的可用数量范围时,我们称这种资源成为瓶颈。

 

当系统出现瓶颈时,消除瓶颈是方法通常有两种:

增加成为瓶颈的资源的数量;

减少请求的数量;

1.3影响系统性能的因素

应该说,影响系统性能的因素很多,但归纳起来主要有以下几个因素:

 

硬件因素:CPU个数够不够?内存够不够?等等

操作系统:操作系统的配置是否合理?

应用软件:应用系统设计得如何;

人的因素:操作人员是否有充分的培训,以完全懂得操作系统?

经常性的变化因素:用户的需求是否经常性变化?用户对系统负载的要求是否经常性变化?

1.4系统性能调试的一般原则

对系统进行性能调试必须遵循一定的原则。

 

性能调试是一件严肃的事情,不要对系统的各种参数进行随意的改动;

一次只对某个领域进行性能调试,例如对CPU的使用情况进行分析;

每次只改动一个设置;

每次对系统性能进行分析时,至少使用两种性能分析和调试工具;

经验是最好的分析和调试工具;

知道什么情况下该停止操作;

 

一般地,我们有以下四条性能调试的规则:

 

1)当你回答一个关于计算机系统性能的问题时,最初的回答总是可能吧,视具体情况而定(It depends)”。 当然这个回答不会让用户满意的,因此,我们必须进一步可能对系统性能产生影响的各种因素进行分析,它们所有作用是什么,起多大的作用。

 

2)性能分析和调试总是存在着折衷。当系统管理员试图对计算机系统的性能进行调整时,w我们可能需要修改系统参数,或修改应用。然而,性能调试不存在唯一回答或最优答案。

比如:tuning to improve memory utilization may degrade file system performance;Choosing RAID disk comfigurations for data integrity may be less expersive than altternative mirroring solutions that often improve performance.It is may be more cost-effective to purchase a CPU upgrade rather than spend days or weeks analyzing how the application could be changed to improve performance.

 

3)在分析系统性能的同时,系统性能将会受到影响。由于在进行系统性能分析时,性能分析工具本身将会占用一定的系统资源,如CPU资源、内存资源等等。我们必须注意到这点, 即分析工具本身运行可能会导致系统某方面的资源瓶颈情况更加严重。

 

4)只用一种工具是无法全面、正确地分析出系统的资源瓶颈所在。

 

2.性能分析工具   

2.1  性能分析工具综述

目前,对系统进行性能调试的工具有很多,这些可以两大类:一类是标准的分析工具,即所有的UNIX都会带的分析工具; 另一类是不同厂商的UNIX所特有的性能分析工具,比如HP-UX就有自己的增值性能分析工具。

 

标准的分析工具,即所有的UNIX都会带的分析工具:

sar

iostat

vmstat

time

ps

bdf

top

ipcs

uptime

 

HP-UX自己的增值性能分析工具:

glance/gpm

puma

xps

 

按性能分析工具的用途来说,它可以分为:

CPU的使用情况:sar,time,top,ps,puma,xps

内存的使用情况:vmstat,ipcs

文件系统状态:dbf,iostat,sar,swapinfo,nfsstat

I/O子系统状态:iostat

网络性能:netstat

 

按分析时间点来分,性能分析工具可以分为:

日志型分析工具,如puma,xps,它们将在对系统在某一段时间的运行情况进行取样,然后得出某此结果。这种分析工具非常适合于针对那些时断时续发生的问题进行分析,因为通过取样,可以得出结论;

实时型分析工具,如glance,它们又称快照型分析工具,即它们将实时取出系统运行环境的数据,这种分析工具非常适合于那些在分析工具正在运行时发生的问题,或一直发生的问题。

2.2  如何知道系统安装了哪些性能分析工具

想知道系统中安装了何种性能分析工具,运行命令:

 

#/opt/perf/perfstat -v

2.3  sar

SAR-System Activity Reporter

 

顾名思义,SAR工具将对系统的当前状态进行取样,然后通过计算数据和比例来表达系统的当前运行状态。它的特点是:

System V-based,在很多的UNIX版本中都存在;

可以连续对系统取样,获得大量的取样数据;

取样数据和分析的结果都可以入文件;

自己所需的负载很小

SAR也有一个致命的不足,这就是:SAR不能对某个进程进行深入分析,它仅是一对系统的整体情况进行分析。

 

SAR的语法为:

#sar [-ubdycwaqvmAMS] [-o file] t [n]

每隔t秒取样一次,共取样n次,其中-o file表示取样结果将以二进制形式存入文件file中;

 

#sar [-ubdycwaqvmAMS] [-s time] [-e time] [-i sec] [-f file]

表示从file文件中取出数据,如果没有指定-f file,则从标准数据文件/var/adm/sa/sadd取数据,其中dd表示当前日子。

 -s time表示起始时间;

 -e time表示停止时间;

 -i sec表示取样的时间间隔,如果不指定则表示取文件中所有的数据。

[-ubdycwaqvmAMS]的解释请参阅相关的系统分析领域,如

-u表示对CPU的分析;

-A表示汇总所有数据,即等于-ubdycwaqvm,

-M表示对多个CPU环境中每个CPU都进行各自的分析, 一般它与-q和-u联合使用,以对每个CPU的使用情况进行分析

 

从前面的命令语法中可知,sar可以从一个文件中读取性能数据,这个文件可以通过sar来产生(sar -o file 2 3),也可以通过其他的命令来产生,具体地说,可以通过以下几个命令来产生:

 

#/usr/lbin/sa/sadc [t n] [ofile]:以t秒为时间间隔,共取样n次,所有数据存入文件ofile

如果我们要对系统进行分析,则通常的做法是:

第一步,mkdir /var/adm/sa

第二步,chown adm:adm /var/adm/sa

第三步,/usr/lbin/sa/sadc /var/adm/sa/sa`date +%d`,它会在/var/adm/sa目录下创建一个sadd文件,其中dd表示当前日期,这个命令将对以前取样进行清零。

运行shell命令:#/usr/lbin/sa/sa1 [t n]:表示以t秒为时间间隔,共取样n次,所有数据存入文件/var/adm/sa目录下的sadd文件,其中dd表示当前日期;

运行shell命令:#/usr/lbin/sa/sa2 [-ubdycwaqvmA] [-s time] [-e time] [i sec]

一个通过crontab命令来设置定时执行的方案:

 

0 * * * 0,6 su adm -c "/usr/lbin/sa/sa1":表示以adm用户执行sa1,每个星期的日、六两天是每小时执行一次sa1命令;

 

0 8-17 * * 1-5 su adm -c "/usr/lbin/sa/sa1 3 3"

 

0 8-17 * * 1-5 su adm -c "/usr/lbin/sa/sa1"

 

 

在通过sadcsa1sa2等后台命令收集数据时,我们必须注意如下两点:

 

/usr文件系统的空闲空间够不够

本月数据将覆盖上月所取样的数据,因此,在系统即将进入下一个月时,必须对本月数据进行备份;

sa1sa2是两个shell命令,在目录/usr/lbin/sa下,我们可以修改这两shell文件,以改变缺省的取样方法。

2.4  timetimex

TIME

 

Time命令可以汇报出执行某条命令所花的时间。它的输出包括:实际时间,用户时间和系统时间。

 

它的语法:#time ls

 

TIMEX

 

time一样,timex可以汇报出执行某条命令所花的时间,不过它可以给出更多的信息。

 

选项-s:prints sar data for the interval in which the program ran.

 

option -p: List process accounting records for command and all its children.This option works only if the process accounting software is installed and /usr/lib/acct/turnacct has been invoked to create /var/adm/pacct

 

iostat-I/O statistics Reporter

2.5  iostat

iostat(输入/输出统计)工具将对系统的磁盘操作活动进行监视,它的输出结果会比sar -d的输出结果更有用。它的特点是:

Berkeley-based,在很多的UNIX版本中都存在;

汇报磁盘活动统计情况,同时也会汇报出终端和CPU使用情况;

looks at information on a per-spindle basis

SAR一样,它也有一个致命的不足,这就是:iostat不能对某个进程进行深入分析,它仅是一对系统的整体情况进行分析。

 

iostat的语法为:

iostat [-t] [interval [count]]

interval: Display successive lines which are summaries of the last interval seconds. The first line reported is for the time since a reboot and each subsequent line is for the last interval only.

count: Repeat the statistics count times.

-t: Report terminal statistics as well as disk statistics.

2.6  Vmstat

vmstat-Virtual Meomory Statistics

        

vmstat工具将对系统的虚拟内存、进程、CPU活动进行监视,同时它也对磁盘和forksvforks操作的个数进行汇总。它的特点是:

Berkeley-based,在很多的UNIX版本中都存在;

汇报虚拟内存、进程、CPU活动统计情况,同时也会汇报出磁盘活动情况和forksvforks操作的个数;

iostat一样,它也有一个致命的不足,这就是:vmstat不能对某个进程进行深入分析,它仅是一对系统的整体情况进行分析。

 

vmstat的语法为:

vmstat [-dnS] [interval [count]]

vmstat -f | -s | -z

2.7  GlancePlus

GlancePlusHP公司的性能分析工具,它是一个联机性能分析和诊断工具,用于监控正在发生的系统活动情况。它的特点是:

联机性能分析和诊断;

监控系统资源的使用情况;

多屏幕输出;

带有联机帮助;

进程阀值识别和报警,这个阀值可以基于被监控的进程、资源的利用率、用户、进程名或者终端名;

和前面介绍的其他性能分析工具,如:SARiostatvmstat等相比,GlancePlus有一最大好处,这就是:GlancePlus不仅能对系统的整体情况进行分析,而且还可以对某个进程进行深入分析。

 

GlancePlus所有监控的系统资源主要有以下这些,应该说,它们已经包括了主要的系统资源。

CPU、磁盘、内存和交换区的整体使用情况;

全局进程的活动情况;

CPU的详细使用情况;

内存的详细使用情况;

文件系统、设备和逻辑卷的磁盘输入/输出;

磁盘队列和长度;

交换区的详细使用情况;

系统表的使用情况;

单个进程的活动情况;

 

GlancePlus的运行形式有两种:

 

?  图形方式:

#/opt/perf/bin/gpm,或以后台方式运行#gpm&;不过,我们必须先设置环境变量DISPLAY,因为它是图形输出的目的地,比如:export DISPLAY=主机名(IP地址):0.0;如果是工作站telnet别的主机上,则本工作站还要运行#xhost +,表示别的机器上输出可以到本工作站;

?  终端方式:

#/opt/perf/bin/glance

GlancePlus的界面主要有两部分,上面部分是系统资源的整体使用情况,下面部分则按不同的资源的详细使用情况。

GlancePlus的界面的上面部分的详细说明,其中字母表示谁用了资源,而字母之间的长度资源占用率。

a)   CPU的利用率

S-系统CPU利用率;

U-用户CPU利用率;

R-实时CPU利用率;

Nnice CPU利用率;

Anegative-nice CPU利用率;

b)   磁盘的利用率

F-文件系统I/O

V-虚拟内存I/O

c)   内存的利用率

S-用于系统代码和数据的内存;

U-用于用户代码和数据的内存;

B-用作缓存的内存;

 

d)   交换区的利用率

U-正在使用的交换区;

R-预留的交换区;

 

前面讲到,GlancePlus是一个联机分析诊断工具,其实,GlancePlus还可以与MeasureWare Agent一起使用,MeasureWare Agent将可以在一段时间内帮助GlancePlus收集基本数据,然后由GlancePlus进行分析。

 

Glance可以运行在HP-UXSolarisAIX上。

与其他的工具相比,Glance占用的系统资源会更多一些。

 

通常情况下,启动工具的命令的语法如下:

 

#glance [-j interval][-p dest][-f dest][maxpagers n][-command][-nice n][-nosort][lock][]

 

其中,各选项的含义为:

 

-j :指定数据刷新的时间间隔;

-p :使得结果送到打印机队列;

-f :enbles printing to a file;

-maxpages :limits the number of pages to be printed;

-command:selects the inital metric screen;

-nice :nice value at which glance runs;

-nosort:don't sort processes on the screen;

-lock:locks glance into memory

3.CPU性能分析

CPU的体系结构和工作原理

         我们所说的CPU一般是指微处理器,即Microprocessor,一般地,一个CPU的主要组成部分为:

CPU(central processing unit) cache

         cache就是高速内存,它的存取时间一般是10-20微秒(ns),这样,CPU可以在一个时钟周期内访问一次cache;而一般的内存的存取时间为80-90微秒(ns),它的大小对CPU的性能有很大的影响。

TLB(translation lookaside boffer)

        TLB是高速cache,它用于存放最近访问的虚拟地址和与其对应的物理地址对,这样TLB将可以把虚拟地址转换为物理地址。TLB是内存中系统转换表的一个子集;TLB通常是指向一个内存页面,而不是一个内存地址;它的大小对CPU的性能有很大的影响。

Coprocessor(协助处理器)

         不同的CPU,一般有不同的时钟频率和高速缓存容量。

 

    CPU在一次时钟周期内一般可以从高速缓存内取到一个指令并执行它。因此,从理论上说,只要CPU的主频越快,单位时间内所能执行的指令则越多。目前,有些CPU可以在一个时钟周期内执行多条指令,如PA8500可以执行4条指令。

    高速缓存的大小会制约CPU的执行效率,虽然CPU主频很快,但它取不到数据,则只有空运行。因此,高速缓存的大小很重要;高速缓存又分数据高速缓存和指令高速缓存,分别存放从内存预先取来的即将执行的数据和指令单元。

虚拟寻址

    一般,系统中的虚拟地址空间要比物理地址空间大得多,例如,如果系统是64位的,则理论上,它的寻址空间可以达到264次幂(2**64=18,447PB),但由于受费用的因素的影响,实际上的物理内存最大只有十几GB的内存。

 

    每个进程都有自己的唯一虚拟地址空间,然而,进程的运行必须把虚拟地址映射到物理地址,这需要TLB、高速缓存和内存三者的配合。如果需要的信息不在内存,则导致一个页面错。

流水线(Pipelining)

    TLB和高速缓存试图在一个时钟周期内给CPU提供它所需的信息,然而,这个过程是100%的利用率,对CPU来说,它必须先用一个时钟周期去取下一个指令,再一个时钟周期去执行这条指令,这样,CPU的利用率也只有50%。为了让CPU更忙,通常的做法是,采用流水线的方法。如PA8500是采用7个步骤的流水线。

操作系统和进程

HP-UX一个多用户、多任务的UNIX操作系统。它的性能依赖于用户数的多少、用户任务的类型、硬/软件件的配置。

 

HPUX有两种运行级别:

?  用户级:

         系统用户可以与操作系统进行交互操作,如运行应用和系统命令。用户级通过系统调用接口访问内核级。

?  内核级:

         操作系统自动运行一些功能,它们主要对硬件进行操作。

 

在操作系统中,用户程序是以进程方式运行。进程的状态有以下几种:

SRUN

SSLEEP

SZOMB

SIDL

SSTOP

 

CPU的调度

         一旦进程所需的数据调入内存后,它将等待CPU调度者来分配CPU时间。一般,在HP-UX中,每个进程都可以得一个固定的时间片来运行,这个时间片的长度为十分之一秒(1/10)

    由于HP-UX是一个多任务的操作系统,它需要一种手段来进程的执行次序,这就是中断。在系统中,时钟中断处理器是用来处理时钟中断的系统软件。具体地说,它将收集系统和accounting statistics and does context switching.系统性能也与这种中断发生的频率有关。

 

进程何优先级

每个进程都有自己的优先级;

实时优先级:-32~127,一个进程如果想以实时优先级运行,则必须用命令#rtprio来设置;

分时系统优先级:128177

分时用户优先级:178251

优先级:252255 are used by the system as virtual memory management priorities for process deactivation.

分时进程在初始优先级是由系统分配的,为一个定值。用户可以通过改变进程的nice值来改变分时进程的优先级。因为进程会随着它的执行,将以nice值来降低它的优先级,当它在等待执行时,又将以nice值来增加其优先级。nice值的系统缺值为20

在系统性能分析过程中,我关心不仅仅在完成一个进程耗时多少,还包括时间花在哪以及它的时间多少。

 

衡量CPU闲忙程度的指标

要分析系统的CPU资源是否够的前提谁占用了CPU资源,占用了多少,时间多长。

下面是一些衡量CPU闲忙程度的经用指标:

 

1)用户使用CPU的情况

CPU运行常规用户进程

CPU运行niced process

CPU运行实时进程

 

2)系统使用CPU的情况

用于系统调用

用于I/O管理:中断和驱动

用于内存管理:paging and swapping

用于进程管理:context switch and process start

 

3)WIO:由于进程等待I/O而使CPU处于空闲状态的比率,这些I/O主要指block I/O,raw I/O,VM paging/swapins

 

4)CPU的空闲率,即除了上面的WIO以外的空闲情况;

 

5)CPU用于上下文交换的比率(Context Switch CPU utilization)

 

6)nice 进程运行的优先级

 

7)real-time

 

运行进程队列的长度,即处于可运行状态的进程个数的大小,不过我们关心的是这些在等待CPU调度执行时所花的时间;

 

9)平均负载(load average)

 

CPU资源成为系统性能的瓶颈的征兆

 

CPU就像人的大脑,完成各种交给它的任务。如果任务太多,CPU就要忙不过来,它的运行效率就要下降。就像人生病会有一典型症状一样,当CPU资源 成为系统性能的瓶颈时,它也有一些典型的症状:

 

很慢的响应时间(slow response time)

CPU空闲时间为零(zero percent idle CPU)

过高的用户占用CPU时间(high percent user CPU)

过高的系统占用CPU时间(high percent system CPU)

长时间的有很长的运行进程队列(large run queue size sustained over time)

processes blocked on prority

 

必须注意的是,如果系统出现上面的这些症状并不能说一定是由于CPU资源不够,事实,有些症状的出现很可能是由于其他资源的不足而引起,如内存不够时,CPU会忙内存管理的事,这时从表面上, CPU的利用是100%,甚至显得不够,如果据此就简单地认为增加CPU就可以解决问题是大错特错了。

 

因此,还是那句话,必须用不同的工具、从不同的方面对系统进行分析后,才能做出结论,即使这样,经验将起到不可替代的作用。

 

哪些进程是占用CPU资源的大户

    在操作系统中,并不是所有的进程都以同样的方式使用CPU资源。通常情况下,有些进程需要比其他进程更多的CPU时间片才能顺利地完成任务。下面是一些典型的占用CPU资源的大户:

 

进程创建(process creation)

终端字符进程(teminal character processes(MUX- and LAN-based)

计算密集型进程和实时进程

X-终端和X-服务器进程(X-terminals and X-servers)

 

利用SAR -u分析CPU的利用率

利用SAR进行CPU的利用率分析的命令形式:

 

#sar -u,这时数据是通过sa1在后台定时生成;

#sar -u 5 100,每隔5秒取样一次,共取100次;

SAR -u:Report CPU utilization (the default); portion of time running in one of several modes. On a multi-processor system, if the -M option is used together with the -u option, per-CPU utilization as well as the average CPU utilization of all the processors are reported. If the -M option is not used, only the average CPU utilization of all the processors is reported:

 

cpu: cpu number (only on a multi-processor system with the -M option);

%usr: user mode;

%sys: system mode;

%wio: idle with some process waiting for I/O (only block I/O, raw I/O, or VM pageins/swapins indicated);

%idle: otherwise idle;

对结果的分析

首先,我们看%idle列的值,如果为接近零,则再看对应%wio列的值,如果这列的大于7,则表明系统的磁盘或其他I/O可能有问题,需要进一步的分析:

 

用iostat命令分析各个磁盘的传输闲忙状况,如#iostat -t 5 2,每隔5秒取样一次,共取2次;

用sar -d命令分析各块设备(磁盘、磁带)活动情况;

用sar -b命令分析系统的缓存的活动情况;

用sar -w命令分析进程的deactivation/reactivation and switching activities of the system;

如果%idle列很小,而对应的%wio列的值也很小,这时,我们查看%usr列和%sys列的值。如果%usr列的值很大,说明有用户进程占用很多CPU时间;如果%sys列的值很大,则说明系统管理方面花了很多时间。需要进一步的分析:

如果%sys列的值很大,可以用SAR -C命令对系统调用进行进一步分解,看这些系统调用主要是做些什么。同时,还必须分析是否有其他瓶颈,如paging也会引起%sys的值很大,这时,可以用sar -q查看系统的运行进程队列长度,也可以用GlancePlus和vmstat查看内存的使用情况;

 

利用SAR -q分析运行进程队列长度

利用SAR进行运行进程队列长度分析的命令形式:

 

#sar -q,这时数据是通过sa1在后台定时生成;

#sar -q 5 100,每隔5秒取样一次,共取100次;

SAR -q: Report average queue length while occupied, and percent of time occupied. On a multi-processor machine, if the -M option is used together with the -q option, the per-CPU run queue as well as the average run queue of all the processors are reported. If the -M option is not used, only the average run queue information of all the processors is reported:

 

cpu: cpu number (only on a multi-processor system with the -M option);

runq-sz: Average length of the run queue(s) of processes (in memory and runnable);

%runocc: The percentage of time the run queue(s) were occupied by processes (in memory and runnable);

swpq-sz: Average length of the swap queue of runnable processes (processes swapped out but ready to run);

%swpocc: The percentage of time the swap queue of runnable processes (processes swapped out but ready to run) was occupied.

对结果的分析:

 

这些数据越小越好。

 

如果runq-sz大于4,或者%swapocc大于5时,则表明系统的CPU或内存可能有问题,需要进一步的分析:

 

用sar -u命令分析CPU的使用情况;

用sar -w命令分析进程的deactivation/reactivation and switching activities of the system;

也可以用GlancePlus;

 

利用SAR -c 分析系统调用

 

利用SAR进行系统调用分析的命令形式:

 

#sar -c,这时数据是通过sa1在后台定时生成;

#sar -c 5 100,每隔5秒取样一次,共取100次;

SAR -c: Report system calls:

 

scall/s: Number of system calls of all types per second;

sread/s: Number of read() and/or readv() system calls per second;

swrit/s: Number of write() and/or writev() system calls per second;

swpq-sz: Average length of the swap queue of runnable processes (processes swapped out but ready to run);

fork/s: Number of fork() and/or vfork() system calls per second;

exec/s: Number of exec() system calls per second;

rchar/s: Number of characters transferred by read system calls block devices only) per second;

wchar/s: Number of characters transferred by write system calls (block devices only) per second.

对结果的分析:

 

如果scall/s列的值很大,那么这么多的系统调用的原因就必须仔细分析了。

 

我们可以查看fork/s和exec/s列的值,看看系统是否在创建大量新的进程。

 

利用time命令测试某个命令和程序的执行效率

 

我们可以利用time命令来测试一个命令的执行效率,语法为:

 

time command

 

command is executed. Upon completion, time prints the elapsed time during the command, the time spent in the system, and the time spent executing the command. Times are reported in seconds.

 

Execution time can depend on the performance of the memory in which the program is running.

 

当我们觉得某个进程的性能不好时,最简单的方法就是利用time命令来查看一下进程执行时它的 时间分布情况,然后再用其他工具进一步分析。

 

 

利用top命令查看最耗CPU资源的进程

 

我们可以利用top命令来查看最耗CPU资源的进程。top命令还会根据进程占用CPU资源的多少而动态改变。

 

它的语法为:

top [-s time] [-d count] [-q] [-u] [-h] [-n number]

 

其中各选项的含义为:

-s time: 屏幕刷新的时间间隔time,缺省为5秒;

-d count: 屏幕刷新count次后,top命令自己也退出;

-q: This option runs the top program at the same priority as if it is executed via a nice -20 command so that it will execute faster (see nice(1)). This can be very useful in discovering any system problem when the system is very sluggish. This option is accessibly only to users who have appropriate privileges.

-u: User ID (uid) numbers are displayed instead of usernames. This improves execution speed by eliminating the additional time required to map uid numbers to user names.

-h: Hides the individual CPU state information for systems having multiple processors. Only the average CPU status will be displayed.

-n number: Show only number processes per screen. Note that this option is ignored if number is greater than the maximum number of processes that can be displayed per screen.

top命令运行时,我们可用以下几个快捷键来翻屏:

 

j: 向前翻;

k: 向后翻;

t: 回到第一页;

对结果的分析:

 

通过top命令,我们可以快速了解到目前系统的CPU资源使用情况,尤其是占用CPU资源最多的进程是我们必须关注的对象。

 

我们通过RES(the current size of the process resident in memory)列可以知道每个进程占用内存的数量。

 

我们通过NICE列可以知道系统是否使用NICE值来调节该进程的工作负载平衡。

 

利用uptime命令查看系统整体情况

uptime prints the current time, the length of time the system has been up, the number of users logged on to the system, and the average number of jobs in the run queue over the last 1, 5, and 15 minutes.

 

w is linked to uptime and prints the same output as uptime -w, displaying a summary of the current activity on the system.

 

它的语法为:

 

uptime [-hlsuw] [user]

 

w [-hlsuw] [user]

 

其中各选项的含义为:

 

-h: Suppress the first line and the heading line. This option should not be used with the -u option. This option assumes the use of the -w option to uptime.

-l: Use long output. This option assumes the use of the -w option to uptime.

-s: Use the short form of output for displaying terminal information. The terminal name is abbreviated; the login time and CPU times are suppressed.

-u: Print only the first line describing the overall state of the system. This is the default for the uptime command.ormation for systems having multiple processors. Only the average CPU status will be displayed.

-w: Print a summary of the current activity on the system for each user. This is the default for the w command.

 

利用GlancePlus分析系统CPU资源利用率

利用HPGlancePlus工具可以对进程的整体情况和单独的某个进程都详细分析。

 

1)CPU的整体使用情况的分析:

 

进入GlancePlus

?键进入联机帮助界面;

c键进入CPU的详细界面;

b键表示向后翻页,按f键表示向前翻页;

通过CPU Detail Screen,我们可以知道CPU时间的分布情况,用户用了多少,系统用了多少等。

 

2)对单个进程的CPU资源占用情况分析:

 

进入GlancePlus

?键进入联机帮助界面;

g键进入进程列表界面;

s键进入进程选择界面,通常最忙的进程会作为缺省进程;

输入想查看的进程号;

b键表示向后翻页,按f键表示向前翻页;

在对单个进程的分析中,我们通常要关注以下几个值:

 

CPU Usage;

User CPU;

System CPU;

Priority;

Logical and Physical Reads and Writes;

Total RSS/VSS;

blocked on(通过按shift+>来得到);

 

CPU需求密集型系统的性能调试

4.内存性能分析

内存管理

1)内存管理的主要工作:

 

跟踪内存的使用和可用内存的情况;

为进程分配内存;

管理磁盘与物理内存之间的换页(paging);

 

2)什么是虚拟内存(virtual memory)?

virtual memory uses a disk as an extension of RAM so that the effective size of usable memory grows correspondingly. The kernel will write the contents of a currently unused block of memory to the hard disk so that the memory can be used for another purpose. When the original contents are needed again, they are read back into memory. This is all made completely transparent to the user; programs only see the larger amount of memory available and don't notice that parts of them reside on the disk from time to time. Of course, reading and writing the hard disk is slower (on the order of a thousand times slower) than using real memory, so the programs don't run as fast. The part of the hard disk that is used as virtual memory is called the swap space.

 

3)paging

 

A technique by which the contents of a virtual memory address(called pages) are moved from virtual memory(the disk)into and out of the main memory where it is accessed by the CPU.

 

这个机制是由一个叫vhand的进程来完成。

 

当可用内存的数量小于LOTSFREE时,例程pageout将被调用来选择什么内存可以释放。它采用two-handed clock algorithm,the reference hand turn off the reference bit of each memory page it references.If the refernce bit is still zero when the second hand gets to it,the page is freed.If the page is clean(unmodified),it is added to the freelist.If the page is dirty,it must be posted to the swap device before being put on the freelist.

 

lotsfree: based on physical memory (64 MB -> 863) upper bound where paging starts/stops

desfree: based on physical memory (64 MB -> 215)lower bound where paging starts/stops

minfree: based on physical memory (64 MB -> 53) threshold where deactivation starts

 

4)Page fault

 

An invalid address error(trap)that occurs when the CPU requests a page from memory that has not been paged in from the disk(virtual memory)to the main memory. The page may also have been paged out from the main memory prior the request.

 

5)Process Deactivaton

 

Deactivating a process so its memory pages will be flagged free or paged out rapidly by vhand.

 

6)Thrashing

 

A situation in which a process is spending more time paging than processing;a high number of page faults is occuring.

 

7)Buffer Cache

 

它是内存的一部分,用于加快文件存取时间;

缓存的大小可以随可用内存动态变化,但也可以通过修改内核参数而改成固定的大小;

缓存可以提高磁盘的读/写性能;

在缓存的内容可以通过sync进程来强制写入磁盘;

从缓存的读和写又称为逻辑读和逻辑写;

内存需求

按用途来分,内存可以分成两部分:预留内存和动态内存。

 

预留内存主要用于存放:

system table

data structures

buffer cache

其中系统表和数据结构占用的数量一般很小,但缓存则可能占到很大一部分。

 

动态内存主要用于存放:

process text

data stack

share memory segments

其中各进程锁定的内存会影响动态内存的大小。

 

衡量内存闲忙程度的指标

1)  整体内存忙闲指标:

buffer cache size: 缓存区在内存开销中占很大比例;

page in/out rates;

swap in/out rates;

可用内存的大小,或用得到内存的大小(available memory size):

自由内存的大小(free memory size): what is currently available,it should not be confuzed with available memory,which does not change during normal sytem operation;

swap queue length;

 

2)单个进程的内存衡量指标:

 

一个进程占用物理内存的大小(resident set size)

一个进程占用虚拟内存的大小(virtual set size)

VM reads and writes: it can show how many physical memory management reads and writes were made to and from the disk during the chosen interval.

 

内存资源成为系统性能的瓶颈的征兆

 

当内存资源成为系统性能的瓶颈时,它有一些典型的症状:

 

?  很高的换页率(high pageout rate)

HP-UX是一个按需调页的操作系统,通常情况下,它只执行调入页面进入内存的操作,以让进程能够运行。只有操作系统觉得系统需要释放一些内存空间时,才会执行从内存调出页面的操作,而过高的调出页面操作说明内存缺乏;

?  进程进入不活动状态(process deactivation activity)

当自由的内存页面数量小于MINFREE时,很多进程将强制进入不活动状态,因为,any deactivation activity represents a condition in which normal paging is inadequate to handle the memory demands.自由内存的数量很小,但活动的虚拟内存却很大(very small free memory and large active virtual memory)

交换区所有磁盘的活动次数很高(high disk activity on swap devices)

很高的全局系统CPU利用率(high global system CPU utilization):

很长的运行进程队列,但CPU的空闲时间却很多(large run queue with idle CPU)

内存不够出错(out of memory errors)

CPU用于vhandswapper两中守护进程的时间(CPU time to vhand and swapper)

 

必须注意的是,有时候我们发现CPU很忙,这似乎是CPU资源成为系统性能的瓶颈,但如果进一步分析,发现vhand和swapper守护进程占用了大量的系统CPU时间,很显然,这时系统性能瓶颈真正所在可能是内存。

 

什么地方/哪些进程是占用内存资源的大户?

下面是一些典型的占用内存资源的大户:

buffer cache

plocked processplocked processes are those that are locked in memory and are not elogible to be paged.通常,这些进程都是一些比较重要的进程,不便调出内存。

档案库(archive libraries):把库放入内存可以加快程序的执行,但它们将占用大量的内存;

共享内存(shared memory)

关系型数据库(relational databases)

X-终端和X-服务器进程(X-terminals and X-servers):通常,一个X-终端需要额外的2-4兆内存;一个X-服务器需要400KB以上的内存;

 

利用vmstat命令分析内存的利用率

 

vmstat-report virtual memory statistics

 

The vmstat command reports certain statistics kept about process, virtual memory, trap, and CPU activity. It also can clear the accumulators in the kernel sum structure.

 

它的语法:

 

vmstat [-dnS] [interval [count]]

 

vmstat -f | -s | -z

 

它的选项的说明:

 

-d: Report disk transfer information as a separate section, in the form of transfers per second.

-n: Provide an output format that is more easily viewed on an 80-column display device. This format separates the default output into two groups: virtual memory information and CPU data. Each group is displayed as a separate line of output. On multiprocessor systems, this display format also provides CPU utilization on a per CPU basis.

-S: Report the number of processes swapped in and out (si and so) instead of page reclaims and address translation faults (re and at)

interval: Display successive lines which are summaries over the last interval seconds. If interval is zero, the output is displayed once only. If the -d option is specified, the column headers are repeated. If -d is omitted, the column headers are not repeated.

count: Repeat the summary statistics count times. If count is omitted or zero, the output is repeated until an interrupt or quit signal is received.

-f: Report on the number of forks and the number of pages of virtual memory involved since boot-up.

-s: Print the total number of several kinds of paging- related events from the kernel sum structure that have occurred since boot-up or since vmstat was last executed with the -z option.

-z: Clear all accumulators in the kernel sum structure. This option is restricted to the super user.

对结果的说明:

 

在不带参数的vmstat的命令时,我们首先要关注的是avm(active virtual memory)列和free(free list zise)列的值。如果avm的值很大,而free的值却很小,这时,系统可能有内存瓶颈,我们必须用带-S选项的vmstat命令查看系统是否有deactivation/reactivation活动正在发生。

 

利用ipcs分析消息队列、共享内存和信号量

 

ipcs - report status of interprocess communication facilities

 

ipcs displays certain information about active interprocess communication facilities. With no options, ipcs displays information in short format for the message queues, shared memory segments, and semaphores that are currently active in the system.

 

它的语法:

ipcs [-mqs] [-abcopt] [-C core] [-N namelist]

 

利用GlancePlus分析系统内存资源利用率

 

利用HPGlancePlus可以对内存使用情况进行分析:

 

进入GlancePlus

?键进入联机帮助界面;

m键进入内存的详细界面;

通过memory Detail Screen,我们可以知道内存的分布情况,物理内存多少、缓存多少、用户用了多少,系统用了多少、以及换页情况等。

 

对内存需求密集型系统的性能调试

 

1)基于硬件的方法:

增加物理内存

使用无盘工作站替代X-terminal

 

2)基于软件的方法:

减小内核参数maxdsiz的值;

减少内存锁定的使用;

杀死不必要的进程;

识别出需要大量内存的进程;

重新设计应用;

减小内核的大小;

减小系统表的大小;

减小缓存区的大小;

 

3)利用serialize命令来调度大进程的系统资源需求

/usr/bin/serialize applicaiton

/usr/bin/serialize -p pid

 

5.I/O性能分析

衡量I/O闲忙程度的指标

下面是一些衡量I/O闲忙程度的经用指标:

 

磁盘利用率(disk utilization)

磁盘队列长度(disk queue length)

磁头/逻辑卷的读/写速率(read/write rates per spindle/logical volume)

原始I/O(raw I/O):主要用于数据库应用

交换队列的长度(swap queue length)

缓存命中率(buffer cache hit ratio)

网络文件系统和无盘工作站速率(NFS and diskless rates(server))

 

I/O资源成为系统性能的瓶颈的征兆

I/O成为瓶颈时,会出现下面这些典型的症状:

 

过高的磁盘利用率(high disk utilization)

太长的磁盘等待队列(large disk queue length)

等待磁盘I/O的时间所占的百分率太高(large percentage of time waiting for disk I/O)

太高的物理I/O速率:large physical I/O rate(not sufficient in itself)

过低的缓存命中率(low buffer cache hit ratio(not sufficient in itself))

太长的运行进程队列,但CPU却空闲(large run queue with idle CPU)

哪些活动是占用I/O资源的大户?

下面是一些占用大量I/O资源的活动:

 

换页(paging):paging不仅会引起内存问题,还可能引起磁盘问题;

open,creat,and stat system calls:系统调用会引起大量的磁盘I/O

multiuser I/O and random I/O

relational database

core dumps

 

利用iostat分析I/O的利用率

iostat - report I/O statistics

 

iostat iteratively reports I/O statistics for each active disk on the system.

 

If two or more disks are present, data is presented on successive lines for each disk.

 

With the advent of new disk technologies, such as data striping, where a single data transfer is spread across several disks, the number of milliseconds per average seek becomes impossible to compute accurately. At best it is only an approximation, varying greatly, based on several dynamic system conditions. For this reason and to maintain backward compatibility, the milliseconds per average seek ( msps ) field is set to the value 1.0.

 

它的语法为:

 

iostat [-t] [interval [count]]

 

其选项的含义为:

 

-t:Report terminal statistics as well as disk statistics.

interval: Display successive lines which are summaries of the last interval seconds. The first line reported is for the time since a reboot and each subsequent line is for the last interval only.

count: Repeat the statistics count times.

 

bps         Kilobytes transferred per second.

sps         Number of seeks per second.

msps        Milliseconds per average seek.

对结果的分析:

 

通过查看bps列和sps列的值我们可以知道哪些磁盘比较忙,哪些磁盘比较闲。

利用SAR -d分析磁盘活动

 

通过命令sar -d,我们可以分析系统中的每个磁盘和磁带的活动情况。

 

Report activity for each block device, e.g., disk or tape drive. One line is printed for each device that had activity during the last interval. If no devices were active, a blank line is printed.Each line contains the following data:

 

device:设备名;

%busy: Portion of time device was busy servicing a request; statistics.

avque: Average number of requests outstanding for the device;

r+w/s: Number of data transfers per second (read and writes) from and to the device;

blks/s: Number of bytes transferred (in 512-byte units) from and to the device;

avwait: Average time (in milliseconds) that transfer requests waited idly on queue for the device;

avserv: Average time (in milliseconds) to service each transfer request (includes seek, rotational latency, and data transfer times) for the device.

对结果的分析:

 

如果某个磁盘的%busy列的值大于50%,则说明该磁盘可能存在瓶颈;

 

如果某个磁盘的avwait珍的值大于avserv列的值,也说明该磁盘可能存在瓶颈;

 

利用SAR -b分析缓冲区的活动

 

通过命令sar -b,我们可以分析系统中的缓冲区的活动情况。

 

Report activity for each block device, e.g., disk or tape drive. One line is printed for each device that had activity during the last interval. If no devices were active, a blank line is printed.Each line contains the following data:

 

bread/s Number of physical reads per second from the disk (or other block devices) to the buffer cache;

bwrit/s: Number of physical writes per second from the buffer cache to the disk (or other block device);

lread/s: Number of reads per second from buffer cache;

lwrit/s: Number of writes per second to buffer cache;

%rcache: Buffer cache hit ratio for read requests e.g., 1 - bread/lread;

%wcache: Buffer cache hit ratio for write requests e.g., 1 - bwrit/lwrit;

pread/s: Number of reads per second from character device using the physio() (raw I/O) mechanism;

pwrit/s: Number of writes per second to character device using the physio() (i.e., raw I/O ) mechanism; mechanism.

对结果的分析:

 

如果%rcache列的值小于90%,并且%wcache列的值不在70-70%之间,我们必须观察系统中什么应用在做什么样的读/写操作,我们是否需要增加缓冲的大小。

 

利用SAR -w分析交换区的活动

 

通过命令sar -w,我们可以分析系统中的交换区的活动情况。

 

Report activity for each block device, e.g., disk or tape drive. One line is printed for each device that had activity during the last interval. If no devices were active, a blank line is printed.Each line contains the following data:

 

swpin/s: Number of process swapins per second;

swpot/s: Number of process swapouts per second;

bswin/s: Number of 512-byte units transferred for swapins per second;

bswot/s: Number of 512-byte units transferred for swapouts per second;

pswch/s: Number of process context switches per second.

对结果的分析:

 

如果swpin/s的值大于零,那么swpot的值必须引起注意;

 

同时必须注意pswch/s的值,如果很大,说明进程切换频繁。

 

利用GlancePlus分析系统的I/O活动情况

 

1)对磁盘的整体使用情况的分析:

 

进入GlancePlus

?键进入联机帮助界面;

d键进入磁盘的详细界面;

b键表示向后翻页,按f键表示向前翻页;

通过Disk Detail Screen,我们可以知道所有的逻辑和物理I/O请求的分布情况。

 

2)Disk I/O by File System

 

进入GlancePlus

?键进入联机帮助界面;

iDisk I/O by File System表界面;

b键表示向后翻页,按f键表示向前翻页;

这个界面很有用,因为它按不同的文件显示I/O的繁忙程度。

 

3)对逻辑卷的分析

 

进入GlancePlus

?键进入联机帮助界面;

vI/O by logical volumes表界面;

b键表示向后翻页,按f键表示向前翻页;

通过把对文件系统的分析和逻辑卷的分析结合起来,能够知道哪个磁盘的I/O最忙。

 

4)对磁盘的分析

 

5)对交换区的分析

 

 

阅读(7026) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~