如何在PolarDB中查询EMP(PolarStore弹性内存池)缓存使用率/命中率?
监控PolarDB EMP(PolarStore Elastic Memory Pool)的缓存指标
启用EMP后,原InnoDB缓冲池命中率指标无变化是因为EMP是独立于InnoDB缓冲池之外的弹性缓存层,InnoDB原生状态变量仅统计自身缓冲池的命中/未命中行为,不会包含EMP的缓存操作。你可以通过以下专属方式监控EMP的缓存使用率与命中率:
1. 查询EMP专属状态变量
PolarDB为EMP提供了专门的全局状态变量,执行以下命令即可查看:
SHOW GLOBAL STATUS LIKE '%emp%';
常见的关键指标包括:
Polar_emp_cache_hits:EMP缓存命中次数Polar_emp_cache_reads:EMP缓存读取请求总数(命中+未命中)Polar_emp_cache_used_memory:EMP已使用的内存大小
EMP命中率计算公式:
EMP命中率 = Polar_emp_cache_hits / (Polar_emp_cache_hits + Polar_emp_cache_reads)
2. 查看系统表与性能视图
(1)EMP统计信息表
查询information_schema下的专属表获取多维度统计数据:
SELECT * FROM information_schema.POLAR_EMP_STATISTICS;
该表包含缓存命中/未命中次数、内存占用量、缓存对象数量等详细信息。
(2)缓存使用率视图
查看EMP的内存使用情况与配置上限:
SELECT pool_name, used_size, total_size FROM information_schema.POLAR_EMP_CACHE_USAGE;
其中total_size为EMP配置的总内存上限,used_size为当前已使用内存。
3. 适配EMP的监控脚本示例
以下是每秒监控EMP命中率的Python脚本:
import mysql.connector import time conn = mysql.connector.connect( host='xxx.xxx.xxx.xxx', port=PORT, user='xxx', password='xxx' ) cursor = conn.cursor() def get_emp_stats(): cursor.execute("SHOW GLOBAL STATUS LIKE 'Polar_emp_cache_hits'") hits = int(cursor.fetchone()[1]) cursor.execute("SHOW GLOBAL STATUS LIKE 'Polar_emp_cache_reads'") reads = int(cursor.fetchone()[1]) return hits, reads print("Press Ctrl+C to exit.") hits_prev, reads_prev = get_emp_stats() while True: time.sleep(1) hits_cur, reads_cur = get_emp_stats() delta_hits = hits_cur - hits_prev delta_reads = reads_cur - reads_prev if delta_reads > 0: rate = delta_hits / delta_reads print("EMP Cache Hit Rate This Second: {:.2%} (Total Requests: {}, Hits: {})".format(rate, delta_reads, delta_hits)) else: print("No EMP read requests in this second.") hits_prev, reads_prev = hits_cur, reads_cur cursor.close() conn.close()
内容的提问来源于stack exchange,提问作者Han
相关产品推荐
相关产品推荐

