解决因jbd2导致mysql性能过低问题

在几个月前,有同事因为需要对某项功能进行压力测试,测试mysql的读写性能。当时测下来的结果非常不满意,本地测试环境性能巨差无比,当时我帮忙找问题,top看cpu、内存完全没有问题,iotop看到有jbd2 I/O占用到了99%。压力测试一结束,也随之降下来。当时排查了一段时间,始终没有搞定,就放弃了。就在这周,还是需要测试mysql性能,还是因为这个问题,我就花了一个下午的时间,终于解决了。

首先我们应该了解一下jbd2是什么东西。为什么I/O会如此之高。随便google一下,都有问到jbd2如何关闭。但是没有一个答案是能搞定的。wikipedia下是这样定义的(JBD):

The Journaling Block Device (JBD) provides a filesystem-independent interface for filesystem journaling. ext3, ext4 and OCFS2 are known to use JBD. OCFS2 starting from linux 2.6.28 and ext4 use a fork of JBD called JBD2

那如何关闭JBD2呢?

首先用 dumpe2fs /dev/sda6 | more 查看Filesystem Feature下有木有has_journal。如果没有就不用看了 -_-

tune2fs -o journal_data_writeback /dev/sda6
tune2fs -O "^has_journal" /dev/sda6
e2fsck -f /dev/sda6

同时在fstab下重新设定一下,在defaults之后增加

defaults,data=writeback,noatime,nodiratime

重启之后,在使用dumpe2fs查看,若没有了,那说明已经把jbd关闭了。

如果使用tune2fs时候,提示disk正在mount,如果是非系统盘下,你可以使用

fuser -km /home #杀死所有使用/home下的进程
umount /dev/sda6 #umount

之后在使用上面的命令进行移除has_journal

你现在在google上搜索“jbd2/sda1-8 high io”,仍然没有一个完整的解决方案,希望这文章能帮到你。

Leave a Comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: