OPS Notes By 枯木

Top基本介绍

| Comments

top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器。下面跟着笔者一起top一下吧:

1
2
3
4
5
6
7
8
9
# top
top - 10:52:40 up 3 days, 52 min,  1 user,  load average: 57.28, 112.40, 123.60
Tasks:  99 total,   1 running,  98 sleeping,   0 stopped,   0 zombie
Cpu(s): 19.5%us, 11.4%sy,  0.0%ni,  0.0%id, 65.7%wa,  0.0%hi,  3.4%si,  0.0%st
Mem:  16435896k total, 16232468k used,   203428k free,    58004k buffers
Swap:  1044476k total,   713552k used,   330924k free, 10052032k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  ... ...

统计信息区前五行是系统整体的统计信息。第一行是任务队列信息,同uptime命令的执行结果。其内容如下:

10:52:40 当前时间
up 3 days, 52 min 系统运行时间
1 users 当前登录用户数
load average: 57.28, 112.40, 123.60 系统负载,即任务队列平均长度。
分别为1、5、15min前到现在平均值。

第二、三行为进程和CPU的信息。当有多个CPU时,这些内容可能会超过两行。内容如下:

Tasks:99 total 进程总数[键入H可查看线程数]
1 running, 98 sleeping, 0 stopped 正在运行的进程、睡眠进程、停止的进程
0 zombie 僵尸进程数
Cpu(s): 19.5%us, 11.4%sy,
0.0%ni, 0.0%id,
65.7%wa, 0.0%hi, 3.4%si, 0.0%st
用户空间占用CPU百分比、内核空间占用CPU百分比
用户进程空间内改变进程优先级占用CPU、空闲CPU百分比
等待IO的CPU时间百分比,最后三个是中断请求相关

倒数第2、3行为内存相关信息:

Mem: 16435896k total, 16232468k used,
203428k free, 58004k buffers
分别是物理内存总量、使用物理内存总量
空闲内存总量、用作内核缓存内存量
Swap: 1044476k total, 713552k used,
330924k free, 10052032k cached
分别是交换分区量、使用交换分区总量
空闲交换区总量、缓存交换区总量

buffer Difference between buffer and cache?

A data area, shared by hardware devices or program a process is called buffer. They are operated at different speeds or with different sets of priorities. The buffer allows each device or process to operate without holding up by the other. In order to a buffer to be effective, the size of the buffer needs to be considered by the buffer designer. Like a cache, a buffer is a “midpoint holding place” but does not exist so much to accelerate the speed of an activity as for supporting the coordination of separate activities.

This term is used not only in programming but in hardware as well. In programming, buffering sometimes needs to screen data from its final intended place so that it can be edited or processed before moving to a regular file or database.

cached

Cache memory is type of random access memory (RAM). Cache Memory can be accessed more quickly by the computer microprocessor than it can be accessed by regular RAM. Like microprocessor processes data, it looks first in the cache memory and if there, it finds the data from a previous reading of data, it does not need to do the more time consuming reading of data from larger memory.

Sometimes Cache memory is described in levels of closeness and convenience to the microprocessor. An L1 cache is on the same chip like the microprocessors.

In addition to cache memory, RAM itself is a cache memory for hard disk storage since all of RAM’s contents come up to the hard disk initially when you turn on your computer and load the operating system that you are loading it into RAM and later when you start new applications and access new data. RAM also contains a special area called a disk cache that consists of the data most recently read in from the hard disk.

最后1行则是进程相关的资源占用信息:

  • PID:进程的ID
  • USER:进程所有者
  • PR:进程的优先级别,越小越优先被执行
  • NI:nice值。负值表示高优先级,正值表示低优先级
  • VIRT:进程占用的虚拟内存
  • RES:进程占用的物理内存
  • SHR:进程使用的共享内存
  • S:进程的状态。S表示休眠,R表示正在运行,Z表示僵死状态,N表示该进程优先值为负数
  • %CPU:进程占用CPU的使用率
  • %MEM:进程使用的物理内存和总内存的百分比
  • TIME+:该进程启动后占用的总的CPU时间,即占用CPU使用时间的累加值。
  • COMMAND:进程启动命令名称

–EOF–

top实践–top实践小技巧

Comments