shitou's blog 
Home About Feed | MIX BOY 塌客

Tags "mysql"

30
Oct

Shell: 统计MySQL InnoDB表的大小 by shitou

0
之前写的脚本了,MyISAM表和数据的大小直接统计目录就行了,InnoDB不行
#file:                  get_innodb_db_size.sh
#author:                shitou
#date:                  09/18/2008
#aim:                   get mysql db table size, especially for Innodb table
#use:                   first replace the db username and password, 
#                       #./get_innodb_db_size username db_name

[[ $# == 0 ]] && { echo "need the db name and mysql username"; exit 1; }
mysql -u $1 -p -e "show table status from $2\G" | \
awk '/(Data_length:|Name:)/{print $0}' | \
awk 'BEGIN{i=1;
        total=0;
        print "DB: '"$2"'";
        print "-----------------------------------";};
        {if(i%2==0){size=$2;printf "%-30s%d\n", table, size}
        else
        {table=$2};i++;total+=$2};
        END{print "-----------------------------------";
        split(i/2, num, ".");
        printf "TOTAL TABLE:%25d\n", num[1];
        printf "TOTAL SIZE:%25d B\n", total}'

#EOF

Tags: shell,mysql

2009-10-30 11:58:19, 296 reviews

send to mailbox

Your email:

11
Oct

mysqlreport详解 by shitou

2
最近在玩mysqlreport, 在网上找到一篇台湾人汉化的文档.但发现没有 innodb 部分的说明.
于是,参考官方的文档, 补充了一下innodb部分. 如下:

下面的图表只输出innodb部分, 要查看全部信息, 点击下面的url
官方: http://hackmysql.com/mysqlreportguide
一篇台湾作者汉化的文档: http://forum.slime.com.tw/thread208416.html

__ InnoDB Buffer Pool __________________________________________________
Usage           7.97M of   8.00M  %Used:  99.61
Read hit      100.00%

Pages
  Free              2            %Total:   0.39
  Data            499                     97.46 %Drty:   0.00
  Misc             11                      2.15
  Latched           0                      0.00

Reads         101.06M     8.5/s
  From file       373     0.0/s            0.00
  Ahead Rnd        19     0.0/s
  Ahead Sql        13     0.0/s

Writes        860.88k     0.1/s
Flushes       254.62k     0.0/s
Wait Free           0       0/s

__ InnoDB Lock _________________________________________________________
Waits             424     0.0/s
Current             0
Time acquiring
  Total        254266 ms
  Average         599 ms
  Max           39559 ms

__ InnoDB Data, Pages, Rows ____________________________________________
Data
  Reads           502     0.0/s
  Writes      344.09k     0.0/s
  fsync       158.03k     0.0/s
  Pending
    Reads           0
    Writes          0
    fsync           0

Pages
  Created         699     0.0/s
  Read            523     0.0/s
  Written     254.62k     0.0/s

Rows
  Deleted       4.59k     0.0/s
  Inserted     74.16k     0.0/s
  Read         94.67M     8.0/s
  Updated      40.61k     0.0/s

第一区块, 展示了 mysql innodb 的缓存统计信息. 
其中, innodb跟myisam的缓存机制有较大区别, innodb不仅缓存索引,还缓存一些表数据.而myisam只缓存索引.
Usage           7.97M of   8.00M  %Used:  99.61
Read hit      100.00%
Usage 表示, 总的缓存中, 当前已占用 7.97M, 使用率达 99.61%. 这种情况, 是存在瓶颈的, 需要适当增加缓存总量.
Read hit 表示缓存命中率 100%, 这个数值是比较理想的, 一般情况下, 都应该大于 99.98%.
Pages
Free              2            %Total:   0.39
Data            499                     97.46 %Drty:   0.00
Misc             11                      2.15
Latched           0                      0.00
innodb的存储是按页分的, 每页的容量默认是 16K. (详见 http://www.mysqlperformanceblog.com/2006/06/04/innodb-page-size/)

这里的,Free指的是缓存中的总页数, 剩余的页, 占总的 0.39%.
Data是指缓存中, 存储索引数据的页的数量.其中, 最后一项 %Dtry 表示脏数据的百分比.所谓的脏数据是指, 对缓存数据更新后, 没有同步到硬盘的数据.
misc 和 latched 就是之前说的其他信息的一些缓存.
Reads         101.06M     8.5/s
From file       373     0.0/s            0.00
Ahead Rnd        19     0.0/s
Ahead Sql        13     0.0/s
Reads代表从缓存里, 总共读取了多少M的数据.
From file, 表示从硬盘文件中读取到缓存里的页数量.
Ahead Rnd, 表示随机预读的次数.
Ahead Sql, 表示全表扫描时, sql预读的次数.
Writes        860.88k     0.1/s
Flushes       254.62k     0.0/s
Wait Free           0       0/s
Writes , 表示写入缓存的总大小.
Flushes , 表示缓存数据更新到硬盘的大小.
Waint Free, 表示, 等待可写入数据的页的次数.
这里为什么会等待, 是因为, 数据写入到缓存页时, 必须保证, 这个页被创建好, 或者这个页之前的数据已经被同步到硬盘上.
Waits             424     0.0/s
Current             0
Time acquiring
  Total        254266 ms
  Average         599 ms
  Max           39559 ms
Waits , 表示执行线程等待锁的释放的次数.
Current, 表示当前所有的执行线程, 正在等待锁的数量.
Time acquiring 里的 Total , 指的是, 等待锁所消耗的总时间.
Average, 是指, 平均消耗的时间.
Max, 是指, 单次等待锁, 所消耗最多的时间.
Data
  Reads           502     0.0/s
  Writes      344.09k     0.0/s
  fsync       158.03k     0.0/s
Pending
    Reads           0
    Writes          0
    fsync           0
Data里的Reads, 表示数据读取的次数.
Writes, 表示数据写入的数据量大小.
fsync, 表示缓存同步到硬盘的数据量大小.

Pending里的Reads, Writes, fsync , 表示当前进行读写, 同步的次数.
Pages
  Created         699     0.0/s
  Read            523     0.0/s
  Written     254.62k     0.0/s
Pages 里的created, 表示, 总共创建过 699 个页.
Read, 表示被读取的页的数量.
Written, 表示写入到页里的,总大小.
Rows
Deleted       4.59k     0.0/s
Inserted     74.16k     0.0/s
Read         94.67M     8.0/s
Updated      40.61k     0.0/s
Rows里的四个操作,分别代表删除, 插入, 查询, 更新的数据量大小.

性能关注点分析

首先是Usage, 如果占比达 90 - 95%以上, 可能需要增加预设缓存大小.
调整的参数是 innodb_buffer_pool_size

其次是 Read Hit, 即缓存命中率, 如果该值远远小于100%, 就要调查缓存的有效性了.
比如, 缓存写次数是否大于查询次数. (Buffer里的reads和writes)

最后,需要关注的是, 数据的读写比例. 这里有个要注意的地方是, mysql如果启动到现在不到24小时或一个较长的运行周期, 这个读写比例值可能是不准的.

一般的应用,我感觉读写比例在 8/2 差不多. 如果读远远大于写, 那么你可以测下 MyISAM 引擎的性能, 看看是否适合你.
转载自javaeye
Tags: mysql,监控

2008-10-11 15:19:40, 378 reviews

send to mailbox

Your email:

Tags

U-ka saegusa IN db command Mai Kuraki Norah Jones log iPhoneException ACG Mac Safari objective-c CouchDB LVS AJAX debian 推荐 AMQP google mail bug gettext Erlang 北京 iptables 架构 tips mysql backup function 我看 postfix 监控 SEO cache Etag memcache thread 进程 线程 无锡 yield file column mixboy xml rss gems ruby shitou shell lighttpd 安全 csrf 公司 nginx linux 模块 apache webserver 朋友 大学 生活 尼古拉斯凯奇 movie 文件同步 笑笑 歌词 auto complete plugin rails music ubuntu blog

Category

  • iPhone[17]
  • Erlang[4]
  • google[8]
  • 生活[38]
  • 音乐[11]
  • 电影[11]
  • linux[20]
  • web server[6]
  • mail server[3]
  • cluster[1]
  • system manage[5]
  • ruby[18]
  • ruby on rails[27]
  • 开源[3]

Episode

  • iPhoneException
  • shell
  • thread
  • memcache

Recent Comments

  • я считаю: превосходно. мамба интим знакомс...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • [b]Comprar vardenafil 20mg en Mexico Sin Receta...
  • я думаю: восхитительно.. познакомлюсь ради...

Popular Posts

  • MySQL Innodb备份
  • 准备开始学习Erlang了(恶狼, 二郎..)
  • Lighttpd配置参数
  • iPhone上的HelloWorld终于跑起来了
  • Etag和Expire

Recommended Posts

  • Mai Kuraki -永远より ながく
  • U-ka saegusa IN db Final Best
  • Heaven Can Wait - Charlotte Gainsbou
  • Ruby遍历MemCached的key
  • Norah Jones - The fall
  • 请记得仰望梦想的姿势
  • Shell: 统计MySQL InnoDB表的大小
  • Rails Benchmark
  • 发送异常到邮箱
  • I Miss Nobody
  • Music4u, Vol. 1
  • my macbook
  • Mai Kuraki-Beautiful
  • 10首最伤情英文歌曲精选
  • Mai Kuraki - PUZZLE/Revive

Friends' blogs

  • levy
  • sphance
  • andreas

Login

   注册

留言 查看留言

留言

   取消

留言 查看留言


Statistics

  • 访问次数: 51664
  • 今天访问: 131
  • 日志: 172
  • 评论: 138
  • 音乐: 9
  • 用户: 150


 

just DO NOT support IE

close