应当增加缓冲池实例的数量,以避免缓冲池互斥争用。
如果缓冲池大小为8GB,我怀疑您是否会看到缓冲池互斥争用。
更新0:
我在回答中提到8Gb缓冲池,而在最初的问题中,总内存为8GB。当然,缓冲池必须小于8GB。4GB听起来是个不错的开始,但请确保没有发生交换。
更新1:
// Yasufumi的幻灯片(在最新的MySQL版本中,输出可能略有不同)
要确定缓冲池互斥锁上是否存在争用,请SHOW ENGINE INNODB STATUS
在高峰时间收集十二个样本。
然后使用shell片段对其进行聚合:
#!/bin/sh
cat $1.innodb | grep "Mutex at " | cut -d"," -f1 | sort | uniq -c > /tmp/tmp1.txt
cat $1.innodb | grep "lock on " | cut -d"-"
-f2- | sort | uniq -c > /tmp/tmp2.txt
cat /tmp/tmp1.txt /tmp/tmp2.txt | sort -n > $1.contention rm /tmp/tmp1.txt /tmp/tmp2.txt
给出这样的输出:
.....
4 lock on RW-latch at 0x7fb86b2c9138 created in file dict/dict0dict.c line 1356
6 lock on RW-latch at 0x7fb86b2c4138 created in file dict/dict0dict.c line 1356
12 lock on RW-latch at 0x7fb86b2d9538 created in file dict/dict0dict.c line 1356
20 lock on RW-latch at 0x7fb86b2db138 created in file dict/dict0dict.c line 1356
22 Mutex at 0x7fb86b28f0e0 created file btr/btr0sea.c line 139
30 lock on RW-latch at 0x7fb86b2ba938 created in file dict/dict0dict.c line 1356
36 lock on RW-latch at 0x7fb86b2bad38 created in file dict/dict0dict.c line 1356
71 Mutex at 0x7fb86b28ecb8 created file buf/buf0buf.c line 597
164 lock on RW-latch at 0x7fb86b28f0b8 created in file btr/btr0sea.c line 139
如果看到大量的缓冲池互斥锁等待,那么该考虑多个缓冲池实例了。在小于约48G的缓冲池中,争用不太可能发生。