时间:2021-07-01 10:21:17 帮助过:2人阅读
第一分钟
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主线程
标签: