zoukankan      html  css  js  c++  java
  • 找出Linux下面哪个进程最耗iowait

    1. 找出CPU占用率高的线程:
    ps H -eo user,pid,ppid,tid,time,psr,%cpu,cmd --sort=%cpu
    参数'H'显示线程相关的信息,格式输出中包含:user,pid,ppid,tid,time,%cpu,cmd,然后再用%cpu字段进行排序
    2. 找出耗iowait的进程
    先停掉syslog
    service syslog stop
    打开block dump:
    echo 1 > /proc/sys/vm/block_dump
    多次运行,查看结果
    dmesg | egrep "READ|WRITE|dirtied" | egrep -o '([a-zA-Z]*)' | sort | uniq -c | sort -rn | head
    排前的比较占用io
    抓完后关掉block_dump和启动syslog:
    echo 0 > /proc/sys/vm/block_dump
    service syslog start
    实践发现,这样找出的进程一般为kjournald、pdflush、kswapd0。
    3. pidstat
    # pidstat -d 5
    Linux 2.6.26-2-openvz-686 (pro-12-gl.savonix.com)   10/29/2009  _i686_  (2 CPU)
    11:19:41 PM       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
    11:19:46 PM      1895      0.00     23.06      0.00  kjournald
    11:19:46 PM      7309      0.00      0.80      0.00  syslog-ng
    11:19:46 PM     21404      0.00      0.80      0.00  tlsmgr
    11:19:46 PM       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
    11:19:51 PM     18208      0.00      0.80      0.00  syslog-ng
    11:19:51 PM       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
    11:19:56 PM      1895      0.00      9.60      0.00  kjournald
    11:19:56 PM     17120      0.00      1.60      0.00  tlsmgr
    11:19:56 PM     27257      0.00      1.60      0.00  apache2
    11:19:56 PM       PID   kB_rd/s   kB_wr/s kB_ccwr/s  Command
    11:20:01 PM       423      0.00      0.80      0.00  apache2
    11:20:01 PM      1851      0.00      0.80      0.00  nginx
    11:20:01 PM      1895      0.00      8.80      0.00  kjournald
    然后可以使用top命令查看进程对应的物理CPU:
    执行top后,按f,再选择j: P Last used cpu (SMP) ,再按回车回到top界面
    注:进程kjournald、pdflush、kswapd0的作用
    1.kswapd0
    Linux uses kswapd for virtual memory management such that pages that have been recently accessed are kept in memory and less active pages are paged out to disk.
    (what is a page?)…Linux uses manages memory in units called pages.
    So,the kswapd process regularly decreases the ages of unreferenced pages…and at the end they are paged out(moved out) to disk
    系统每过一定时间就会唤醒kswapd,看看内存是否紧张,如果不紧张,则睡眠,在kswapd中,有2个阀值,pages_hige和pages_low,当空闲内存页的数量低于pages_low的时候,kswapd进程就会扫描内存并且每次释放出32个free pages,直到free page的数量到达pages_high.
    2.kjournald
    EXT3文件系统的日志进程,具有3种模式:
    journal - logs all filesystem data and metadata changes. The slowest of the three ext3 journaling modes, this journaling mode minimizes the chance of losing the changes you have made to any file in an ext3 filesystem.(记录所有文件系统上的元数据改变,最慢的一种模式,)
    ordered - only logs changes to filesystem metadata, but flushes file data updates to disk before making changes to associated filesystem metadata. This is the default ext3 journaling mode.(默认使用的模式,只记录文件系统改变的元数据,并在改变之前记录日志)
    writeback - only logs changes to filesystem metadata but relies on the standard filesystem write process to write file data changes to disk. This is the fastest ext3 journaling mode.(最快的一种模式,同样只记录修改过的元数据,依赖标准文件系统写进程将数据写到硬盘)
    修改模式EXT3的工作模式;
    vim /etc/fstab
    /dev/hda5      /opt            ext3       data=writeback        1 0
    详细介绍:
    http://www.linuxplanet.com/linuxplanet/reports/4136/5/
    3.pdflush
    pdflush用于将内存中的内容和文件系统进行同步,比如说,当一个文件在内存中进行修改,pdflush负责将它写回硬盘.每当内存中的垃圾页(dirty page)超过10%的时候,pdflush就会将这些页面备份回硬盘.这个比率是可调节的,通过/etc/sysctl.conf中的 vm.dirty_background_ratio项 默认值为10 也可以
    cat /proc/sys/vm/dirty_background_ratio 查看当前的值
  • 相关阅读:
    TensorFlow 官方文档中文版 --技术文档
    借助离散数学解决“哈弗大学智商测试”一题 --编程算法
    Python3文件操作1 --Python3
    ThinkPHP5.0完全开发手册 --技术文档
    JSON和Serialize数据格式的对比
    JSON格式简介
    Github的简易操作
    Python3之JSON数据解析实例:新闻头条 --Python3
    MySql常用函数 --MySql
    Git简易教程
  • 原文地址:https://www.cnblogs.com/feisky/p/2390248.html
Copyright © 2011-2022 走看看