码迷,mamicode.com
首页 > 数据库 > 详细

innodb master主线程

时间:2015-08-17 16:52:13      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

 

/* Number of IO operations per second the server can do */
extern ulong    srv_io_capacity;
/* Returns the number of IO operations that is X percent of the
capacity. PCT_IO(5) -> returns the number of IO operations that
is 5% of the max where max is srv_io_capacity.  */
#define PCT_IO(p) ((ulong) (srv_io_capacity * ((double) p / 100.0)))

 

第一分钟

1)日志缓冲刷新到disk

/* Flush logs if needed */
srv_sync_log_buffer_in_background();

 

2)合并insert buffer

如果上一秒的disk io 小于 innodb_io_capacity的5%,将innodb_io_capacity的 5%的insert_buffer刷新至disk

/* If i/os during one second sleep were less than 5% of
        capacity, we assume that there is free disk i/o capacity
        available, and it makes sense to do an insert buffer merge. */
if (n_pend_ios < SRV_PEND_IO_THRESHOLD
    && (n_ios - n_ios_old < SRV_RECENT_IO_ACTIVITY)) {
    srv_main_thread_op_info = "doing insert buffer merge";
    ibuf_contract_for_n_pages(FALSE, PCT_IO(5));
}

 

3)刷新缓冲区中的脏页至disk

如果缓冲区中的脏页比例大于70%,则刷新100%的innodb_io_capacity的脏页至disk

如果不大于,通过判断重做日志的速度来判断刷新脏页的数量

srv_max_buf_pool_modified_pct 75
buf_get_modified_ratio_pct 缓冲区中的脏页比例
if (UNIV_UNLIKELY(buf_get_modified_ratio_pct()
                  > srv_max_buf_pool_modified_pct)) {
    n_pages_flushed = buf_flush_list(PCT_IO(100), IB_ULONGLONG_MAX);
} else if (srv_adaptive_flushing) {
    //通过计算重做日志的速度,得到要刷新脏页个数
    ulint n_flush = buf_flush_get_desired_flush_rate();

    if (n_flush) {
        n_flush = ut_min(PCT_IO(100), n_flush);
        n_pages_flushed =buf_flush_list(n_flush,IB_ULONGLONG_MAX);
    }
}

 

每十分钟

1)如果过去10秒内的disk io 小于200,则把缓冲区中的100个脏页刷新到disk 

#define SRV_PAST_IO_ACTIVITY    (PCT_IO(200))
buf_get_total_stat(&buf_stat);
    n_pend_ios = buf_get_n_pending_ios() + log_sys->n_pending_writes;
    n_ios = log_sys->n_log_ios + buf_stat.n_pages_read
        + buf_stat.n_pages_written;

    srv_main_10_second_loops++;
    if (n_pend_ios < SRV_PEND_IO_THRESHOLD
        && (n_ios - n_ios_very_old < SRV_PAST_IO_ACTIVITY)) {

        srv_main_thread_op_info = "flushing buffer pool pages";
        buf_flush_list(PCT_IO(100), IB_ULONGLONG_MAX);

        /* Flush logs if needed */
        srv_sync_log_buffer_in_background();
    }

 

2)合并insert bufferr中的5个页

srv_main_thread_op_info = "doing insert buffer merge";
ibuf_contract_for_n_pages(FALSE, PCT_IO(5));

 

3)将日志缓冲刷新到disk,即使事务没有commit

srv_sync_log_buffer_in_background();

 

4)如果缓冲区中的脏页比例超过70%,则把100个脏页刷新到disk,否则只刷新10个脏页

srv_main_thread_op_info = "flushing buffer pool pages";

/* Flush a few oldest pages to make a new checkpoint younger */

if (buf_get_modified_ratio_pct() > 70) {

    /* If there are lots of modified pages in the buffer pool
    (> 70 %), we assume we can afford reserving the disk(s) for
    the time it requires to flush 100 pages */

    n_pages_flushed = buf_flush_list(
        PCT_IO(100), IB_ULONGLONG_MAX);
} else {
    /* Otherwise, we only flush a small number of pages so that
    we do not unnecessarily use much disk i/o capacity from
    other work */

    n_pages_flushed = buf_flush_list(
          PCT_IO(10), IB_ULONGLONG_MAX);
}

 

5)创建新的checkpoint

srv_main_thread_op_info = "making checkpoint";

/* Make a new checkpoint about once in 10 seconds */

log_checkpoint(TRUE, FALSE);

 

innodb master主线程

标签:

原文地址:http://www.cnblogs.com/taek/p/4736111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!