Home Database Mysql Tutorial InnoDB存储引擎之MasterThread

InnoDB存储引擎之MasterThread

Jun 07, 2016 pm 04:12 PM
innodb storage engine

InnoDB存储引擎的主要工作都是在一个单独的后台线程Master Thread中完成的。 1.InnoDB 1.0.x版本之前的Master Thread Master Thread具有最高的线程优先级别。其内部由多个循环组成:主循环(loop)、后台循环(backgroup loop)、刷新循环(flush loop)、暂停循环(s

InnoDB存储引擎的主要工作都是在一个单独的后台线程Master Thread中完成的。
1.InnoDB 1.0.x版本之前的Master Thread

Master Thread具有最高的线程优先级别。其内部由多个循环组成:主循环(loop)、后台循环(backgroup loop)、刷新循环(flush loop)、暂停循环(suspend loop)。Master Thread会根据数据库运行的状态在上述4状态下进行切换。Loop被称为主循环,因为大多数的操作是在这个循环中,其中有两大部分的操作:每秒的操作和每10秒的操作。伪代码如下:

\

可以看到,loop循环通过thread sleep来实现,这意味着所谓的每秒一次或者每10秒一次的操作是不精确的。在负载很高的情况可能会有延迟,只能说大概在这个频率下。当然InnoDB源代码中还通过其他的方法来尽量保证这个频率。
每秒一次的操作:
a.日志缓冲刷新到磁盘,即使这个事务还没有提交(总是);
即使某个是我还没有提交,InnoDB存储引擎仍然每秒会将重做日志缓冲中的内容刷新到重做日志文件。这就可以解释为什么再大的事务提交的时间也很短。
b.合并插入缓冲(可能);
合并插入缓冲(Insert Buffer)并不是每秒都会发生。InnoDB存储引擎会判断当前一秒内发生的IO次数是否小于5次,如果小于5次,InnoDB认为当前的IO压力很小,可以执行合并插入缓冲的操作。
c.至多刷新100个InnoDB的缓冲池中的脏页到磁盘(可能);
InnoDB存储引擎通过判断当前缓冲池中脏页的比例(buf_get_modified_ratio_pct)是否超过了配置文件中innodb_max_dirty_pages_pct这个参数的值,如果超过了这个阀值,InnoDB存储引擎认为需要做磁盘同步操作,将100个脏页写入磁盘。
d.如果当前没有用户活动,则切换到background loop(可能);
每10秒的操作:
a.刷新100个脏页到磁盘(可能);
b.合并至多5个插入缓冲(总是);
c.将日志缓冲刷新到磁盘(总是);
d.删除无用的Undo页(总是);
e.刷新100个或者10个脏页到磁盘(总是);
在以上的过程中,InnoDB存储引擎会先判断过去10秒内磁盘的IO操作是否小于200次,如果是,InnoDB存储引擎认为当前有足够的磁盘IO操作能力,因此将100个脏页刷新到磁盘。接着,InnoDB存储引擎会合并插入缓冲,不同于每秒一次操作时可能发生的合并插入缓冲操作,这次的合并插入缓冲总是会进行。之后InnoDB存储引擎会在进行一次将日志刷新到磁盘。这和每秒一次时发生的操作是一样的。在接下来InnoDB存储引擎会执行full purge操作,即删除无用的Undo页。在full purge过程中,InnoDB存储引擎会判断当前事务系统中已被删除的行是否可以删除,如果可以,则InnoDB会立即将其删除。每次最多尝试回收20个undo页。然后,InnoDB存储引擎会判定缓冲池中脏页的比列如果有超过70%的脏页,则刷新100个脏页到磁盘。如果比例小于70%则只需要刷新10%的脏页到磁盘。
若当前没有用户活动(上巨款空闲时)或者数据库关闭(shutdown),就会切换到这个循环。background loZ喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcLvhu+HWtNDQ0tTPwrLZ1/c6PGJyPgogICAgICAgICAgICBhLsm+s/3O3tPDtcRVbmRv0rMo19zKxyk7PGJyPgogICAgICAgICAgICBiLrrPsqIyMLj2suXI67u6s+Uo19zKxyk7PGJyPgogICAgICAgICAgICBjLsz4u9i1vdb30a27tyjX3MrHKTs8YnI+CiAgICAgICAgICAgIGQusru2z8ui0MIxMDC49tKz1rG1vbf7us/M9bz+KL/JxNwszPjXqrW9Zmx1c2ggbG9vcNbQzeqzySk7PGJyPgogICAgICAgIMj0Zmx1c2ggbG9vcNbQw7vKssO0ysLH6b/J0tTX9qOsSW5ub0RCtOa0otL9x+a74cfQu7u1vXN1c3BlbmQgbG9vcKOsvatNYXN0ZXIgVGhyZWFkudLG8KOstci0/cqxvOS1xLeiyfqho8j008O7p8b008MoZW5hYmxlKcHLSW5ub0RCtOa0otL9x+ajrMi0w7vT0Mq508PIzrrOSW5ub0RCtOa0otL9x+a1xL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XE1/a3qMrHzai5/cXQts+y+sn61tjX9sjV1r61xMvZtsjAtL72tqjX7rrPysq1xMui0MLU4NKzyv3Bv6Gj0vK0y6OstbHU4NKztcSxyMHQ0KHT2mlubm9kYl9tYXhfZGlydHlfcGFnZXNfcGN0yrGjrNKyu+HLotDC0ru2qMG/tcTU4NKzoaM8YnI+CjxwPiAgICAgICAgu7nT0NK7uPa4xLHkysc61q7HsMO/tM69+NDQZnVsbCBwdXJnZbLZ1/fKsaOs1+624LvYytUyMLj2VW5kb9KzoaO000lubm9EQjEuMC54sOaxvr+qyrzS/cjrss7K/Wlubm9kYl9wdXJnZV9iYXRjaF9zaXplo6y4w7LOyv2/ydLUv9jWxsO/tM5mdWxsIHB1cmdlu9jK1bXEVW5kb9KztcTK/cG/o6zErMjPMjCho7/J0tS2r8ystcS21MbkvfjQ0NDeuMSho82ouf3D/MHuc2hvdyBlbmdpbmUgaW5ub2RiIHN0YXR1c7/J0tSy6b+0tbXG2k1hc3RlciBUaHJlYWS1xNe0zKzQxc+ioaPI58/Czbw6PC9wPgo8cD48aW1nIHNyYz0="http://img.blog.csdn.net/20141209120143421" alt="\">
有图可知,主循环进行了1154432次,每秒挂起(sleep)的操作进行了1154432次,10秒一次的活动进行了106465次,background loop进行了90829次,flush loop进行了90829次。
3.InnoDB 1.2.x版本的Master Thread
InnoDB 1.2.x版本中,Master Thread的伪代码如下:
n?緁贻?ez脂捦t不鎗薧r丿z脂捗沧玁辤于佮┺?kyj薧?ky喎?http://www.2cto.com/os/系统的并发性。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Huawei will launch innovative MED storage products next year: rack capacity exceeds 10 PB and power consumption is less than 2 kW Mar 07, 2024 pm 10:43 PM

This website reported on March 7 that Dr. Zhou Yuefeng, President of Huawei's Data Storage Product Line, recently attended the MWC2024 conference and specifically demonstrated the new generation OceanStorArctic magnetoelectric storage solution designed for warm data (WarmData) and cold data (ColdData). Zhou Yuefeng, President of Huawei's data storage product line, released a series of innovative solutions. Image source: Huawei's official press release attached to this site is as follows: The cost of this solution is 20% lower than that of magnetic tape, and its power consumption is 90% lower than that of hard disks. According to foreign technology media blocksandfiles, a Huawei spokesperson also revealed information about the magnetoelectric storage solution: Huawei's magnetoelectronic disk (MED) is a major innovation in magnetic storage media. First generation ME

Vue3+TS+Vite development skills: how to encrypt and store data Vue3+TS+Vite development skills: how to encrypt and store data Sep 10, 2023 pm 04:51 PM

Vue3+TS+Vite development tips: How to encrypt and store data. With the rapid development of Internet technology, data security and privacy protection are becoming more and more important. In the Vue3+TS+Vite development environment, how to encrypt and store data is a problem that every developer needs to face. This article will introduce some common data encryption and storage techniques to help developers improve application security and user experience. 1. Data Encryption Front-end Data Encryption Front-end encryption is an important part of protecting data security. Commonly used

How to clear cache on Windows 11: Detailed tutorial with pictures How to clear cache on Windows 11: Detailed tutorial with pictures Apr 24, 2023 pm 09:37 PM

What is cache? A cache (pronounced ka·shay) is a specialized, high-speed hardware or software component used to store frequently requested data and instructions, which in turn can be used to load websites, applications, services, and other aspects of the system faster part. Caching makes the most frequently accessed data readily available. Cache files are not the same as cache memory. Cache files refer to frequently needed files such as PNGs, icons, logos, shaders, etc., which may be required by multiple programs. These files are stored in your physical drive space and are usually hidden. Cache memory, on the other hand, is a type of memory that is faster than main memory and/or RAM. It greatly reduces data access time since it is closer to the CPU and faster compared to RAM

Git installation process on Ubuntu Git installation process on Ubuntu Mar 20, 2024 pm 04:51 PM

Git is a fast, reliable, and adaptable distributed version control system. It is designed to support distributed, non-linear workflows, making it ideal for software development teams of all sizes. Each Git working directory is an independent repository with a complete history of all changes and the ability to track versions even without network access or a central server. GitHub is a Git repository hosted on the cloud that provides all the features of distributed revision control. GitHub is a Git repository hosted on the cloud. Unlike Git which is a CLI tool, GitHub has a web-based graphical user interface. It is used for version control, which involves collaborating with other developers and tracking changes to scripts and

How MySQL sees InnoDB row format from binary content How MySQL sees InnoDB row format from binary content Jun 03, 2023 am 09:55 AM

InnoDB is a storage engine that stores data in tables on disk, so our data will still exist even after shutdown and restart. The actual process of processing data occurs in memory, so the data in the disk needs to be loaded into the memory. If it is processing a write or modification request, the contents in the memory also need to be refreshed to the disk. And we know that the speed of reading and writing to disk is very slow, which is several orders of magnitude different from reading and writing in memory. So when we want to get certain records from the table, does the InnoDB storage engine need to read the records from the disk one by one? The method adopted by InnoDB is to divide the data into several pages, and use pages as the basic unit of interaction between disk and memory. The size of a page in InnoDB is generally 16

what is mysql innodb what is mysql innodb Apr 14, 2023 am 10:19 AM

InnoDB is one of the database engines of MySQL. It is now the default storage engine of MySQL and one of the standards for binary releases by MySQL AB. InnoDB adopts a dual-track authorization system, one is GPL authorization and the other is proprietary software authorization. InnoDB is the preferred engine for transactional databases and supports transaction security tables (ACID); InnoDB supports row-level locks, which can support concurrency to the greatest extent. Row-level locks are implemented by the storage engine layer.

How to correctly use sessionStorage to protect sensitive data How to correctly use sessionStorage to protect sensitive data Jan 13, 2024 am 11:54 AM

How to correctly use sessionStorage to store sensitive information requires specific code examples. Whether in web development or mobile application development, we often need to store and process sensitive information, such as user login credentials, ID numbers, etc. In front-end development, using sessionStorage is a common storage solution. However, since sessionStorage is browser-based storage, some security issues need to be paid attention to to ensure that the stored sensitive information is not maliciously accessed and used.

Engine landscape changes: Three-cylinder engines challenge the dominance of six-cylinders and eight-cylinders Engine landscape changes: Three-cylinder engines challenge the dominance of six-cylinders and eight-cylinders Oct 08, 2023 pm 10:57 PM

According to news on October 8, the U.S. auto market is undergoing a change under the hood. The previously beloved six-cylinder and eight-cylinder power engines are gradually losing their dominance, while three-cylinder engines are emerging. News on October 8 showed that the U.S. auto market is undergoing a change under the hood. The beloved six-cylinder and eight-cylinder power engines in the past are gradually losing their dominance, and the three-cylinder engine is beginning to emerge. In most people's minds, Americans love large-displacement models, and the "American big V8" has always been the Synonymous with American cars. However, according to data recently released by foreign media, the landscape of the U.S. auto market is undergoing tremendous changes, and the battle under the hood is intensifying. It is understood that before 2019, the United States

See all articles