Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5945278
  • 博文数量: 680
  • 博客积分: 10821
  • 博客等级: 上将
  • 技术积分: 11839
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-02 10:41




分类: 系统运维

2016-01-06 22:10:15


# Monitoring per-process disk I/O activity 
# written by   
import sys, os, time, signal, re 
class DiskIO: 
     def __init__(self, pname=None, pid=None, reads=0, writes=0): 
         self.pname = pname   = pid 
         self.reads = 0 
         self.writes = 0 
def main(): 
     argc = len(sys.argv) 
     if argc != 1: 
         print "usage: ./iotop" 
     if os.getuid() != 0: 
         print "must be run as root" 
     signal.signal(signal.SIGINT, signal_handler) 
     os.system('echo 1 > /proc/sys/vm/block_dump') 
     print "TASK              PID       READ      WRITE" 
     while True: 
         os.system('dmesg -c > /tmp/diskio.log') 
         l = []   
         f = open('/tmp/diskio.log', 'r') 
         line = f.readline() 
         while line: 
             m = re.match(\ 
                 '^(\S+)\((\d+)\): (READ|WRITE) block (\d+) on (\S+)', line) 
             if m != None: 
                 if not l:        
                     line = f.readline()  
                 found = False    
                 for item in l:   
                     if == 
                         found = True             
                         if == "READ": 
                             item.reads = item.reads + 1  
                         elif == "WRITE": 
                             item.writes = item.writes + 1 
                 if not found:    
             line = f.readline() 
         for item in l: 
             print "%-10s %10s %10d %10d" % \ 
                 (item.pname,, item.reads, item.writes) 
def signal_handler(signal, frame): 
     os.system('echo 0 > /proc/sys/vm/block_dump') 
if __name__=="__main__": 

1:调整一下文件系统的jounal模式,默认为ordered ,改成writeback会提高一些效率。
Despite writing some data more than once, ext3 is often faster (higher throughput) than ext2 because ext3's journaling optimizes hard drive head motion. You can choose from three journaling modes to optimize speed, optionally choosing to trade off some data integrity.
    * One mode, data=writeback, limits the data integrity guarantees, allowing old data to show up in files after a crash, for a potential increase in speed under some circumstances. (This mode, which is the default journaling mode for most journaling file systems, essentially provides the more limited data integrity guarantees of the ext2 file system and merely avoids the long file system check at boot time.)
    * The second mode, data=ordered (the default mode), guarantees that the data is consistent with the file system; recently-written files will never show up with garbage contents after a crash.
    * The last mode, data=journal, requires a larger journal for reasonable speed in most cases and therefore takes longer to recover in case of unclean shutdown, but is sometimes faster for certain database operations.
The default mode is recommended for general-purpose computing needs. To change the mode, add the data=something option to the mount options for that file system in the /etc/fstab file, as documented in the mount man page (man mount).

2:另外可以用dumpe2fs看一下Journal size是多大,
     可以想办法把Journal size的值改大一些。
阅读(4865) | 评论(0) | 转发(0) |