Saya memiliki masalah aneh yang sepertinya tidak bisa saya perbaiki. Saya lebih sebagai programmer web daripada Admin Server / DB, jadi saya harap seseorang di sini dapat membantu saya.
Situasi
Saya bekerja pada sistem yang menangani banyak update
, insert
dan delete
permintaan. Karena itu, saya memilih INNODB sebagai mesin penyimpanan saya karena kemampuan kunci barisnya. Kami memperbarui 60.000 Catatan setiap 10 Menit, menggunakan Gearman untuk memparalelkan pekerjaan kami di server yang berbeda. Kode ini dalam PHP dan kami menggunakan Zend Framework.
Masalah
SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction
Kami mendapatkan kesalahan di atas hampir setiap 30 menit, dari salah satu pekerja Gearman kami.
Itu 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
Kode
$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();
Itulah Kode untuk memperbarui satu tabel. Kami memiliki kode yang mirip untuk memperbarui tabel lain. Dengan kode yang diberikan di atas, kami melakukan 50 permintaan setiap kali metode ini dipanggil, yang akan setiap 30 detik oleh hampir 20 pekerja.
Bahkan lebih banyak info
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)
Pertanyaan-pertanyaan
Apa yang dalam laporan ini terlihat aneh? Bagi saya, itu tidak terlihat seperti kita kehabisan memori.
Yang tidak saya mengerti adalah Data InnoDB Pages, Rows > Rows > Read
,. Mengapa ada 480.000 Bacaan per detik? Apa artinya? Dan bagi saya tampaknya hanya ada 42 pembaruan per detik, yang tidak terlalu cepat.
Bagaimana dengan tabel atau file yang terbuka. Apakah ini nilai yang biasa? Saya tidak punya pengalaman dalam topik itu.
Sesuatu tidak berfungsi seperti yang diharapkan, dan saya berharap seseorang di sini dapat membantu saya menemukannya.
sumber
SHOW ENGINE INNODB STATUS;
output?SHOW CREATE TABLE userproducts\G
, 2) Silakan posting outputSHOW GLOBAL VARIABLES LIKE 'innodb%'\G
, 3) Pertanyaan: Apakah Anda menginstal plugin innodb ?, 4) Silakan posting outputSHOW ENGINE INNODB STATUS\G
SHOW ENGINE INNODB STATUS\G
memposting seluruh output, karena saya hanya diperbolehkan mengalokasikan teks dengan 30k huruf. Jadi saya harus melewatkan sesuatu. Pertanyaan 3) Apa yang Anda maksud dengan ini? Saya tidak menginstal apa pun saya hanya mengatur mesin meja ke innodb.Jawaban:
PENGAMATAN # 1
Hanya melihat output dari Anda,
SHOW ENGINE INNODB STATUS\G
saya melihat berbagai pesan kunci tabel di bagian bawah setiap transaksi. Anda memiliki satu transaksi yang memegang kunci 38096 barisPENGAMATAN # 2
Melihat kembali struktur tabel, saya melihat
userproducts
tabel tidak memiliki indeksproduct_id
. Karena itu, Anda melakukan pemindaian tabel penuh untuk melakukan pembaruan satu baris.PENGAMATAN # 3
Anda juga memiliki indeks duplikat di
userproducts
tabel. Dua indeks dimulai denganuserinfos_id
kolom. Tidak perlu mengasapi indeks dengan kolom terkemuka rangkap.PENGAMATAN # 4
Anda memiliki innodb_thread_concurrency = 8. Ini harus diatur ke nol untuk konkurensi tak terbatas
Lihat posting saya sebelumnya tentang ini
May 26, 2011
: Tentang kinerja basis data single threaded versus multithreadedSep 12, 2011
: Kemungkinan untuk menggunakan MySQL lebih dari satu inti?Feb 24, 2012
: Tuning Server Percona khusus dengan XtraDB untuk OLTPMar 16, 2012
: Menggunakan beberapa core untuk satu permintaan MySQL di DebianREKOMENDASI # 1
Tambahkan ini ke /etc/my.cnf
dan restart MySQL
REKOMENDASI # 2
Silakan jalankan ini selama periode off Anda
REKOMENDASI # 3 (Tujuan Jangka Panjang Opsional)
Anda perlu merestrukturisasi Layout InnoDB Anda karena Anda telah mengaktifkan innodb_file_per_table. Itu membatalkan kebutuhan untuk banyak file ibdata. Anda hanya butuh satu. Silakan lihat posting saya yang lalu tentang ini:
Oct 29, 2010
: Posting Asli Saya di StackOverflowApr 01, 2012
: Apakah innodb_file_per_table disarankan?Mar 25, 2012
: Mengapa InnoDB menyimpan semua basis data dalam satu file?Feb 03, 2012
: Pengoptimalan terjadwal tabel di MySQL InnoDBCobalah !!!
sumber
Indeks yang hilang pada product_id jelas merupakan masalah.
Ini lebih lanjut dapat mengoptimalkan situasi: Urutkan product_ids Anda sebelum membaginya di antara utas.
sumber
Oke, pertama-tama, kesalahan yang Anda khawatirkan,
lock wait timeout exceeded
pada dasarnya mengatakan bahwa sesuatu gagal karena harus menunggu terlalu lama untuk kunci dirilis. Itu tidak ada hubungannya dengan pemanfaatan memori. Ada utas StackOverflow di sini dengan jawaban [dasar] yang bagus tentang pemecahan masalah umum dari kesalahan ini.Seperti yang akan Anda lihat di sana, Anda bisa mendapatkan jumlah data yang baik dengan menjalankan
SHOW INNODB STATUS\G
dan dapat mengonfigurasi waktu tunggu tunggu kunci InnoDB ke nilai yang lebih sesuai untuk kasus penggunaan Anda.Mengenai pertanyaan Anda tentang apa yang Anda lihat dalam laporan, well, 480.000 baris dibaca per detik berarti bahwa rata-rata, 480.000 baris basis data dibaca per detik selama periode waktu yang dicakup laporan.
Saya tidak sepenuhnya nyaman menjawab bagian "apa yang tampak aneh tentang laporan", tetapi saya akan mengatakan bahwa Anda mungkin perlu memberikan lebih banyak informasi dengan cara apa yang sebenarnya berjalan terhadap database untuk mendapatkan jawaban pada itu ... tetapi setiap kali saya melihat nilai baca yang besar, seperti 480 ribu baris dibaca per detik, saya segera mulai bertanya-tanya apa permintaan atau pertanyaan yang melarikan diri dan mencoba membaca seluruh database. Mungkin pengalaman yang lebih banyak DBA memiliki lain mengambilnya, tapi tidak ada yang aneh pada dasarnya saya dapat melihat dalam laporan itu, selain jumlah
updates
dancreates
tidak sesuai dengan volume pembaruan catatan yang Anda katakan sedang Anda lakukan.sumber
updates
? Yah saya pikir 56 Juta sudah banyak berhenti. Apa yang membuat saya merasa ada sesuatu yang salah, adalah 640 Miliar Baca. Apa inireads
? Apakah iniSELECT
Pernyataan?updates
/ s, tetapi laporan MySQL hanya menunjukkan 42,3 / s, yang jauh lebih sedikit dari yang diharapkan untuk volume yang Anda nyatakan. Bahkan menambahkan semuacreates
, Anda secara signifikan dari volume yang Anda katakan Anda miliki. Jika itu karena volume 60.000 / 10 menit adalah angka kasar yang tidak terlalu akurat, bagus, tetapi menonjol bagi saya. Mengenaireads
, ya,SELECT
pernyataan menyebabkanreads
pada database. Jika memilih dari sejumlah besar baris, ia membaca banyak baris. Tapi ya, itu sepertinya sangat tinggi bagi saya.