MasterThread of InnoDB Storage Engine

Source: Internet
Author: User
The main work of the InnoDB Storage engine is completed in a separate background thread MasterThread. 1. MasterThreadMasterThread before InnoDB1.0.x has the highest thread priority. It consists of multiple loops: Main loop, backgrouploop, flushloop, and pause loop (s ).

The main work of the InnoDB Storage engine is completed in a separate background Thread Master Thread. 1. The Master Thread before InnoDB 1.0.x has the highest Thread priority. It consists of multiple loops: Main loop, backgroup loop, flush loop, and pause loop (s ).

The main work of the InnoDB Storage engine is completed in a separate background Thread Master Thread.
1. Master Thread before InnoDB 1.0.x

Master threads have the highest priority. It consists of multiple loops: Main loop, backgroup loop, flush loop, and suspend loop ). The Master Thread switches between the above four states based on the database running status. Loop is called the main Loop, because most operations are in this Loop, there are two major operations: operations per second and operations per 10 seconds. The pseudocode is as follows:


We can see that the loop is implemented through thread sleep, which means that the so-called operation once per second or every 10 seconds is not accurate. There may be latency when the load is high. It can only be said at this frequency. Of course, InnoDB source code also uses other methods to ensure this frequency as much as possible.
Operations per second:
A. The log buffer is refreshed to the disk, even if the transaction has not been committed (always );
Even if I have not submitted a redo log, the InnoDB Storage engine will refresh the content in the redo log buffer to the redo log file every second. This can explain why another large transaction commit takes a short time.
B. Merge insert buffering (possible );
Insert Buffer does not occur every second. The InnoDB Storage engine determines whether the number of I/O operations in the current second is less than 5. If the number is less than 5, InnoDB considers that the current I/O pressure is low and can merge and insert buffering operations.
C. Refresh dirty pages in the buffer pool of up to 100 InnoDB to the disk (possibly );
The InnoDB Storage engine determines whether the ratio of dirty pages (buf_get_modified_ratio_pct) in the Current Buffer Pool exceeds the value of innodb_max_dirty_pages_pct in the configuration file. If the value exceeds this threshold, the InnoDB Storage engine considers that Disk Synchronization is required and writes 100 dirty pages to the disk.
D. If no user activity exists, switch to background loop (possibly );
Operations per 10 seconds:
A. Refresh 100 dirty pages to the disk (possibly );
B. Merge up to five insert buffers (always );
C. Refresh the log buffer to the disk (always );
D. Delete useless Undo pages (always );
E. Refresh 100 or 10 dirty pages to the disk (always );
In the above process, the InnoDB Storage engine first checks whether the disk I/O operations in the past 10 seconds are less than 200 times. If yes, the InnoDB Storage engine considers that there is sufficient disk I/O operation capability, so it refreshes 100 dirty pages to the disk. Next, the InnoDB Storage engine merges the insert buffer, which is different from the merge insert buffer operation that may occur once an operation per second. This merge insert buffer will always be performed. After that, the InnoDB Storage engine will refresh the log to the disk once. This is the same as the operation that occurs once per second. In the next step, the InnoDB Storage engine will perform the full purge operation to delete useless Undo pages. During the full purge process, the InnoDB Storage engine determines whether the row deleted in the current transaction system can be deleted. If yes, InnoDB immediately deletes the row. At most 20 undo pages can be recycled at a time. The InnoDB Storage engine then determines that if there are more than 70% dirty pages in the dirty pages of the buffer pool, 100 dirty pages will be refreshed to the disk. If the proportion is less than 70%, you only need to refresh the 10% dirty pages to the disk.
If there is no user activity (when the huge amount of money is idle) or the database is shut down, it will switch to this loop. Background loZ environment? http://www.2cto.com/kf/ware/vc/ "Target =" _ blank "class =" keylink "> vcLvhu + HWtNDQ0tTPwrLZ1/keys + s/keys + keys/M9bz + KL/keys + keys + release/release + Wz2M/release/cfmttS0xcXMSU + release + a1xL3pydzAtL + release/release + 8 rHsvrJ + rTz09oyMLj2suXI67u6s + W1xMfpv/release + release release + release/release + tMXFzElPtcTNzM3Cwb + release + XH + release/release + 9q7y4v + m0xcXM1/release/L2bbIysejrL/ keys + keys + cores/w + cores/K/cores/a3qMrHzai5/cXQts + y + cores + HLotDC0ru2qMG/tctunk4zoam8yni + cores/tM69 + export/fKsaOs1 + export + qyrzS/cjrss7K/export/ydluv9export xso/export/cG/o6zErMjPMjCho7/export/J0tSy6b + export + ioaPI58/export =" http://img.blog.csdn.net/20141209120143421 "Alt =" \ ">

As shown in the figure, the main loop is performed 1154432 times, the sleep operation is performed 1154432 times per second, the activity is performed 106465 times per second, and the background loop is performed 90829 times, flush loop performed 90829 times.
3. InnoDB 1.2.x Master Thread
In InnoDB 1.2.x, the pseudo code of the Master Thread is as follows:
System concurrency.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.