Mysql:在本地计算机上观察到插入和更新都很慢

时间:2012-03-30 14:07:02

标签: mysql performance innodb

这是Uday。我有一个小的innodb表的写性能问题。

    There is a table called "wlists" on my local machine(mysql 5.1.X).
    It has 5 attributes and has less than 1000 rows. 
    By default, innodb_flush_log_at_trx_commit is set to 1 ;

    Now the thing is that
    every insert/update it is taking 0.04 seconds, 
    this is horrible because i can do just 54K inserts per hour.

    When innodb_flush_log_at_trx_commit set to 2, its working fine. 

如何通过innodb_flush属性设置为1来获得相同的性能..?

    Here are some other details that may help in addressing this:
    load on the machine       : Quite normal
    innodb_log_file_size      : 1MB
    innodb_buffer_pool_size   : 8MB
    innodb_thread_concurrency : 8 
    Query                     : update wlists set customer_id = 1000 where id = 300; 

我尝试过不同的选项,比如OPTIMIZE表,增加日志缓冲区,检查网络延迟,但没有人工作。我真的很感谢那些在这里帮助我的人。

这是桌子的DESC和EXPLAIN。

    mysql> DESC wlists ; 
    +-------------+--------------+------+-----+---------+----------------+
    | Field       | Type         | Null | Key | Default | Extra          |
    +-------------+--------------+------+-----+---------+----------------+
    | id          | int(11)      | NO   | PRI | NULL    | auto_increment | 
    | customer_id | int(11)      | NO   | MUL | NULL    |                | 
    | name        | varchar(45)  | YES  |     | NULL    |                | 
    | created     | datetime     | YES  |     | NULL    |                | 
    | modified    | varchar(255) | YES  |     | NULL    |                | 
    +-------------+--------------+------+-----+---------+----------------+
    5 rows in set (0.01 sec)

    mysql> explain select customer_id from wlists where id = 300 ;
    +----+-------------+-----------+-------+---------------+---------+---------+-------+------+
    | id | select_type | table     | type  | possible_keys | key     | key_len | ref   | rows | Extra |
    ----+-------------+-----------+-------+---------------+---------+---------+-------+------+
    |  1 | SIMPLE      | wishlists | const | PRIMARY       | PRIMARY | 4       | const         |    1 |       | 
    +----+-------------+-----------+-------+---------------+---------+---------+-------+------+-------+
    1 row in set (0.00 sec)

SELECT工作正常。问题仅在于UPDATE / INSERT。

此致 UDAY

1 个答案:

答案 0 :(得分:1)

innodb_flush_log_at_trx_commit设置为1将始终导致写入性能下降,因为InnoDB将在每次操作后等待操作系统返回磁盘成功。但请注意,操作系统有时会基于自己的缓存。

但设置innodb_flush_log_at_trx_commit == 1也是保证ACID和完整数据恢复的唯一方法(假设操作系统不会过多)。所以这是一个权衡。解决此问题的理想方法是使用备用电池的存储系统,该系统具有自己的写入缓存。这样您就可以获得写缓存的优势而不会出现数据恢复问题。当然,您必须确保完全维护备用电池,并且当电池经过定期维护周期时,您将遇到写入速度问题。