sync_binloghtml
Command-Line Formatmysql |
--sync-binlog=#sql |
|
Option-File Format緩存 |
sync_binlog安全 |
|
System Variable Nameapp |
sync_binlogless |
|
Variable Scopeasync |
Global函數 |
|
Dynamic Variable性能 |
Yes |
|
|
Permitted Values |
|
Platform Bit Size |
32 |
|
Type |
numeric |
|
Default |
0 |
|
Range |
0 .. 4294967295 |
|
|
Permitted Values |
|
Platform Bit Size |
64 |
|
Type |
numeric |
|
Default |
0 |
|
Range |
0 .. 18446744073709547520 |
sync_binlog參數說明:
當sync_binlog是控制事務寫入二進制日誌的方式。若是設置大於0,則達到sync_binlog設置的值一組事務同步寫入到二進制日誌;若是設置爲0,則每當事務發生,在內存中的事務信息,不是同步刷到磁盤,而是依賴於操做系統時常刷新到磁盤;當設置爲1,則是更安全的選項,當宕機後,最多失去1個事務的信息,可是性能確實最慢的。
innodb_flush_log_at_trx_commit
Command-Line Format |
--innodb_flush_log_at_trx_commit[=#] |
|
Option-File Format |
innodb_flush_log_at_trx_commit |
|
System Variable Name |
||
Variable Scope |
Global |
|
Dynamic Variable |
Yes |
|
|
Permitted Values |
|
Type |
enumeration |
|
Default |
1 |
|
Valid Values |
0 |
|
1 |
||
2 |
Controls the balance between strict ACID compliance for commit operations, and higher performance that is possible when commit-related I/O operations are rearranged and done in batches. You can achieve better performance by changing the default value, but then you can lose up to one second worth of transactions in a crash.
For durability and consistency in a replication setup that uses InnoDB with transactions:
Caution
Many operating systems and some disk hardware fool the flush-to-disk operation. They may tell mysqld that the flush has taken place, even though it has not. Then the durability of transactions is not guaranteed even with the setting 1, and in the worst case a power outage can even corrupt InnoDBdata. Using a battery-backed disk cache in the SCSI disk controller or in the disk itself speeds up file flushes, and makes the operation safer. You can also try using the Unix command hdparm to disable the caching of disk writes in hardware caches, or use some other command specific to the
innodb_flush_log_at_trx_commit參數說明:
innodb_flush_log_at_trx_commit=1,徹底尊周ACID事務的原則,每提交一次,log buffer中的日誌刷新到log file的文件緩存,而後在刷新到磁盤。這種的性能最差。當innodb_flush_log_at_trx_commit=0的時候,當mysqld宕掉的時候,會丟失一秒的事務,每1秒log buffer中的日誌會先寫到log file的文件緩存,而後經過操做系統調度,時常刷新到磁盤。當爲innodb_flush_log_at_trx_commit=2,會丟失一秒的事務,每次提交log buffer的日誌會寫到日誌文件緩存,日誌文件緩存中的日誌刷新到磁盤則是每秒鐘發生。
參數 |
值 |
Sync_binlog |
100 |
Innodb_flush_log_at_trx_commit |
2 |
Innodb_buffer_pool_size |
3.5G |
Innodb_log_file_size |
300 |
這次插入4247160條記錄,花了時間大概爲244秒。
參數 |
值 |
Sync_binlog |
1 |
Innodb_flush_log_at_trx_commit |
1 |
Innodb_buffer_pool_size |
3.5G |
Innodb_log_file_size |
300 |
插入4247160條記錄花了290秒。不一樣的參數配置插入相同數據量,相差了46秒的時間。
相關的文件以及函數:
源文件:/sql/binlog.cc
相關函數:
std::pair<bool, bool> sync_binlog_file(bool force);
int ordered_commit(THD *thd, bool all, bool skip_commit = false);