[20171109]缓存命中率神话.txt

--//在oracle版本的早期,缓存命中率是一个很重要的优化指标,实际上这个根本不重要.
--//一般OLTP系统即使出现严重的性能问题,这个数值也很高,实际上一个简单的情况就能说明问题,
--//比如走hash join的计划,不小心走了nested loop,可能导致逻辑读上升.缓存命令率很高,但是数据库
--//未必运行在最佳性能.

--//这个也是我学习oracle早期一个不好理解的问题,^_^.

--//https://connor-mcdonald.com/2017/11/07/buffer-cache-hit-ratio-blast-from-the-past/给出一个例子,能很好的说明问题.

SYS@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SYS@book> grant select on v_$sysstat to scott ;
Grant succeeded.

--//注:我修改源代码,加入AUTHID CURRENT_USER .不然报如下错误:
SCOTT@book> exec choose_a_hit_ratio(92);
Current ratio is: 90.72333
Another 18142 consistent gets needed...
BEGIN choose_a_hit_ratio(92); END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SCOTT.CHOOSE_A_HIT_RATIO", line 72
ORA-06512: at line 1

--//代码如下:
create or replace
procedure choose_a_hit_ratio(p_ratio number default 99,p_show_only boolean default false) AUTHID CURRENT_USER
  v_phy                number;
  v_db                 number;
  v_con                number;
  v_count              number;
  v_additional_congets number;
  v_hit number;
 
  procedure show_hit is
  begin
    select p.value, d.value, c.value
    into v_phy, v_db, v_con
    from
      ( select value from v$sysstat where name = 'physical reads' ) p,
      ( select value from v$sysstat where name = 'db block gets' ) d,
      ( select value from v$sysstat where name = 'consistent gets' ) c;
    v_hit := 1-(v_phy/(v_db+v_con));
    dbms_output.put_line('Current ratio is: '||round(v_hit*100,5));
  end;
begin
--
-- First we work out the ratio in the normal fashion
--
  show_hit;

if p_ratio/100 < v_hit or p_ratio > 99.9999999 then
    dbms_output.put_line('Sorry - I cannot help you');
    return;
  end if;
--
-- Flipping the formula we can work out how many more consistent gets
-- we need to increase the hit ratio
--
  v_additional_congets := trunc(v_phy/(1-p_ratio/100)-v_db - v_con);

dbms_output.put_line('Another '||v_additional_congets||' consistent gets needed...');

if p_show_only then return; end if;
--
-- Create a simple table to hold 200 rows in a single block
--
  begin
    execute immediate 'drop table dummy';
  exception
    when others then null;
  end;

execute immediate 'create table dummy (n primary key) organization index as '||
                    'select rownum n from all_objects where rownum <= 200';
--
-- Turn off any new 9i connect-by features to ensure we still do lots of
-- logical IO
--
  begin
    execute immediate 'alter session set "_old_connect_by_enabled" = true';
  exception
    when others then null;
  end;
--
-- Grind away until we do all those additional gets
--
  execute immediate '
    select count(*)
    from (
      select n
      from dummy
      connect by n > prior n
      start with n = 1 )
    where rownum < :v_additional_congets' into v_count using v_additional_congets;

show_hit;
end;
/

--//执行如下:

SCOTT@book> set serveroutput on
SCOTT@book> exec choose_a_hit_ratio(85,true);
Current ratio is: 90.71867
Sorry - I cannot help you
PL/SQL procedure successfully completed.

SCOTT@book> exec choose_a_hit_ratio(92,true);
Current ratio is: 90.72316
Another 18144 consistent gets needed...
PL/SQL procedure successfully completed.

SCOTT@book> exec choose_a_hit_ratio(92);
Current ratio is: 90.86547
Another 16374 consistent gets needed...
Current ratio is: 92.06869
PL/SQL procedure successfully completed.

SCOTT@book> exec choose_a_hit_ratio(98);
Current ratio is: 92.33213
Another 443318 consistent gets needed...
Current ratio is: 98.01083
PL/SQL procedure successfully completed.

SCOTT@book> exec choose_a_hit_ratio(99,true);
Current ratio is: 98.0109
Another 598700 consistent gets needed...
PL/SQL procedure successfully completed.

SCOTT@book> exec choose_a_hit_ratio(99);
Current ratio is: 98.01091
Another 598698 consistent gets needed...
Current ratio is: 99.00114
PL/SQL procedure successfully completed.

[20171109]缓存命中率神话.txt相关推荐

  1. 华为云CDN如何提高缓存命中率

    背景信息 CDN缓存命中率低,会导致源站压力大,静态资源访问效率低.您可以针对导致CDN缓存命中率低的具体原因,选择对应的优化策略,来提高CDN的缓存命中率.CDN缓存命中率包括流量命中率和请求命中率 ...

  2. 深入探讨Varnish缓存命中率

    也许你还在为刚才动态内容获得7336.76 reqs/s的吞吐率感到振奋,等等,理想和现实是有差距的,你要忍受现实的残酷,别忘了,我们压力测试中的动态内容都处于全缓存情况下,也就是每次请求都命中缓存, ...

  3. mysql 加快命中_合理配置MySQL缓存 提高缓存命中率

    众所周知,系统读取数据时,从内存中读取要比从硬盘上速度要快好几百倍.故现在绝大部分应用系统,都会最大程度的使用缓存(内存中的一个存储区域),来提高系统的运行效率.MySQL数据库也不例外.在这里,笔者 ...

  4. 合理配置MySQL缓存 提高缓存命中率

    众所周知,系统读取数据时,从内存中读取要比从硬盘上速度要快好几百倍.故现在绝大部分应用系统,都会最大程度的使用缓存(内存中的一个存储区域),来提高系统的运行效率.MySQL数据库也不例外.在这里,笔者 ...

  5. Nginx 缓存命中率

    # 在http头部显示命中方式 location ~* ^.*\.(js|ico|gif|jpg|jpeg|png)$ {proxy_redirect off;proxy_set_header Hos ...

  6. 关于缓存命中率的几个关键问题!

    一.缓存命中率的介绍 命中:可以直接通过缓存获取到需要的数据. 不命中:无法直接通过缓存获取到想要的数据,需要再次查询数据库或者执行其它的操作.原因可能是由于缓存中根本不存在,或者缓存已经过期. 通常 ...

  7. shell 实现memcache缓存命中率监控脚本

    公司有几个服务器开着多个memcached进程,除了要监控他们是否正常telnet通,实例是否存在外还要监控他们的缓存命中率.针对他们的缓存命中率进行报警. 网上有个perl写的,需要编译安装.有个p ...

  8. mysql query cache 命中率_MySQL缓存命中率概述及如何提高缓存命中率

    MySQL缓存命中率概述 工作原理: 查询缓存的工作原理,基本上可以概括为: 缓存SELECT操作或预处理查询(注释:5.1.17开始支持)的结果集和SQL语句: 新的SELECT语句或预处理查询语句 ...

  9. Innodb存储引擎的缓存命中率计算

    数据库的慢查询是我们在生产环境中必须经常检测的,如果慢查询语句过多,说明我们应该增加buffer_pool的大小了.常常检查的指标就是查看缓存命中率是否过低. mysql> show statu ...

最新文章

  1. keras中merge用法总结的言简意赅的
  2. 从技术上还原入侵雅虎服务器是怎么一回事
  3. WebService大讲堂之Axis2(2):复合类型数据的传递
  4. 算法整理:Boyer-Moore 投票算法
  5. mysql数据库自动化脚本备份_mysql 自动化脚本备份
  6. 安装readline出现错误
  7. java xmlutil_XmlUtil工具类(toxml()和toBean())
  8. Kali2020.1安装AWVS12 详细过程
  9. 21天学通C语言-学习笔记(4)
  10. 关于N卡录制双音轨问题以及PR2020 注册机
  11. 用 PS 去除图片中文字的方法
  12. Permutation 和 Combination
  13. 线性时不变因果系统的判断方法
  14. 关于gitlab启动后,浏览器git clone 还是localhost问题记录
  15. 红米4鸿蒙系统刷机包,小米 红米4 高配版获取Root权限服务含精简系统方案
  16. 一、基于wifi控制的智能家居系统之项目简介和设计方案(硬件基于arduino+esp8266,软件Android+Web端+scoket服务器,实现语音控制)
  17. fcpx插件:stupid raisins info pop for mac(27个标题字幕栏)
  18. 房屋出租系统(初级)
  19. python.exe-找不到序数:无法定位序数242与动态链接库libiomp5md.dll上。
  20. 美国陆军:2045年20项新兴科技趋势报告

热门文章

  1. SPOJ MULTQ3 7299 Multiples of 3 (区间更新)
  2. 机器人(机械臂)动力学建模方法(Newton-Euler equation)
  3. bloc+rxdart解决代码混乱大问题
  4. 蓝桥杯C/C++ 带分数
  5. Linux系统存储交换机日志
  6. JAVA-数据库之JDBC连接MySQL数据库
  7. unity3d : Failed to query D3D11 context for ID3DUserDefinedAnnotation interface (hr = 0x80004002)
  8. cmd系统命令不识别
  9. A+B Problem 详细解答 (转载)
  10. 【Android实战】记录自学自己定义GifView过程,能同一时候支持gif和其它图片!【有用篇】...