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秒的操作。伪代码如下:
每秒一次的操作:
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+a1xLHto6zEx8O0TWFzdGVyIFRocmVhZNfcyse0ptPaudLG8LXE17TMrKGjPGJyPgogICAgMi5Jbm5vREIgMS4yLniw5rG+1q7HsLXETWFzdGVyIFRocmVhZDxicj4KICAgICAgICDU2klubm9EQjEuMC54sOaxvtaux7CjrElubm9EQrTmtKLS/cfmttTT2klPxuTKtcrH09DP3rXEo6zU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gICAgu7nT0NK7uPa4xLHkysc61q7HsMO/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的伪代码如下:


MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
