对mysql做压力测试,测试完之后,mysql的内存一直不下降
$ free -m total used free shared buff/cache availableMem: 128669 107316 2821 649 18531 19970Swap: 0 0 0
# top -u mysqltop - 16:21:21 up 6 days, 23:41, 5 users, load average: 0.00, 0.85, 2.93Tasks: 427 total, 1 running, 425 sleeping, 1 stopped, 0 zombie%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 stKiB Mem : 13175748+total, 2238988 free, 11056342+used, 18955080 buff/cacheKiB Swap: 0 total, 0 free, 0 used. 19794852 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 6059 mysql 20 0 0.154t 0.102t 8888 S 0.0 82.9 4033:55 mysqld
使用了0.102*1024=104G,需要0.154*1024=157G,buffer_pool占用了80G,一直不释放,调整buffer_pool_size到70G
mysql> show variables like '%pool_size%';+-------------------------+-------------+| Variable_name | Value |+-------------------------+-------------+| innodb_buffer_pool_size | 85899345920 |+-------------------------+-------------+1 row in set (0.00 sec)mysql> select 70*1024*1024*1024;+-------------------+| 70*1024*1024*1024 |+-------------------+| 75161927680 |+-------------------+1 row in set (0.00 sec)mysql> set global innodb_buffer_pool_size=75161927680;Query OK, 0 rows affected (0.01 sec)
调整后,内存立即就释放了;free和available两项都有增加
$ free -m total used free shared buff/cache availableMem: 128669 96811 13326 649 18531 30476Swap: 0 0 0
之后又调整buffer_pool_size到80G,发现mysql占用的内存又慢慢上来了,看来mysql的buffer_pool_size会占用固定的内存大小。最后将buffer_pool_size设置为了物理内存的一半。