1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
void master_thread() { int innodb_io_capacity = 200 ;//表示磁盘IO吞吐量 int innodb_max_dirty_pages_pct = 75 ;//最大脏页百分比 goto loop; loop: //1秒循环 for(int i = o; i<10; i++) { thread_sleep(1);//innodb 优化,压力大时不总是等待1秒 //日志缓冲刷新到磁盘 do log buffer flush to disk; //如果磁盘压力小,合并插入缓冲 if ( last_one_second_ios < innodb_io_capacity*5% ) { do merge at most innodb_io_capacity*5% insert buffer; } //判断脏页比例 if ( buf_get_modified_ratio_pct > innodb_max_dirty_pages_pct ) { do buffer pool flush innodb_io_capacity*100% dirty page; } //如果开启自适应刷新,通过判断产生重做日志的速度来判断合适的刷新脏页数量 else if enable adaptive flush { do buffer pool flush desired amount dirty page; } //如果无用户活动,切换到 backgroud loop if ( no user activity ) { goto backgroud loop; } } //10秒循环 //如果磁盘压力小,刷新innodb_io_capacity*100%的脏页到磁盘 if ( last_ten_second_ios < innodb_io_capacity ) { do buffer pool flush innodb_io_capacity*100% dirty page; } //合并插入缓冲 do merge at most innodb_io_capacity*5% insert buffer; //日志缓冲刷新到磁盘 do log buffer flush to disk; //删除无用undo页,每次最多删除20个undo页 do full purge; //判断脏页比例 if ( buf_get_modified_ratio_pct >70% )//--------- { do buffer pool flush innodb_io_capacity*100% dirty page; } else { do buffer pool flush innodb_io_capacity*10% dirty page; } //产生一个模糊检查点,只是将最老日志序列号的页写入磁盘 do fuzzy checkpoint; goto loop; //backgroud backgroud loop: //删除无用undo页 do full purge; //合并插入缓冲 do merge innodb_io_capacity*100% insert buffer; //不空闲跳回主循环,空闲则进入flush loop if not idle { goto loop; } else { goto flush loop; } //flush loop flush loop: //不断刷新脏页到磁盘,直到脏页比例小于innodb_max_dirty_pages_pct,则进入suspend loop do buffer pool flush innodb_io_capacity*100% dirty page; while ( buf_get_modified_ratio_pct > innodb_max_dirty_pages_pct ); goto suspend loop; //suspend loop suspend loop: suspend_thread(); waiting event; goto loop; } |