简体   繁体   中英

innoDB - should i turn innodb_flush_log_at_trx_commit off?

I have a database table that has 100s of thousands of rows. Entering a new row or updating a row takes a little bit of time. To do 50 updates (in the format of update table set field = 1234 where id = 5678; update table set field = 912 where id = 582; ... ) it can take 4 or 5 seconds.

How can i reduce this time? Is it worth playing with the innodb_flush_log_at_trx_commit setting? How can I set that setting just for certain connections/queries?

Is it safe to play with innodb_flush_log_at_trx_commit ? The data isn't important, as long as one copy (either before the UPDATE command or after) is in tact (it is only setting some somewhat random data updates... no important data gets changed in these queries)

the bulk of the queries on this tables are SELECT so that is why i use innodb.

thanks

Yes, it is safe to change innodb_flush_log_at_trx_commit. The effect of changing it from 1 (the default) to 0 or 2 is that log writes will happen about one per second instead of one per commit. In other words, right now your 50 updates are causing 50 fsyncs (assuming you are using autocommit). You could change that to 1 fsync per second.

But you could also get a similar effect by not using autocommit, and instead wrapping the 50 updates in an explicit transaction:

  1. Start a transaction, which temporarily disables autocomit.
  2. Run 50 updates.
  3. Commit.

This will result in 1 fsync at commit time (plus the 1 fsync per second that is always done regardless of the config). This might be enough to improve your throughput.

All that said, I wouldn't think 50 fsyncs requires 5 seconds on any system, unless you have extraordinarily crappy hard drives or the server is also loaded with a lot of other traffic.

You should also make sure the updates are benefiting from an index. I could assume id is the primary key of the table, and therefore it's the clustered index. But I'd want to confirm that. Can you run SHOW CREATE TABLE <tablename> and post the output in an edit of your question above?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM