Mysql binary log polling and innodb write Optimization

Source: Internet
Author: User
Innodb_buffer_pool_size if Innodb is used, this is an important variable. Compared with MyISAM, Innodb is more sensitive to buffersize. MySIAM may also use the default key_buffer_size for large data volumes, but Innodb will feel crawling when using the default value for large data volumes. The Innodb buffer pool caches data and indexes.

Innodb_buffer_pool_size
If Innodb is used, this is an important variable. Compared with MyISAM, Innodb is more sensitive to buffer size. MySIAM may also use the default key_buffer_size for large data volumes, but Innodb will feel crawling when using the default value for large data volumes. The Innodb buffer pool caches data and indexes, so you do not need to leave space for the system cache. If you only use Innodb, you can set this value to 70%-80% of the memory. Similar to key_buffer, if the data volume is small and does not increase much, do not set this value too high or increase the memory usage.

Innodb_aDdItional_pool_size
This effect is not very obvious, at least when the operating system can reasonably allocate memory. However, you may still need to set it to 20 MB or more to see how much memory Innodb will allocate for other purposes.

Innodb_log _File_ Size
It is very important to write a lot, especially when there is a large amount of data. Note that large files provide higher performance, but it takes more time to recover the database. I usually use 64 M-512 M, depending on the server space.

Innodb_log_buffer_size
The default value can be used for most moderate write operations and short transactions. If you often update or use a lot of blob data, you should increase this value. But it is a waste of memory because it will always flush in one second ?) Once, so you do not need to set it to more than 1 second. 8-16 m should be enough. A smaller application can be used.

Innodb_flush_log_at _TrX_commit (this is useful)
Why is Innodb 100 times slower than MyISAM? You probably forgot to adjust this value. The default value 1 indicates that logs need to be written to the hard disk (flush) for each transaction commit or non-transactional command. This is time-consuming. Battery backEdUp cache. Set to 2 is applicable to many applications, especially the conversion from the MyISAM table. It means writing data to the system cache instead of writing data to the hard disk. Logs are flushed to hard disks per second, so you will not lose updates that exceed 1-2 seconds. Setting 0 is faster, but the security is poor. Even if MySQL fails, the transaction data may be lost. Value 2 can only lose data when the entire operating system is down.

 

The above is viewed on the Internet. I found that there are a lot of up logs in the slow query.DateFor the insert query, innodb_flush_log_at_trx_commit is changed to 2. The effect is obvious. It is more obvious to change it to 0, but the security is relatively poor. Follow these steps to start mysqld:

Vim/etc/my. cnf

Innodb_flush_log_at_trx_commit = 2

 

You can also run the following command at mysqld:

SetGLOBAL innodb_flush_log_at_trx_commit = 2

 

The following is an explanation of innodb_flush_log_at_trx_commit In the mysql manual:

If innodb_flush_log_at_trx_commit is set to 0, log buffer writes data to log file once a second, and flush (flush to disk) operations of log file are performed simultaneously. However, in this mode, when a transaction is committed, there will be no action. If innodb_flush_log_at_trx_commit is set to 1 (default), log buffer writes the log file to the disk for each transaction commit and flush the data to the disk. If innodb_flush_log_at_trx_commit is set to 2, log buffer writes the log file every time a transaction is committed. However, flush (flush to disk) operations are not performed at the same time. In this mode, MySQL flush (flush to disk) operations every second. Note: Due to the process scheduling policy, this "flush (flush to disk) operation once per second" does not guarantee 100% "per second ".

The default value 1 is for ACID (atomicity, consisteNcY, isolation,DuRability) Atomic, consistency, isolation and persistence considerations. If you do not set innodb_flush_log_at_trx_commit to 1, you will get better performance. However, when the system crashes, you may lose up to one second of transaction data. When you set innodb_flush_log_at_trx_commit to 0, the crash of the mysqld process will lead to the loss of all transaction data in the last second. If you set innodb_flush_log_at_trx_commit to 2, all transaction data may be lost in the last second only when the operating system crashes or the system powers down. The crash recovery mechanism of InnoDB is not affected by this value. No matter how much this value is set, the crash recovery mechanism will work.

 

 

In addition, the innodb_flush_method parameter is also worth noting and has an impact on write operations:

Innodb_flush_method: sets the InnoDB synchronous IO method:

1) Default-use fSync().
2) O_SYNC is usually slow to open files in sync mode.
3) O_DIRECT: Use Direct IO on Linux. This can significantly increase the speed, especially on RAID systems. Avoid extra data replication and double buffering (mysql buffering and OS buffering ).

 

Mysql binary round robin:

Vi/etc/my. cnf

ExPire-logs-days = 7

In this way, mysql will automatically delete binary logs that have been generated for more than 7 days.

You can use the purge master logs to manually delete the LOGS. The following information is displayed on the Internet:

Purge master logs syntax
PURGE {MASTER | BINARY} logs to 'Log _ name'
PURGE {MASTER | BINARY} logs before 'date'
Deletes all binary logs listed in the log index before the specified log or date. These logs will also be deleted from the list of records in the log index file, so that the given log becomes the first.
For example:
Purge master logs to 'mysql-bin.010 ';
Purge master logs before '2017-04-02 22:46:26 ';
The date argument for the BEFORE variable can be in the 'yyyy-MM-DD hh: mm: ss' format. Both MASTER and BINARY are synonyms.
If you have an active slave server that is currently reading one of the logs you are trying to delete, this statement does not work, but fails with an error. However, if the slave server is slave and you happen to have cleared one of the logs it wants to read, the slave server cannot be copied after it is started. This statement can be run safely when the slave server is being copied.

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.