INNODB性能泄漏在哪里?


11

我有一个奇怪的问题,似乎无法解决。我不是服务器/数据库管理员,而是Web程序员,所以我希望这里有人可以帮助我。

情况

我正在开发一个处理很多updateinsertdelete请求的系统。因此,我选择INNODB作为其行锁定功能的存储引擎。我们使用Gearman并行化在不同服务器上的工作,每10分钟更新60,000条记录。该代码在PHP中,我们正在使用Zend Framework。

问题

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction

我们几乎每30分钟就会从我们的一名Gearman工人那里收到上述错误。

mysql_report

MySQL 5.1.63-0+squeeze1  uptime 15 9:52:12      Tue Sep 11 21:25:23 2012

__ Key _________________________________________________________________
Buffer used    55.00k of  16.00M  %Used:   0.34
  Current       2.92M            %Usage:  18.24
Write hit      99.95%
Read hit      100.00%

__ Questions ___________________________________________________________
Total         122.05M    91.7/s
  DMS         106.63M    80.1/s  %Total:  87.37
  Com_         10.23M     7.7/s            8.38
  COM_QUIT      4.05M     3.0/s            3.32
  QC Hits       1.09M     0.8/s            0.90
  +Unknown     47.77k     0.0/s            0.04
Slow 2 s       11.14M     8.4/s            9.13  %DMS:  10.45  Log:  ON
DMS           106.63M    80.1/s           87.37
  INSERT       69.21M    52.0/s           56.70         64.90
  UPDATE       22.94M    17.2/s           18.79         21.51
  DELETE       11.19M     8.4/s            9.17         10.49
  SELECT        3.30M     2.5/s            2.70          3.09
  REPLACE           0       0/s            0.00          0.00
Com_           10.23M     7.7/s            8.38
  set_option    4.11M     3.1/s            3.37
  show_fields   3.44M     2.6/s            2.82
  begin         1.33M     1.0/s            1.09

__ SELECT and Sort _____________________________________________________
Scan            4.31M     3.2/s %SELECT: 130.57
Range              52     0.0/s            0.00
Full join          24     0.0/s            0.00
Range check         0       0/s            0.00
Full rng join       1     0.0/s            0.00
Sort scan      31.98k     0.0/s
Sort range      2.05M     1.5/s
Sort mrg pass       0       0/s

__ Query Cache _________________________________________________________
Memory usage  849.84k of  16.00M  %Used:   5.19
Block Fragmnt   1.57%
Hits            1.09M     0.8/s
Inserts         2.52M     1.9/s
Insrt:Prune   1.83k:1     1.9/s
Hit:Insert     0.43:1

__ Table Locks _________________________________________________________
Waited            764     0.0/s  %Total:   0.00
Immediate     106.63M    80.1/s

__ Tables ______________________________________________________________
Open              128 of  128    %Cache: 100.00
Opened          4.82k     0.0/s

__ Connections _________________________________________________________
Max used          301 of  300      %Max: 100.33
Total           4.05M     3.0/s

__ Created Temp ________________________________________________________
Disk table      3.44M     2.6/s
Table           3.44M     2.6/s    Size:  32.0M
File                5     0.0/s

__ Threads _____________________________________________________________
Running            20 of   89
Cached              4 of    8      %Hit:  97.29
Created       109.59k     0.1/s
Slow                0       0/s

__ Aborted _____________________________________________________________
Clients         2.95k     0.0/s
Connects        3.22k     0.0/s

__ Bytes _______________________________________________________________
Sent           13.61G   10.2k/s
Received       26.90G   20.2k/s

__ InnoDB Buffer Pool __________________________________________________
Usage          89.62M of   1.46G  %Used:   5.97
Read hit      100.00%
Pages
  Free         90.26k            %Total:  94.03
  Data          5.24k                      5.46 %Drty:   2.79
  Misc            498                      0.52
  Latched           0                      0.00
Reads         728.62G  547.2k/s
  From file       816     0.0/s            0.00
  Ahead Rnd         3     0.0/s
  Ahead Sql        27     0.0/s
Writes        715.15M   537.1/s
Flushes        11.91M     8.9/s
Wait Free           0       0/s

__ InnoDB Lock _________________________________________________________
Waits         1008791     0.8/s
Current            18
Time acquiring
  Total     184022524 ms
  Average       18241 ms
  Max           59096 ms

__ InnoDB Data, Pages, Rows ____________________________________________
Data
  Reads           919     0.0/s
  Writes       14.17M    10.6/s
  fsync         7.40M     5.6/s
  Pending
    Reads           0
    Writes          0
    fsync           0

Pages
  Created      43.90k     0.0/s
  Read          2.64k     0.0/s
  Written      11.91M     8.9/s

Rows
  Deleted      47.34M    35.6/s
  Inserted     49.70M    37.3/s
  Read        639.52G  480.3k/s
  Updated      56.33M    42.3/s

代码

$this->db->beginTransaction();

        try {
            for($i = 0; $i < count($products); $i++)
            {
                $this->db->query("UPDATE userproducts SET lowest_price= :p1, last_lowest_price_update='".date("Y-m-d H:i:s", time())."' WHERE product_id = :p2", array(
'p1' => $products[$i]['price_total_end'][1],
'p2' => $products[$i]['asin']));
            }
            $this->db->commit();
        } catch (Exception $e) {
            $this->db->rollBack();
            echo $e->getMessage();
        }
        $this->db->closeConnection();

那就是更新一张桌子的代码。我们有类似的代码来更新另一个表。使用上面给出的代码,每次调用此方法时,我们都会提交50个请求,这将由近20位工作人员每30秒提交一次。

更多信息

mysqladmin status

Uptime: 6770  Threads: 109  Questions: 857696  Slow queries: 52469  Opens: 1382  Flush tables: 1  Open tables: 128  Queries per second avg: 126.690

mysql> SHOW STATUS LIKE 'Open%';
+--------------------------+-------+
| Variable_name            | Value |
+--------------------------+-------+
| Open_files               | 21    |
| Open_streams             | 0     |
| Open_table_definitions   | 230   |
| Open_tables              | 128   |
| Opened_files             | 71653 |
| Opened_table_definitions | 0     |
| Opened_tables            | 0     |
+--------------------------+-------+
7 rows in set (0.00 sec)

mysql> SHOW CREATE TABLE userproducts\G
*************************** 1. row ***************************
       Table: userproducts
Create Table: CREATE TABLE `userproducts` (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `userinfos_id` int(12) NOT NULL,
  `seller_sku` varchar(35) COLLATE utf8_bin NOT NULL,
  `product_id` varchar(20) COLLATE utf8_bin NOT NULL,
  `price` float(8,2) NOT NULL,
  `shipping` float(6,2) NOT NULL DEFAULT '0.00',
  `alter_preis` float(8,2) DEFAULT NULL,
  `ek_price` float(8,2) NOT NULL DEFAULT '-1.00',
  `quantity` int(5) NOT NULL DEFAULT '0',
  `lowest_price` float(8,2) DEFAULT NULL,
  `titel` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'n/a',
  `url` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `sales_rank` int(8) DEFAULT NULL,
  `kategorie` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `kategorie_2` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `kategorie_3` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `optimierung` int(1) NOT NULL DEFAULT '0',
  `indi` int(1) DEFAULT '0',
  `akt_festpreis` int(1) DEFAULT '0',
  `new` int(1) DEFAULT '1',
  `locked` int(1) DEFAULT '0',
  `determined` int(1) DEFAULT '0',
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  `a_m_preis` float(8,2) DEFAULT NULL,
  `a_h_preis` float(8,2) DEFAULT NULL,
  `m_preis` float(8,2) NOT NULL DEFAULT '0.00',
  `h_preis` float(8,2) NOT NULL DEFAULT '0.00',
  `preisabstand` float(6,2) DEFAULT '0.00',
  `preisabstand_art` varchar(12) COLLATE utf8_bin DEFAULT 'euro',
  `festpreis` float(8,2) DEFAULT '0.00',
  `last_update` datetime NOT NULL,
  `last_lowest_price_update` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `seller_sku_by_seller` (`userinfos_id`,`seller_sku`),
  KEY `userinfos_id` (`userinfos_id`)
) ENGINE=InnoDB AUTO_INCREMENT=32301793 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
1 row in set (0.00 sec)

mysql> SHOW GLOBAL VARIABLES LIKE 'innodb%'\G
*************************** 1. row ***************************
Variable_name: innodb_adaptive_hash_index
        Value: ON
*************************** 2. row ***************************
Variable_name: innodb_additional_mem_pool_size
        Value: 104857600
*************************** 3. row ***************************
Variable_name: innodb_autoextend_increment
        Value: 8
*************************** 4. row ***************************
Variable_name: innodb_autoinc_lock_mode
        Value: 1
*************************** 5. row ***************************
Variable_name: innodb_buffer_pool_size
        Value: 1572864000
*************************** 6. row ***************************
Variable_name: innodb_checksums
        Value: ON
*************************** 7. row ***************************
Variable_name: innodb_commit_concurrency
        Value: 0
*************************** 8. row ***************************
Variable_name: innodb_concurrency_tickets
        Value: 500
*************************** 9. row ***************************
Variable_name: innodb_data_file_path
        Value: ibdata1:1G;ibdata2:1G;ibdata3:1G:autoextend
*************************** 10. row ***************************
Variable_name: innodb_data_home_dir
        Value: /var/lib/mysql/
*************************** 11. row ***************************
Variable_name: innodb_doublewrite
        Value: ON
*************************** 12. row ***************************
Variable_name: innodb_fast_shutdown
        Value: 1
*************************** 13. row ***************************
Variable_name: innodb_file_io_threads
        Value: 4
*************************** 14. row ***************************
Variable_name: innodb_file_per_table
        Value: ON
*************************** 15. row ***************************
Variable_name: innodb_flush_log_at_trx_commit
        Value: 1
*************************** 16. row ***************************
Variable_name: innodb_flush_method
        Value: 
*************************** 17. row ***************************
Variable_name: innodb_force_recovery
        Value: 0
*************************** 18. row ***************************
Variable_name: innodb_lock_wait_timeout
        Value: 50
*************************** 19. row ***************************
Variable_name: innodb_locks_unsafe_for_binlog
        Value: OFF
*************************** 20. row ***************************
Variable_name: innodb_log_buffer_size
        Value: 26214400
*************************** 21. row ***************************
Variable_name: innodb_log_file_size
        Value: 314572800
*************************** 22. row ***************************
Variable_name: innodb_log_files_in_group
        Value: 2
*************************** 23. row ***************************
Variable_name: innodb_log_group_home_dir
        Value: ./
*************************** 24. row ***************************
Variable_name: innodb_max_dirty_pages_pct
        Value: 90
*************************** 25. row ***************************
Variable_name: innodb_max_purge_lag
        Value: 0
*************************** 26. row ***************************
Variable_name: innodb_mirrored_log_groups
        Value: 1
*************************** 27. row ***************************
Variable_name: innodb_open_files
        Value: 300
*************************** 28. row ***************************
Variable_name: innodb_rollback_on_timeout
        Value: OFF
*************************** 29. row ***************************
Variable_name: innodb_stats_method
        Value: nulls_equal
*************************** 30. row ***************************
Variable_name: innodb_stats_on_metadata
        Value: ON
*************************** 31. row ***************************
Variable_name: innodb_support_xa
        Value: ON
*************************** 32. row ***************************
Variable_name: innodb_sync_spin_loops
        Value: 20
*************************** 33. row ***************************
Variable_name: innodb_table_locks
        Value: ON
*************************** 34. row ***************************
Variable_name: innodb_thread_concurrency
        Value: 8
*************************** 35. row ***************************
Variable_name: innodb_thread_sleep_delay
        Value: 10000
*************************** 36. row ***************************
Variable_name: innodb_use_legacy_cardinality_algorithm
        Value: ON
36 rows in set (0.00 sec)

mysql> SHOW ENGINE INNODB STATUS\G
*************************** 1. row ***************************
  Type: InnoDB
  Name: 
Status: 
=====================================
120912 17:15:21 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 37 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 257219, signal count 242756
--Thread 47843758212864 has waited at ../../../storage/innobase/lock/lock0lock.c line 5108 for 0.00 seconds the semaphore:
Mutex at 0x2b82ed8712b8 created file ../../../storage/innobase/srv/srv0srv.c line 891, lock var 0
waiters flag 0
Mutex spin waits 0, rounds 125510621, OS waits 136209
RW-shared spins 100480, OS waits 14880; RW-excl spins 164568, OS waits 4813
------------------------
LATEST DETECTED DEADLOCK
------------------------
120912 17:14:59
*** (1) TRANSACTION:
TRANSACTION 0 20639503, ACTIVE 8 sec, process no 1655, OS thread id 47843745568512 fetching rows
mysql tables in use 1, locked 1
LOCK WAIT 700 lock struct(s), heap size 63472, 38097 row lock(s), undo log entries 2
MySQL thread id 99112, query id 2086869 s16468810.onlinehome-server.info 87.106.82.83 web0 Updating
UPDATE userproducts SET lowest_price=44.9, last_lowest_price_update='2012-09-12 17:14:53' WHERE product_id LIKE 'B007J20HN2'
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 985 n bits 136 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639503 lock_mode X waiting
Record lock, heap no 60 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 [SOME STRANGE CHARAKTERS LIKE ABOVE]

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 985 n bits 136 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639496 lock_mode X locks rec but not gap waiting
Record lock, heap no 59 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 0: len 4; hex 815d9f43; asc  ] C;; 1: len 6; hex 0000013ae793; asc    :  ;; 2: len 7; hex 000000002d01e9; asc     -  ;; 3: len 4; hex 80006f9a; asc   o ;; 4: len 12; hex 30302d3956335a2d47555a34; asc 00-9V3Z-GUZ4;; 5: len 10; hex 42303032414c38463732; asc B002AL8F72;; 6: len 4; hex cdccdb42; asc    B;; 7: len 4; hex 00000000; asc     ;; 8: len 4; hex cdccdb42; asc    B;; 9: len 4; hex 000080bf; asc     ;; 10: len 4; hex 800003e7; asc     ;; 11: len 4; hex cdccdb42; asc    B;; 12: len 30; hex 537572706c75732056696e74616765204a61636b65204d36352052656769; asc Surplus Vintage Jacke M65 Regi;...(truncated); 13: len 30; hex 687474703a2f2f6563782e696d616765732d616d617a6f6e2e636f6d2f69; asc http://ecx.images-amazon.com/i;...(truncated); 14: len 4; hex 800034c5; asc   4 ;; 15: len 10; hex 42656b6c656964756e67; asc Bekleidung;; 16: len 3; hex 4e2f41; asc N/A;; 17: len 3; hex 4e2f41; asc N/A;; 18: len 4; hex 80000000; asc     ;; 19: len 4; hex 80000000; asc     ;; 20: len 4; hex 80000000; asc     ;; 21: len 4; hex 80000000; asc     ;; 22: len 4; hex 80000000; asc     ;; 23: len 4; hex 80000000; asc     ;; 24: len 1; hex 80; asc  ;; 25: SQL NULL; 26: SQL NULL; 27: len 4; hex 00000000; asc     ;; 28: len 4; hex 00000000; asc     ;; 29: len 4; hex 00000000; asc     ;; 30: len 4; hex 6575726f; asc euro;; 31: len 4; hex 00000000; asc     ;; 32: len 8; hex 8000124cc3d28e8a; asc    L    ;; 33: len 8; hex 8000124cc3d28fc6; asc    L    ;;

*** WE ROLL BACK TRANSACTION (1)
------------
TRANSACTIONS
------------
Trx id counter 0 20639610
Purge done for trx's n:o < 0 20639595 undo n:o < 0 0
History list length 4
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, process no 1655, OS thread id 47843726903040
MySQL thread id 99216, query id 2090678 localhost root
SHOW ENGINE INNODB STATUS
---TRANSACTION 0 20639607, not started, process no 1655, OS thread id 47843746371328
--- [ SOME MORE LIKE THESE ] 
---TRANSACTION 0 20527676, not started, process no 1655, OS thread id 47843739748096
MySQL thread id 1340, query id 5247 s16468807.onlinehome-server.info 87.106.72.226 web0
---TRANSACTION 0 20639609, ACTIVE 0 sec, process no 1655, OS thread id 47843728910080 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 3 lock struct(s), heap size 1216, 2 row lock(s)
MySQL thread id 99095, query id 2090662 s16468809.onlinehome-server.info 87.106.82.94 web0 Updating
UPDATE `userproducts` SET `locked` = '0' WHERE (userinfos_id = '28565')
------- TRX HAS BEEN WAITING 0 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 985 n bits 136 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639609 lock_mode X locks rec but not gap waiting
Record lock, heap no 57 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 0: len 4; hex 8158219b; asc  X! ;; 1: len 6; hex 0000013aeebe; asc    :  ;; 2: len 7; hex 000000003208b2; asc     2  ;; 3: len 4; hex 80006f95; asc   o ;; 4: len 12; hex 32592d50484d342d54475458; asc 2Y-PHM4-TGTX;; 5: len 10; hex 42303031314246525832; asc B0011BFRX2;; 6: len 4; hex 00004040; asc   @@;; 7: len 4; hex 00004040; asc   @@;; 8: len 4; hex 00004040; asc   @@;; 9: len 4; hex 000080bf; asc     ;; 10: len 4; hex 80000001; asc     ;; 11: len 4; hex 33330741; asc 33 A;; 12: len 21; hex 5b556e62656b616e6e7465722045696e62616e645d; asc [Unbekannter Einband];; 13: len 30; hex 687474703a2f2f6563782e696d616765732d616d617a6f6e2e636f6d2f69; asc http://ecx.images-amazon.com/i;...(truncated); 14: len 4; hex 800d67f7; asc   g ;; 15: len 1; hex 42; asc B;; 16: len 3; hex 4e2f41; asc N/A;; 17: len 3; hex 4e2f41; asc N/A;; 18: len 4; hex 80000000; asc     ;; 19: len 4; hex 80000000; asc     ;; 20: len 4; hex 80000000; asc     ;; 21: len 4; hex 80000000; asc     ;; 22: len 4; hex 80000000; asc     ;; 23: len 4; hex 80000000; asc     ;; 24: len 1; hex 80; asc  ;; 25: SQL NULL; 26: SQL NULL; 27: len 4; hex 00000000; asc     ;; 28: len 4; hex 00000000; asc     ;; 29: len 4; hex 00000000; asc     ;; 30: len 4; hex 6575726f; asc euro;; 31: len 4; hex 00000000; asc     ;; 32: len 8; hex 8000124cc3758ea7; asc    L u  ;; 33: len 8; hex 8000124cc3d291b5; asc    L    ;;

------------------

[SOME MORE OF THESE]

------------------
---TRANSACTION 0 20639544, ACTIVE 22 sec, process no 1655, OS thread id 47843758212864 fetching rows, thread declared inside InnoDB 158
mysql tables in use 1, locked 1
60 lock struct(s), heap size 6752, 5861 row lock(s), undo log entries 29
MySQL thread id 99161, query id 2090677 s16468810.onlinehome-server.info 87.106.82.83 web0 Updating
UPDATE userproducts SET shipping=0, last_lowest_price_update='2012-09-12 17:15:22' WHERE product_id LIKE 'B00851I800' AND userinfos_id=28570
---TRANSACTION 0 20639538, ACTIVE 24 sec, process no 1655, OS thread id 47843733726976 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 368, 1 row lock(s)
MySQL thread id 99159, query id 2088002 s16468808.onlinehome-server.info 87.106.82.91 web0 Updating
UPDATE userproducts SET lowest_price=10.69, last_lowest_price_update='2012-09-12 17:14:59' WHERE product_id LIKE 'B0065JFS2U'
------- TRX HAS BEEN WAITING 24 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 6 n bits 120 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639538 lock_mode X waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 [ SAME STRANGE CHARAKTERS]

------------------
---TRANSACTION 0 20639510, ACTIVE 29 sec, process no 1655, OS thread id 47843554330368 starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 368, 1 row lock(s)
MySQL thread id 99119, query id 2086898 s16468808.onlinehome-server.info 87.106.82.91 web0 Updating
UPDATE userproducts SET lowest_price=50.8, last_lowest_price_update='2012-09-12 17:14:53' WHERE product_id LIKE 'B002MPPOUC'
------- TRX HAS BEEN WAITING 29 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 6 n bits 120 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639510 lock_mode X waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 0: len 4; hex 8000bb1d; asc     ;; 1: len 6; hex 000001394831; asc    9H1;; 2: len 7; hex 000000003409ad; asc     4  ;; 3: len 4; hex 80000003; asc     ;; 4: len 12; hex 30302d364f4e4a2d48305039; asc 00-6ONJ-H0P9;; 5: len 10; hex 42303037523531533241; asc B007R51S2A;; 6: len 4; hex d7e34243; asc   BC;; 7: len 4; hex 00000000; asc     ;; 8: len 4; hex d7e34243; asc   BC;; 9: len 4; hex 000080bf; asc     ;; 10: len 4; hex 80000003; asc     ;; 11: len 4; hex d7e34243; asc   BC;; 12: len 30; hex 54616765736465636b65206f646572204b697373656e2041746963612037; asc Tagesdecke oder Kissen Atica 7;...(truncated); 13: len 30; hex 687474703a2f2f6563782e696d616765732d616d617a6f6e2e636f6d2f69; asc http://ecx.images-amazon.com/i;...(truncated); 14: len 4; hex 800c7b52; asc   {R;; 15: len 1; hex 4b; asc K;; 16: len 3; hex 4e2f41; asc N/A;; 17: len 3; hex 4e2f41; asc N/A;; 18: len 4; hex 80000001; asc     ;; 19: len 4; hex 80000000; asc     ;; 20: len 4; hex 80000000; asc     ;; 21: len 4; hex 80000000; asc     ;; 22: len 4; hex 80000000; asc     ;; 23: len 4; hex 80000000; asc     ;; 24: len 1; hex 80; asc  ;; 25: SQL NULL; 26: SQL NULL; 27: len 4; hex 00000000; asc     ;; 28: len 4; hex 00000000; asc     ;; 29: len 4; hex 00000000; asc     ;; 30: len 4; hex 6575726f; asc euro;; 31: len 4; hex 00000000; asc     ;; 32: len 8; hex 8000124cc3b3ba08; asc    L    ;; 33: len 8; hex 8000124cc3d1d42c; asc    L   ,;;

------------------
---TRANSACTION 0 20639508, ACTIVE 30 sec, process no 1655, OS thread id 47843558143744 fetching rows
mysql tables in use 1, locked 1
LOCK WAIT 700 lock struct(s), heap size 63472, 38096 row lock(s)
MySQL thread id 99117, query id 2086890 s16468810.onlinehome-server.info 87.106.82.83 web0 Updating
UPDATE userproducts SET lowest_price=109.9, last_lowest_price_update='2012-09-12 17:14:53' WHERE product_id LIKE 'B002AL8F72'
------- TRX HAS BEEN WAITING 1 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 985 n bits 136 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639508 lock_mode X waiting
Record lock, heap no 59 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 0: len 4; hex 815d9f43; asc  ] C;; 1: len 6; hex 0000013aef08; asc    :  ;; 2: len 7; hex 00000000391358; asc     9 X;; 3: len 4; hex 80006f9a; asc   o ;; 4: len 12; hex 30302d3956335a2d47555a34; asc 00-9V3Z-GUZ4;; 5: len 10; hex 42303032414c38463732; asc B002AL8F72;; 6: len 4; hex cdccdb42; asc    B;; 7: len 4; hex 00000000; asc     ;; 8: len 4; hex cdccdb42; asc    B;; 9: len 4; hex 000080bf; asc     ;; 10: len 4; hex 800003e7; asc     ;; 11: len 4; hex cdccdb42; asc    B;; 12: len 30; hex 537572706c75732056696e74616765204a61636b65204d36352052656769; asc Surplus Vintage Jacke M65 Regi;...(truncated); 13: len 30; hex 687474703a2f2f6563782e696d616765732d616d617a6f6e2e636f6d2f69; asc http://ecx.images-amazon.com/i;...(truncated); 14: len 4; hex 800034c5; asc   4 ;; 15: len 10; hex 42656b6c656964756e67; asc Bekleidung;; 16: len 3; hex 4e2f41; asc N/A;; 17: len 3; hex 4e2f41; asc N/A;; 18: len 4; hex 80000000; asc     ;; 19: len 4; hex 80000000; asc     ;; 20: len 4; hex 80000000; asc     ;; 21: len 4; hex 80000000; asc     ;; 22: len 4; hex 80000000; asc     ;; 23: len 4; hex 80000000; asc     ;; 24: len 1; hex 80; asc  ;; 25: SQL NULL; 26: SQL NULL; 27: len 4; hex 00000000; asc     ;; 28: len 4; hex 00000000; asc     ;; 29: len 4; hex 00000000; asc     ;; 30: len 4; hex 6575726f; asc euro;; 31: len 4; hex 00000000; asc     ;; 32: len 8; hex 8000124cc3d291ec; asc    L    ;; 33: len 8; hex 8000124cc3d28fc6; asc    L    ;;

------------------
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
2714 OS file reads, 202235 OS file writes, 95816 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 8.70 writes/s, 4.68 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
0 inserts, 0 merged recs, 0 merges
Hash table size 3112859, node heap has 344 buffer(s)
7394.83 hash searches/s, 930.22 non-hash searches/s
---
LOG
---
Log sequence number 14 2880311684
Log flushed up to   14 2880309944
Last checkpoint at  14 2880298289
0 pending log writes, 0 pending chkp writes
83150 log i/o's done, 3.89 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 1884360120; in additional pool allocated 21052672
Dictionary memory allocated 1087464
Buffer pool size   96000
Free buffers       90835
Database pages     4818
Modified db pages  26
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 4102, created 716, written 187723
0.00 reads/s, 0.00 creates/s, 8.05 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
1 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 1655, id 47843546388224, state: sleeping
Number of rows inserted 844694, updated 784400, deleted 836993, read 11188899916
15.40 inserts/s, 87.40 updates/s, 12.51 deletes/s, 253212.99 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

1 row in set (0.01 sec)

问题

该报告中有什么看起来很奇怪?对我来说,看起来我们似乎内存不足。

我不了解的是InnoDB数据Pages, Rows > Rows > Read。为什么每秒有480,000次读取?那是什么意思?在我看来,每秒只有42次更新,这确实不是那么快。

如何打开表或文件。这是通常的值吗?我没有那个主题的经验。

某些功能无法正常工作,我希望这里的人可以帮助我找到它。


您在SHOW ENGINE INNODB STATUS;输出中看到任何DEADLOCK 吗?
量子

不。一无所获。
M. Hirn

1)请发布输出SHOW CREATE TABLE userproducts\G,2)请发布输出SHOW GLOBAL VARIABLES LIKE 'innodb%'\G,3)问题:您安装了innodb插件吗?,4)请发布输出SHOW ENGINE INNODB STATUS\G
RolandoMySQLDBA 2012年

我向问题添加了以下信息。但是我无法SHOW ENGINE INNODB STATUS\G发布整个输出,因为只允许分配30k个字母的文本。所以我不得不跳过一些东西。问题3)这些是什么意思?我没有安装任何东西,我只是将表引擎设置为innodb。
M. Hirn

Answers:


7

观察#1

仅查看您的输出,SHOW ENGINE INNODB STATUS\G我在每个事务的底部都会看到各种表锁定消息。您有一个持有锁38096行的交易

------------------
---TRANSACTION 0 20639508, ACTIVE 30 sec, process no 1655, OS thread id 47843558143744 fetching rows
mysql tables in use 1, locked 1
LOCK WAIT 700 lock struct(s), heap size 63472, 38096 row lock(s)
MySQL thread id 99117, query id 2086890 s16468810.onlinehome-server.info 87.106.82.83 web0 Updating
UPDATE userproducts SET lowest_price=109.9, last_lowest_price_update='2012-09-12 17:14:53' WHERE product_id LIKE 'B002AL8F72'
------- TRX HAS BEEN WAITING 1 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 631 page no 985 n bits 136 index `PRIMARY` of table `usr_web0_1`.`userproducts` trx id 0 20639508 lock_mode X waiting
Record lock, heap no 59 PHYSICAL RECORD: n_fields 34; compact format; info bits 0
 0: len 4; hex 815d9f43; asc  ] C;; 1: len 6; hex 0000013aef08; asc    :  ;; 2: len 7; hex 00000000391358; asc     9 X;; 3: len 4; hex 80006f9a; asc   o ;; 4: len 12; hex 30302d3956335a2d47555a34; asc 00-9V3Z-GUZ4;; 5: len 10; hex 42303032414c38463732; asc B002AL8F72;; 6: len 4; hex cdccdb42; asc    B;; 7: len 4; hex 00000000; asc     ;; 8: len 4; hex cdccdb42; asc    B;; 9: len 4; hex 000080bf; asc     ;; 10: len 4; hex 800003e7; asc     ;; 11: len 4; hex cdccdb42; asc    B;; 12: len 30; hex 537572706c75732056696e74616765204a61636b65204d36352052656769; asc Surplus Vintage Jacke M65 Regi;...(truncated); 13: len 30; hex 687474703a2f2f6563782e696d616765732d616d617a6f6e2e636f6d2f69; asc http://ecx.images-amazon.com/i;...(truncated); 14: len 4; hex 800034c5; asc   4 ;; 15: len 10; hex 42656b6c656964756e67; asc Bekleidung;; 16: len 3; hex 4e2f41; asc N/A;; 17: len 3; hex 4e2f41; asc N/A;; 18: len 4; hex 80000000; asc     ;; 19: len 4; hex 80000000; asc     ;; 20: len 4; hex 80000000; asc     ;; 21: len 4; hex 80000000; asc     ;; 22: len 4; hex 80000000; asc     ;; 23: len 4; hex 80000000; asc     ;; 24: len 1; hex 80; asc  ;; 25: SQL NULL; 26: SQL NULL; 27: len 4; hex 00000000; asc     ;; 28: len 4; hex 00000000; asc     ;; 29: len 4; hex 00000000; asc     ;; 30: len 4; hex 6575726f; asc euro;; 31: len 4; hex 00000000; asc     ;; 32: len 8; hex 8000124cc3d291ec; asc    L    ;; 33: len 8; hex 8000124cc3d28fc6; asc    L    ;;

观察#2

回顾表结构,我发现该userproducts表上没有索引product_id。因此,您正在执行全表扫描以执行单行的更新。

观察#3

您在userproducts表中也有重复的索引。该userinfos_id列有两个索引。无需使用重复的前导列来膨胀索引。

观察#4

您具有innodb_thread_concurrency =8。对于无限并发,应将其设置为零。

查看我过去的帖子

建议1

将此添加到/etc/my.cnf

[mysqld]
innodb_thread_concurrency = 0

然后重启MySQL

建议2

请在您的休息时间运行

ALTER TABLE userproducts ADD INDEX product_id (product_id),DROP INDEX userinfos_id;

建议3(可选的长期目标)

您需要重组InnoDB布局,因为您启用了innodb_file_per_table。这消除了对多个ibdata文件的需求。您只需要一个。请查看我过去的帖子:

试试看 !!!


2
哇。这是我所期望的。谢谢,我会尽一切努力,然后再回来告诉它是如何工作的。谢谢;)
M. Hirn 2012年

1
@MichaelHirn是的,不要开玩笑。我们应该开始将所有关于DBA的好的问题迁移到RolandoMySQLDBA.stackexchange.com,并绕开其他SE网站。:)
HopelessN00b 2012年

3

product_id缺少索引肯定是问题所在。

可能会进一步优化这种情况:对product_id进行排序,然后在线程之间分配它们。


是的,你说的没错。缺少的product_id导致了错误。好吧,我可以修复它,但对于您选择的优化策略,我也很感兴趣。您能详细说明如何进行吗?我想我没明白你的意思。
M. Hirn'9

INSERT需要将数据(或索引条目)放在磁盘上的适当位置。这涉及(1)读取尚未缓存的块,(2)更新该块以添加新信息,以及(3)最终将该块写回到磁盘。在对数据进行排序时,有更好的机会找到已经缓存的必要块,从而避免了读取和/或写入。(在处理大表时,磁盘I / O是最大的开销。)
Rick James

0

好的,首先,您所关心的错误lock wait timeout exceeded实际上是在说某事失败,因为它必须等待太长时间才能释放锁。它与内存利用率无关。这里有一个StackOverflow线程,提供了有关此错误的一般故障排除的很好的[基本]答案。

如您所见,您可以通过运行获得大量数据,SHOW INNODB STATUS\G并可以将InnoDB锁定等待超时配置为更适合您的用例的值。

关于您在报告中看到的内容的问题,每秒读取480,000行意味着在报告涵盖的时间段内平均每秒读取480,000行数据库。

我对回答“报告中看起来有些奇怪”的部分并不完全满意,但是我想说,您可能需要以针对数据库的确切运行方式提供更多信息,以获得答案。这样...但是只要我看到很大的读取值(例如每秒读取48万行),我就立即开始想知道哪些查询正在运行,并试图读取整个数据库。也许更多的经验DBA上有另一个拿,但没有什么本质奇怪,我可以在该报告中看到,超过的人数等updates,并creates不会记录更新的你说你正在执行的音量相对应的。


好吧,我将在接下来的几分钟内编辑有关《守则》的更多信息。您的意思是,“更新和创建的数量与您所说的正在执行的记录更新数量不符。” 我们少了updates吗?好吧,我认为有5千6百万人辞职了。令我感到不对劲的是6,400亿次读取。这些是reads什么?这些是SELECT陈述吗?
M. Hirn

@MichaelHirn您说您要在10分钟内进行60,000条记录更新,这将是100 updates/ s,但是MySQL报告仅显示42.3 / s,这远低于您所声明的数量。即使加上所有creates,您的数量也大大减少了。如果那是因为60,000 / 10分钟的音量是一个不太准确的粗略数字,那很好,但是对我来说很突出。对于reads,是的,一条SELECT语句reads在数据库上引起。如果从大量行中进行选择,它将读取很多行。但是,对我来说,这似乎很高。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.