mysql計算共享池命中率 計算記憶體命中率

2021-10-18 11:58:50 字數 4456 閱讀 9313

(1)lc的命中率:

.計算公式:library cache hit ratio = sum(pinhits) / sum(pins)

selectsum(pinhits)/sum(pins)fromv$librarycache

通常在98%以上,否則,需要要考慮加大共享池,繫結變數,修改cursor_sharing等引數。

.計算共享池記憶體使用率:

select(1-round(bytes/(&tsp_in_m*1024*1024),2))*100||'%'fromv$sgastatwherename='free memory'andpool='shared pool';

其中: &tsp_in_m是你的總的共享池的size(m)

共享池記憶體使用率,應該穩定在75%-90%間,太小浪費記憶體,太大則記憶體不足。

查詢空閒的共享池記憶體:

select*fromv$sgastatwherename='free memory'andpool='shared pool';

(2)pga的命中率:

計算公式:bp x 100 / (bp + ebp)

bp:bytes processed

ebp:extrabytesread/written

select*fromv$pgastatwherename='cache hit percentage';

或者從oem的圖形介面中檢視

我們可以檢視乙個檢視以獲取oracle的建議值:

select round(pga_target_for_estimate/1024/1024) target_mb,

estd_pga_cache_hit_percentage cache_hit_perc,

estd_overalloc_count

from v$pga_target_advice;

the output of this query might look like the following:

target_mb cache_hit_perc estd_overalloc_count

63              23                   367

125              24                    30

250              30                     3

375              39                     0

500              58                     0

600              59                     0

700              59                     0

800              60                     0

900              60                     0

1000              61                     0

1500              67                     0

2000              76                     0

3000              83                     0

4000              85                     0

在此例中:pga至少要分配375m

我個人認為pga命中率不應該低於50%

以下的sql統計sql語句執行在三種模式的次數: optimal memory size, one-pass memory size, multi-pass memory size:

select name profile, cnt, decode(total, 0, 0, round(cnt*100/total,4)) percentage

from (select name, value cnt, (sum(value) over ()) total from v$sysstat where name like 'workarea exec%');

計算在記憶體中排序的比率:

select * from v$sysstat t where name='sorts (memory)'—查詢記憶體排序數--select * from v$sysstat t where name='sorts (disk)'—查詢磁碟排序數--caculate sort in memory ratioselect round(&sort_in_memory/(&sort_in_memory+&sort_in_disk),4)*100||'%' from dual

此比率越大越好,太小整要考慮調整,加大pga

(3)db buffer cache命中率:

計算公式:hit ratio = 1 - [physical reads/(block gets + consistent gets)]

select name, physical_reads, db_block_gets, consistent_gets,

1 - (physical_reads / (db_block_gets + consistent_gets)) "hit ratio"

from v$buffer_pool_statistics

where name='default';

通常應在90%以上,否則,需要調整,加大db_cache_size

另外一種計算命中率的方法(摘自oracle官方文件<>):

select name, value

from v$sysstat

where name in('session logical reads',

'physical reads',

'physical reads direct',

'physical reads direct (lob)',

'db block gets', 'consistent gets');

命中率的計算公式為:hit ratio = 1 - ((physical reads - physical reads direct - physical reads direct (lob)) /

(db block gets + consistent gets - physical reads direct - physical reads direct (lob))

分別代入上一查詢中的結果值,就得出了buffer cache的命中率

幾個常用的檢查語句

1.查詢排序最多的sql:

select hash_value, sql_text, sorts, executions

from v$sqlarea

order by sorts desc;

2.查詢磁碟讀寫最多的sql:

select * from

(select sql_text,disk_reads "total disk" ,

executions "total exec",disk_reads/executions "disk/exec" from v$sql where executions>0

and is_obsolete='n' order by 4 desc)

where rownum<11

3.查詢工作量最大的sql(實際上也是按磁碟讀寫來排序的):

selectsubstr(to_char(s.pct, '99.00'), 2) || '%' load,s.executions executes,p.sql_textfrom(selectaddress,disk_reads,executions,pct,rank() over (order by disk_reads desc) rankingfrom(selectaddress,disk_reads,executions,100 * ratio_to_report(disk_reads) over () pctfromsys.v_$sqlwherecommand_type != 47)wheredisk_reads > 50 * executions) s,sys.v_$sqltext pwheres.ranking <= 5 andp.address = s.addressorder by1, s.address, p.piec 4.用下列sql工具找出低效sql:select executions , disk_reads, buffer_gets,

round((buffer_gets-disk_reads)/buffer_gets,2) hit_radio,

round(disk_reads/executions,2) reads_per_run,

sql_text

from v$sqlarea

where executions>0

and buffer_gets > 0

and (buffer_gets-disk_reads)/buffer_gets < 0.8

order by 4 desc;

redis命中率計算

redis提供了info這個命令,能夠隨時監控伺服器的狀態,只用telnet到對應伺服器的埠,執行命令即可 telnet localhost 6379 info在輸出的資訊裡面有這幾項和快取的狀態比較有關係 keyspace hits 14414110 keyspace misses 3228654...

redis命中率計算

redis提供了info這個命令,能夠隨時監控伺服器的狀態,只用telnet到對應伺服器的埠,執行命令即可 quote telnet localhost 6379 info quote 在輸出的資訊裡面有這幾項和快取的狀態比較有關係 quote keyspace hits 14414110 keys...

Redis命中率計算

redis提供info命令,能夠隨時監控伺服器的狀態,只用telnet到對應伺服器的埠,執行命令即可 telnet localhost 6379 info在輸出的資訊裡面有這幾項和快取的狀態比較有關係 keyspace hits 14414110 keyspace misses 3228654 us...