[20190320]测试相同语句遇到导致cursor pin S的情况.txt

--//前面测试链接:http://blog.itpub.net/267265/viewspace-2636342/
--//各个会话执行语句相同的,很容易出现cursor: pin S等待事件.看看如果各个会话执行的语句不同.
--//测试结果如何呢?

-//后记:补充说明测试不严谨,请参考链接:http://blog.itpub.net/267265/viewspace-2639097/

1.环境:
SCOTT@book> @ 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

2.建立测试脚本:
create table job_times (sid number, time_ela number,method varchar2(20));

$ cat mutex.sql
set verify off
insert into job_times values ( sys_context ('userenv', 'sid') ,dbms_utility.get_time ,'&&2') ;
declare
v_id number;
v_d date;
begin
    for i in 1 .. &&1 loop
        select /*+ &&3 */ sysdate from into v_date dual;
        --select  sysdate from into v_date dual;
    end loop;
end ;
/
update job_times set time_ela = dbms_utility.get_time - time_ela where sid=sys_context ('userenv', 'sid') and method='&&2';
commit;
quit

$ cat mutex1.sql
set verify off
insert into job_times values ( sys_context ('userenv', 'sid') ,dbms_utility.get_time ,'&&2') ;
declare
v_id number;
v_d date;
begin
    for i in 1 .. &&1 loop
        --select /*+ &&3 */ sysdate from into v_date dual;
        select  sysdate from into v_date dual;
    end loop;
end ;
/
update job_times set time_ela = dbms_utility.get_time - time_ela where sid=sys_context ('userenv', 'sid') and method='&&2';
commit;
quit

--//通过加入注解&&3,产生每个会话执行语句不同,对比看看.

3.测试:
exec dbms_workload_repository.create_snapshot();
host seq 150 | xargs -I{} -P 150 bash -c  "sqlplus -s -l scott/book @mutex.sql  1e6 test1 {} >/dev/null"
exec dbms_workload_repository.create_snapshot();
host seq 150 | xargs -I{} -P 150 bash -c  "sqlplus -s -l scott/book @mutex1.sql 1e6 test2 {} >/dev/null"
exec dbms_workload_repository.create_snapshot();

--//测试1,执行时等待事件集中在latch: shared pool.
--//测试2,执行时等待事件集中在cursor: pin S.

SCOTT@book> select method,count(*),round(avg(TIME_ELA),0),sum(TIME_ELA) from job_times group by method order by 3 ;
METHOD                 COUNT(*) ROUND(AVG(TIME_ELA),0) SUM(TIME_ELA)
-------------------- ---------- ---------------------- -------------
test1                       150                  19897       2984502
test2                       150                  19380       2907006

--//奇怪的是,测试实际上测试1反而慢一点.从这个测试可以看出,如果如果应用真有大量语句出现cursor争用,通过打散语句的执行,
--//可能未必能提高执行效率.

--//test1的awr报表:
              Snap Id      Snap Time      Sessions Curs/Sess
            --------- ------------------- -------- ---------
Begin Snap:      1681 20-Mar-19 09:53:01        27       1.2
  End Snap:      1682 20-Mar-19 09:56:23        28       1.2
   Elapsed:                3.37 (mins)
   DB Time:              497.85 (mins)

...
Top 10 Foreground Events by Total Wait Time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                            Tota    Wait   % DB           
Event                                 Waits Time Avg(ms)   time Wait Class
------------------------------ ------------ ---- ------- ------ ----------
latch: shared pool                  233,755 18.6      79   62.2 Concurrenc
DB CPU                                      4751           15.9           
library cache: mutex X                  828 13.7      17     .0 Concurrenc
cursor: pin S wait on X                  68  1.4      20     .0 Concurrenc
library cache load lock                  94  1.1      12     .0 Concurrenc
log file sync                           141   .5       4     .0 Commit    
wait list latch free                     50   .3       6     .0 Other     
enq: SQ - contention                      2    0      10     .0 Configurat
library cache lock                        2    0       8     .0 Concurrenc
SQL*Net message to client             2,560    0       0     .0 Network

--//出现了latch: shared pool大量争用.反而测试2使用mutex的效率更高.

--//test2的awr报表:
             Snap Id      Snap Time      Sessions Curs/Sess
            --------- ------------------- -------- ---------
Begin Snap:      1682 20-Mar-19 09:56:23        28       1.2
  End Snap:      1683 20-Mar-19 09:59:40        28       1.2
   Elapsed:                3.28 (mins)
   DB Time:              484.76 (mins)

...
Top 10 Foreground Events by Total Wait Time
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                            Tota    Wait   % DB           
Event                                 Waits Time Avg(ms)   time Wait Class
------------------------------ ------------ ---- ------- ------ ----------
cursor: pin S                       585,684 12.1      21   41.6 Concurrenc
DB CPU                                      4611           15.9           
library cache: mutex X                  525  8.6      16     .0 Concurrenc
latch: shared pool                      117  1.5      13     .0 Concurrenc
latch free                               45  1.3      28     .0 Other     
log file sync                           129   .5       4     .0 Commit    
cursor: pin S wait on X                  44   .4       9     .0 Concurrenc
library cache load lock                  57   .3       6     .0 Concurrenc
row cache lock                           18   .2      10     .0 Concurrenc
enq: SQ - contention                      3    0      11     .0 Configurat

--//对比测试2的cursor: pin S使用12.1秒.而测试1的latch: shared pool使用18.6秒,差距并不大.
--//可以看出使用oracle使用mutex效率更高.

--//另外从一个侧面说明,如果应用大量重复语句执行出现cursor: pin S争用,通过分散的方式也许更加并不是最佳的.
--//减少语句的执行次数才是比较正确的处理问题方式,或者找到为什么执行次数这么高的原因.

--//我又重复测试1次.test1修改testa,test2修改testb.

SCOTT@book> select method,count(*),round(avg(TIME_ELA),0),sum(TIME_ELA) from job_times group by method order by 3 ;
METHOD                 COUNT(*) ROUND(AVG(TIME_ELA),0) SUM(TIME_ELA)
-------------------- ---------- ---------------------- -------------
test2                       150                  19380       2907006
testb                       150                  19648       2947223
testa                       150                  19884       2982666
test1                       150                  19897       2984502

--//结论依旧.
--//如果减少测试用户连接数量呢?测试并发用户50的情况:
$ cat aa3.txt
exec dbms_workload_repository.create_snapshot();
host seq 50 | xargs -I{} -P 50 bash -c  "sqlplus -s -l scott/book @mutex.sql  1e6 test50a {} >/dev/null"
exec dbms_workload_repository.create_snapshot();
host seq 50 | xargs -I{} -P 50 bash -c  "sqlplus -s -l scott/book @mutex1.sql 1e6 test50b {} >/dev/null"
exec dbms_workload_repository.create_snapshot();

SCOTT@book> select method,count(*),round(avg(TIME_ELA),0),sum(TIME_ELA) from job_times group by method order by 3 ;
METHOD                 COUNT(*) ROUND(AVG(TIME_ELA),0) SUM(TIME_ELA)
-------------------- ---------- ---------------------- -------------
test50b                      50                   6437        321825
test50a                      50                   6791        339554
test2                       150                  19380       2907006
testb                       150                  19648       2947223
testa                       150                  19884       2982666
test1                       150                  19897       2984502
6 rows selected.

--//你可以发现在并发用户50的情况下,情况不变,结论依旧.改成并发用户10的情况呢?
--//还可以发现现在同样的工作量,50个并发的情况下,6X秒就可以完成.

SCOTT@book> select method,count(*),round(avg(TIME_ELA),0),sum(TIME_ELA) from job_times group by method order by 3 ;
METHOD                 COUNT(*) ROUND(AVG(TIME_ELA),0) SUM(TIME_ELA)
-------------------- ---------- ---------------------- -------------
testi10b                     10                   1872         18724
testi10a                     10                   2003         20028
test50b                      50                   6437        321825
test50a                      50                   6791        339554
test2                       150                  19380       2907006
testb                       150                  19648       2947223
testa                       150                  19884       2982666
test1                       150                  19897       2984502
8 rows selected.

--//有点奇怪为什么测试1会出现大量的latch: shared pool.
--//这个测试有点像按下葫芦起了瓢,也说明任何问题都给辩证的看.

总结:
--//在测试前我一直以为测试1会块一些,实际情况正好相反.
--//不过为什么这样,我还不是很清楚....

转载于:https://www.cnblogs.com/lfree/p/10565266.html

[20190320]测试相同语句遇到导致cursor pin S的情况.txt相关推荐

  1. cursor:pin S wait on X故障诊分析

    1.    故障概述 7:15,二节点出现大量的"cursor: pin S wait on X"等待事件,数据库性能下降,持续到7:19分恢复正常,持续时间4分钟左右. 下面是详 ...

  2. EM12C监控遇到 ‘cursor: pin S wait on X’ waits.

    最近安装了EM12C,对上有ERP应用的所有库进行监控.EM12C相对之前的grid control还是改进比较大的.安装也蛮简单. 今早一来发现一库有大量的并发,如下图,图1-1: 点上图,图1-1 ...

  3. 并行insert出现library cache lock与cursor: pin S wait on X等待问题记录

    一. 故障现象与紧急处理 开发反馈凌晨5点左右应用出现大量报错 ORA-04021: timeout occurred while waiting to lock object,并且集中出现在inse ...

  4. oracle open hang 等待cursor: pin S wait on X---惜分飞

    客户19.3数据库无法在open过程hang住 分析alert日志 2022-10-18T15:04:57.374918+08:00 db_recovery_file_dest_size of 102 ...

  5. 测试sql语句执行时间

    测试sql语句执行时间,备档用的 新建表:pagetest --添加数据 declare @i int set @i=0 while(@i<90000) begin insert into pa ...

  6. 遭遇cursor:pin x等待事件定位阻塞会话诊断过程

    环境描述:DB:10.2.0.4.0 /OS:AIX 5.3 (64bit) 问题描述: 1.会话A执行如下命令被挂起 SQL> exec dbms_shared_pool.purge('070 ...

  7. 由于uvc驱动函数缺少return语句而导致内核oops的一例

    一.实验环境 1.软件 a) Vmware版本:Vmware Workstation 12.5.7 b) Ubuntu版本:9.10 c) 内核版本:2.6.31.14 d) gcc版本:4.4.1 ...

  8. mysql sql测试_MySQL语句测试——数据查询

    MySQL语句测试--数据查询 3.4 数据查询 一.单表查询 /*1.选择表中的若干列,各个列的先后顺序和语句中列名从左到右的顺序一致 select 目标表达式 from 表名; */ /*(1)s ...

  9. 测试sql语句的执行效率

    测试数据库查询语句的执行效率 declare @d datetime set @d=getdate() select * from orders select [语句执行花费时间(毫秒)]=dated ...

最新文章

  1. WinCE下冷启动程序自动安装装载
  2. java display.getdefault()_java基础(十一 )-----反射——Java高级开发必须懂的
  3. 每天只能发十篇文章的限制引发的连锁反应
  4. html加载出来图片乱掉,HTML基础 img alt 图片加载失败时,出现替代文本
  5. 《现代前端技术解析》读后鬼扯
  6. Message 消息提示
  7. docker容器cpu高问题排查_干货详解:一文教你如何利用阿里开源工具,排查线上CPU居高问题...
  8. vue引用自定义.css文件 - 语法篇
  9. gridview textbox onblur触发按钮_按钮式的密封罐,人手一个都嫌少!
  10. 手机输入法带拼音声调_这些神奇的拼音输入法,你都知道几个?
  11. 阿里巴巴交易平台技术揭秘
  12. 用友适合套打的打印机所有型号和问题
  13. Ceph测试工具总结
  14. 数字化营销服务-如何进行数字化营销?
  15. 位深度8位什么水平_佳能1DX3视频12位RAW拍摄和8位mp4拍摄的色彩有多大差别
  16. VirtualBox 打开虚拟机后,上面的那栏菜单栏不见了的解决办法
  17. 计算机桌面图标多一个箭头,怎么去掉电脑桌面图标箭头(一个小妙招解决win图标小箭头)...
  18. 在线教育直播系统 一对一在线直播平台解决方案
  19. 介绍国内外CMS系统
  20. CA运作模式-认证与过期吊销

热门文章

  1. TCL电视本地升级和强制刷机固件的区别
  2. 2022年技术人365篇写作计划-在赚钱这件事情上,人与人的差别究竟在哪里?
  3. 丽升网上阅卷系统服务器地址,丽升网上阅卷系统介绍书(校园版).doc
  4. JavaWeb - 验证码
  5. 查看sensor和海思芯片数据传送信息的命令
  6. NeuroImage:多模态超扫描揭示母与子在身体和心灵上的同步
  7. Android中播放DSD音乐
  8. 音乐服务器 linux,新西兰Antipodes推CX音乐服务器,采用精简版Linux操作系统
  9. ​ 干货分享|letswave 操作手册
  10. 浏览器隐藏滚动条(不影响内容滚动)