SELECT SUM(modified_database_pages) AS total_modified_database_pages, SUM(pages_made_young) AS total_pages_made_young, SUM(pages_not_made_young) AS total_pages_not_made_young, SUM(hit_rate)/COUNT(hit_rate)*1000 AS hit_rate FROM ( SELECT pool_id, pool_size, database_pages, old_database_pages, modified_database_pages, pages_made_young, pages_not_made_young, hit_rate FROM information_schema.innodb_buffer_pool_stats )t;
参考https://www.cnblogs.com/geaozhang/p/7276802.html这里对这pages_made_young和page_not_made_young,个人觉得解释的非常好。
这里低负载下的information_schema.innodb_buffer_pool_stats中的信息,hit_rate的值简直不可思议。
这个���例是4GB的内存,基本上没有访问量,hit_rate竟然出来好多值为0的情况。
相反在对当前实例做压力测试的时候,这个数据看起来才是正常的,包括modified_database_pages,pages_made_young,pages_not_made_young,hit_rate
这里用mysqlslap 做混合读写的压力测试
./mysqlslap -uroot -proot -h127.0.0.1 -P8000 --concurrency=100 --iterations=10000 --auto-generate-sql --auto-generate-sql-add-autoincrement --auto-generate-sql-load-type=mixed --engine=innodb --number-of-queries=10000
用Python定时打印innodb_buffer_pool_stats
import pymysql import logging import time import decimal def execute_query(conn_dict,sql): conn = pymysql.connect(host=conn_dict['host'], port=conn_dict['port'], user=conn_dict['user'], passwd=conn_dict['password'], db=conn_dict['db']) cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute(sql) list = cursor.fetchall() cursor.close() conn.close() return list def check_innodb_buffer_pool_stats(flag,conn_dict): result = execute_query(conn_dict, '''SELECT modified_database_pages, pages_made_young, pages_not_made_young, hit_rate FROM information_schema.innodb_buffer_pool_stats;''') if result: column = result[0].keys() current_row = '' if(flag<=0): for key in column: current_row += str(key) + " " print(current_row) for row in result: current_row = '' for key in row.values(): current_row += str(key) + " " print(current_row) if __name__ == '__main__': conn = {'host': '127.0.0.1', 'port': my_port, 'user': 'root', 'password': '***', 'db': 'mysql', 'charset': 'utf8mb4'} flag = 0 while 1>0: check_innodb_buffer_pool_stats(flag,conn) time.sleep(3) flag = 1
这样子看下来,这个统计还是比较正常的。