mysql:insert插入數據過慢如何解決,設置innodb_flush_log_at_trx_commit為0就能解決


問題:

最近在做性能測試,造數據,發現insert好慢,只有幾十條每秒,很奇怪,最后再網上找到了原因。

網文如下:

MY SQL insert 速度過慢
最近在用MySQL做存儲,測試中發現插入數據太慢了,插入速度只有20-30 條/秒,后來查資料后,將MySQL的1個參數:innodb_flush_log_at_trx_commit,1改為了0(修改方法,可以直接修改my.ini(windows)/my.cnf(linux)中的對應參數,似乎用命令直接設置沒有效果),插入速度就提升到了3000+每S,MySQL的文檔中,對這個參數的描述如下:
If the value of innodb_flush_log_at_trx_commit is 0, the log buffer is written out to the log file once per second and the flush to disk operation is performed on the log file, but nothing is done at a transaction commit. When the value is 1 (the default), the log buffer is written out to the log file at each transaction commit and the flush to disk operation is performed on the log file. When the value is 2, the log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it. However, the flushing on the log file takes place once per second also when the value is 2. Note that the once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues. 

這樣,如果transaction commit的頻率非常高,1秒鍾內會進行很多次的話,可以考慮將其設置為0,但這樣就要承擔數據庫Crash后,1秒內未存儲到數據庫數據丟失可能的風險


設置后重啟mysql,再重新執行存儲過程,基本上插入速度能達到6000條/s。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM