Slow performance MySql

后端 未结 2 1121
庸人自扰
庸人自扰 2020-12-06 15:45

I\'m trying out performance of a system I\'m building, and it\'s really slow, and I don\'t know why or if it should be this slow. What I\'m testing is how many single INSERT

2条回答
  •  难免孤独
    2020-12-06 16:28

    Like it's explained in the comments, it's InnoDB to blame. By default this engine is too cautious and doesn't utilize the disk cache, to make sure that data indeed has been written on disk, before returning you a success message. So you basically have two options.

    1. Most of time you just don't care for the confirmed write. So you can configure mysql by setting this mysql option to zero:

      innodb_flush_log_at_trx_commit = 0
      

      as long as it's set this way, your InnoDB writes will be almost as fast as MyISAM.

    2. Another option is wrapping all your writes in a single transaction. As it will require only single confirmation from all the writes, it will be reasonable fast too.

    Of course, it's just sane to prepare your query only once with multiple inserts but the speed gain is negligible compared to the issue above. So it doesn't count neither as an explanation nor as a remedy for such an issue.

提交回复
热议问题