Mysql Slow Insert

后端 未结 6 613
别那么骄傲
别那么骄傲 2021-02-07 22:17

I have the following InnoDB table:

+-----------+-----------+------+-----+-------------------+----------------+
| Field     | Type      | Null | Key | Default             


        
6条回答
  •  独厮守ぢ
    2021-02-07 23:17

    Sometimes it is not the query itself which causes a slowdown - another query operating on the table can easily cause inserts to slow down due to transactional isolation and locking. Your slow queries might simply have been waiting for another transaction(s) to complete. This is fairly common on a busy table, or if your server is executing long/complex transactions.

    Another significant factor will be the overall performance of your database: how your my.cnf file is tuned, how the server itself is tuned, what else the server has running on it, and of course, what hardware the server is running.

    The linux tool mytop and the query SHOW ENGINE INNODB STATUS\G can be helpful to see possible trouble spots. General linux performance tools can also show how busy your disks are, etc.

    Given the nature of this table, have you considered an alternative way to keep track of who is online? In MySQL, I have used a MEMORY table for such purposes in the past. A NoSQL data store might also be good for this type of information. Redis could store this as a sorted set with much success (score == timestamp).

    Further reading:

    • http://dev.mysql.com/doc/refman/5.1/en/innodb-tuning.html
    • http://dev.mysql.com/doc/refman/5.1/en/memory-storage-engine.html
    • http://redis.io/commands#sorted_set

提交回复
热议问题