zoukankan      html  css  js  c++  java
  • MySQL的数据读取过程

    本文来自:http://blog.chinaunix.net/uid-20785090-id-4759476.html

      对于build-in的innodb的架构,每次当发布IO请求时,究竟是
    mysql服务的线程完成还是由innodb_read_io_threads来完成的呢?和朋友讨论
    这个问题,没有结论,通过跟踪发现,是由mysql服务的线程完成的.

    MYSQL:5.5.33
    OS:RHEL 5.8

    连接到mysql,关闭自动提交,然后发布一条sql
    mysql> set autocommit=0;
    Query OK, 0 rows affected (0.02 sec)

    mysql> insert into t2 values(34);
    Query OK, 1 row affected (0.04 sec)

    查看当前事务的线程handle

    mysql> show engine innodb statusG;

    ...............................

    ---TRANSACTION 57498, ACTIVE 3 sec
    1 lock struct(s), heap size 376, 0 row lock(s), undo log entries 1
    MySQL thread id 12, OS thread handle 0x4d67e940, query id 332 localhost root cleaning up
    TABLE LOCK table `db1`.`t2` trx id 57498 lock mode IX
    ----------------------------
    END OF INNODB MONITOR OUTPUT
    ============================


    可以看到当前的handle是  0x4d67e940,通过pstack找到mysql的进程号,然后查看线程
    通过gdb也可以实现类似的功能.

    [root@c12 zabbix]# ps -eaf | grep mysqld
    root      2452     1  0 Jan09 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/c12.fb.com.pid
    mysql     2734  2452  0 Jan09 ?        00:00:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/mysql/plugin --user=mysql --log-error=/usr/local/mysql/data/c12.fb.com.err --pid-file=/usr/local/mysql/data/c12.fb.com.pid --socket=/tmp/mysql.socket

    [root@c12 zabbix]# pstack 2734
    .............................

    Thread 2 (Thread 0x4d67e940 (LWP 26297)):
    #0  0x00000036a1ccaf36 in poll () from /lib64/libc.so.6
    #1  0x0000000000b612cf in vio_io_wait ()
    #2  0x0000000000b613c3 in vio_socket_io_wait ()
    #3  0x0000000000b61a18 in vio_read ()
    #4  0x0000000000659213 in net_read_raw_loop(st_net*, unsigned long) ()
    #5  0x0000000000659aab in net_read_packet(st_net*, unsigned long*) ()
    #6  0x0000000000659d1c in my_net_read ()
    #7  0x00000000006ea30d in do_command(THD*) ()
    #8  0x00000000006b5d5f in do_handle_one_connection(THD*) ()
    #9  0x00000000006b5e37 in handle_one_connection ()
    #10 0x0000000000acde7a in pfs_spawn_thread ()
    #11 0x00000036a280673d in start_thread () from /lib64/libpthread.so.0
    #12 0x00000036a1cd3d1d in clone () from /lib64/libc.so.6
    Thread 1 (Thread 0x2ab3670fcab0 (LWP 2734)):
    #0  0x00000036a1ccaf36 in poll () from /lib64/libc.so.6
    #1  0x000000000059b6ca in handle_connections_sockets() ()
    #2  0x00000000005a3379 in mysqld_main(int, char**) ()
    #3  0x00000036a1c1d994 in __libc_start_main () from /lib64/libc.so.6
    #4  0x0000000000594319 in _start ()

    对这个线程跟踪IO调用

    [root@c12 ~]# strace -e trace=open,pread -p 26297
    Process 26297 attached - interrupt to quit


    发布一个读表的select

    mysql> select count(*) from  users;
    +----------+
    | count(*) |
    +----------+
    |        2 |
    +----------+
    1 row in set (0.02 sec)

    .....................................................
    open("./zabbix/users.ibd", O_RDWR)      = 60
    pread(60, "sj304=43773773773773773773773773233202267E277"..., 16384, 65536) = 16384
    pread(60, "v304i22713233qz5"..., 16384, 16384) = 16384


    可以看到这线程的调用输出,先打开文件,然后使用pread去读取,刚好每次的大小是innodb_page_size定的.

  • 相关阅读:
    电脑进入bios和u盘启动快捷键
    Securecrt 在win7下 字体太少问题
    windows无法安装到这个磁盘 gpt分区形式
    优酷上传高清视频
    将文件服务器及域控制器从2003迁移至Windows Server 2008 R2
    L SERVER 数据库被标记为“可疑”的解决办法
    Outlook关闭时最小化
    windows 7系统封装总结
    查询某软件所连接的外网IP地址
    windows桌面图标及任务管理栏丢失
  • 原文地址:https://www.cnblogs.com/erisen/p/6040106.html
Copyright © 2011-2022 走看看