Group commit and real fsync
分組提交和即時fsync
During the recent months I’ve seen few cases of customers upgrading to MySQL 5.0 and having serious performance slow downs, up to 10 times in certain cases. What was the most surprising for them is the problem was hardware and even OS specific - it could show up with one OS version but not in the other. Even more interesting performance may be dramatically affected by –log-bin settings, which usually has just couple of percent overhead. So what is going on?
最近這幾個月,我已經碰到少數幾個案例:一些客戶升級到 MySQL 5.0,結果效能嚴重下降,某些特定情況下甚至達到10倍以下。然而令他們最為驚訝的是,產生這些問題竟然是由於硬體甚至是作業系統 -- 在某個版本的作業系統上存在這些問題但在其他版本則沒有。更有趣的是,MySQL 的效能竟然戲劇性地受到 log-bin 設定的影響 -- 這通常只是對系統效能有 2% 的影響。那麼,到底發生什麼事了呢?
Actually we’re looking at two issues here which interleave such funny way
讓我們來找找這2個有趣的問題中交叉的地方吧:
Group commit is broken in MySQL 5.0 if binary loging is enabled (as it enables XA) 在 MySQL 5.0 中如果啟用二進位日誌(binary log)(啟用XA也是如此),則分組提交中斷了 Certain OS/Hardware configurations still fake fsync delivering great performance at the cost of being non ACID 某些作業系統/硬體設定仍舊只是實現了偽 fsync,由於它是 非ACID,結果導致大量的效能損失
First one can be tracked by this bug. In the nutshell the problem is - new feature - XA was implemented in MySQL 5.0 which did not work with former group commit code. The new code for group commit however was never implemented. XA allows to keep different transactonal storage engines in sync, together with binary log. XA is enabled if binary log is enabled this is why this issue is trigered by enabled binary log. if binary log is disabled, so is XA and old group commit code works just fine.
第一個問題可以查看 這個bug。概括地說,這個問題是新特性 -- MySQL 5.0 中新增加了 XA 特性,它不支援舊的分組提交代碼。然而新的分組提交代碼還完全沒實現。XA 支援讓不同的事務性儲存引擎保持同步,都儲存在二進位日誌中。如果啟用了二進位日誌,則 XA 也啟用了,這就是為什麼啟用二進位日之後會觸發這個問題。如果禁用二進位日誌,則 XA 和舊的分組提交代碼就都沒問題了。
Second one is interesting. Actually we would hear much more people screaming about this problem if OS would be honest with us. Happily for us many OS/Hardware pairs are still lying about fsync(). fsync() call suppose to place data on the disk securely, which unless you have battery backed up cache would give you only 80-200 sequential fsync() calls per second depending on your hard drive speed. With fake fsync() call the data is only written to the drives memory and so can be lost if power goes down. However it gives great performance improvement and you might see 1000+ of fsync() calls per second. So if your OS is not giving you real fsync you might not notice this bug. The performance degradation will still happen but it will be much smaller, especially with large transactions.
第二個問題很有趣。事實上如果作業系統更加誠實的話,我們將會聽到更多的使用者的抱怨。幸好,對我們來說,不少作業系統/硬體組合還是基於 fsync() 之上。fsync() 調用假使安全地把資料放在磁碟中,除非有備用電池快取依賴於磁碟的驅動速度才只能達到每秒 80 - 200 次連續的 fsync() 調用。而偽 fsync() 則只是把資料寫在磁碟記憶體中,一旦斷電了,這些資料就會丟失了。不過這麼做能獲得很高效能,大約能達到每秒有1000多次的 fsync() 調用。因此,如果你的作業系統不支援即時 fsync() 調用,就要注意這個bug。效能會被降低,不過這會越來越少,尤其是在很大的事務過程中。