Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7096382
  • 博文数量: 703
  • 博客积分: 10821
  • 博客等级: 上将
  • 技术积分: 12042
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-02 10:41
个人简介

中科院云平台架构师,专注于数字化、智能化,技术方向:云、Linux内核、AI、MES/ERP/CRM/OA、物联网、传感器、大数据、ML、微服务。

文章分类

全部博文(703)

分类: 系统运维

2016-01-06 22:10:15

IO占用大,文件系统使用的是ext3
用iostat命令发现磁盘util%接近100%,用下面的脚本查看,发现kjournald一直在写。请问是什么原因造成的,该怎么处理,谢谢! 

  
#!/usr/bin/python 
# 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  
         self.pid = pid 
         self.reads = 0 
         self.writes = 0 
  
def main(): 
     argc = len(sys.argv) 
     if argc != 1: 
         print "usage: ./iotop" 
         sys.exit(0) 
  
     if os.getuid() != 0: 
         print "must be run as root" 
         sys.exit(0) 
  
     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:        
                     l.append(DiskIO(m.group(1), m.group(2))) 
                     line = f.readline()  
                     continue             
                 found = False    
                 for item in l:   
                     if item.pid == m.group(2): 
                         found = True             
                         if m.group(3) == "READ": 
                             item.reads = item.reads + 1  
                         elif m.group(3) == "WRITE": 
                             item.writes = item.writes + 1 
                 if not found:    
                     l.append(DiskIO(m.group(1), m.group(2))) 
             line = f.readline() 
         time.sleep(1) 
         for item in l: 
             print "%-10s %10s %10d %10d" % \ 
                 (item.pname, item.pid, item.reads, item.writes) 
  
def signal_handler(signal, frame): 
     os.system('echo 0 > /proc/sys/vm/block_dump') 
     sys.exit(0) 
  
if __name__=="__main__": 
     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的值改大一些。
阅读(6403) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~