[20190401]那个更快的疑问.txt

--//前一阵子,做了11g于10g下,单表单条记录唯一索引扫描的测试,摘要如下:
--//参考链接:
http://blog.itpub.net/267265/viewspace-2636321/
http://blog.itpub.net/267265/viewspace-2636342/

1.环境:
--//当时的测试,在11g下测试结果如下:
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)
-------------------- ---------- ---------------------- -------------
result_cache                 50                   8611        430536
id=1_unique_index            50                   9494        474714
null                         50                  10664        533197
id=1_index                   50                  28160       1407987
notnull                      50                  29279       1463928

--//在10g下测试结果如下:
SCOTT@test> 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)
-------------------- ---------- ---------------------- -------------
id=1_unique_index            50                   4864        243192
notnull                      50                  34134       1706713
id=1_index                   50                  34703       1735173
null                         50                  37234       1861717

--//我的测试环境服务器硬件相同,os版本一样,对比可以发现id=1_unique_index的情况下,10g比11g快了1倍(指id=1_unique_index的情况).
--//而其他方式下11g都明显快于10g,而10g下除了id=1_unique_index下其他执行方式都可以看到大量cbc latch等待事件.
--//而11g仅仅在id=1_index,notnull下看到大量cbc latch等待时间,null方式下(全表扫描)的情况下反而看不到cbc
--//latch等待事件.
--//我一直再想,我是不是测试方法存在什么问题,或者11g做了什么改进?重复测试唯一索引的情况看看:

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

create table t as select rownum id from dual ;
create unique index pk_t on t(id);
create table job_times (sid number, time_ela number,method varchar2(20));
--//分析表略.

$ cat m1.txt
set verify off
host sleep $(echo &&3/50 | bc -l )
insert into job_times values ( sys_context ('userenv', 'sid') ,dbms_utility.get_time ,'&&2') ;
commit ;
declare
v_id number;
v_d date;
begin
    for i in 1 .. &&1 loop
        select /*+ &&3 */ count (*) into v_id from t where id=1;
        --//select /*+ &&3 */ count (*) into v_id from t ;
        --//select /*+ &&3 */ 1 into v_id from dual ;
        --//select /*+ &&3 */ sysdate into v_d from 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

$ sqlplus -s -l scott/book @m1.txt 1e6 id=1_unique_index 0 >/dev/null
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)
-------------------- ---------- ---------------------- -------------
id=1_unique_index             1                   2615          2615

--//在10g环境下重复上面的步骤略.环境:
SCOTT@test> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- ----------------------------------------------------------------
x86_64/Linux 2.4.xx            10.2.0.4.0     Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

$ sqlplus -s -l scott/btbtms @m1.txt 1e6 id=1_unique_index 0 >/dev/null

SCOTT@test> 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)
-------------------- ---------- ---------------------- -------------
id=1_unique_index             1                   1535          1535

--//可以看出即使我单个用户执行相似的sql语句情况下,唯一索引查询10g下明显快于11g.

2.使用strace跟踪看看:
--//执行1e6次有点慢,改成1e5看看.

--//11g的测试:
$ strace -f -c sqlplus -s -l scott/book @m1.txt 1e5 id=1_unique_index 0 >/dev/null
...
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 72.78    0.043919           0    700708           getrusage
 19.80    0.011947           0    200179           times
  6.67    0.004024         671         6         3 wait4
  0.24    0.000147          29         5           clone
  0.18    0.000106           0       375         2 read
  0.16    0.000096           0       264       106 open
...
------ ----------- ----------- --------- --------- ----------------
100.00    0.060341                902967       206 total

--//10g的测试:
$ strace -f -c sqlplus -s -l scott/btbtms @m1.txt 1e5 id=1_unique_index 0 >/dev/null
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 72.00    0.056425           0    700486           getrusage
 24.98    0.019573        2796         7         2 wait4
  0.91    0.000714           3       236           read
  0.74    0.000582          97         6           clone
  0.73    0.000572         286         2           shmdt
  0.23    0.000177           1       302       189 open
  0.16    0.000122           1       145       108 stat
  0.05    0.000042           1        65           write
..
  0.03    0.000025           0       116           times
------ ----------- ----------- --------- --------- ----------------
100.00    0.097352                702291       347 total

--//差异在于10g很少做times的系统调用上.10g下仅仅116次.而11g高达200179.

--//如果再次执行跟踪如下,11g:
$ strace -f  -p 57003
times({tms_utime=1948, tms_stime=328, tms_cutime=0, tms_cstime=0}) = 10865304314
times({tms_utime=1948, tms_stime=328, tms_cutime=0, tms_cstime=0}) = 10865304314
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
times({tms_utime=1948, tms_stime=328, tms_cutime=0, tms_cstime=0}) = 10865304314
times({tms_utime=1948, tms_stime=328, tms_cutime=0, tms_cstime=0}) = 10865304314
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={19, 483038}, ru_stime={3, 285500}, ...}) = 0
times({tms_utime=1948, tms_stime=328, tms_cutime=0, tms_cstime=0}) = 10865304314
times({tms_utime=1948, tms_stime=328, tms_cutime=0, tms_cstime=0}) = 10865304314
--//调用7次getrusage,调用2次times.
--//对比前面的调用比例也可以看出getrusage调用700708,times调用times200179.非常接近7:2

--//而10g下仅仅看到:
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={13, 203992}, ru_stime={1, 700741}, ...}) = 0

--//正是这样的差异导致10g下明显快于11g.
--//顺便看看times输出表示什么?
$ man 2 times
NAME
       times - get process times

SYNOPSIS
       #include <sys/times.h>

clock_t times(struct tms *buf);

DESCRIPTION
       times() stores the current process times in the struct tms that buf points to.  The struct tms is as defined in <sys/times.h>:

struct tms {
              clock_t tms_utime;  /* user time */
              clock_t tms_stime;  /* system time */
              clock_t tms_cutime; /* user time of children */
              clock_t tms_cstime; /* system time of children */
       };

The  tms_utime field contains the CPU time spent executing instructions of the calling process.  The tms_stime
       field contains the CPU time spent in the system while executing tasks on behalf of the calling process.  The
       tms_cutime field contains the sum of the tms_utime and tms_cutime values for all waited-for terminated children.
       The tms_cstime field contains the sum of the tms_stime and tms_cstime values for all waited-for terminated
       children.

Times for terminated children (and their descendants) is added in at the moment wait(2) or waitpid(2) returns
       their process ID. In particular, times of grandchildren that the children did not wait for are never seen.

All times reported are in clock ticks.

RETURN VALUE
       times() returns the number of clock ticks that have elapsed since an arbitrary point in the past.  For Linux 2.4
       and earlier this point is the moment the system was booted.  Since Linux 2.6, this point is (2^32/HZ) -  300
       (i.e.,  about  429 million) seconds before system boot time.  The return value may overflow the possible range of
       type clock_t.  On error, (clock_t) -1 is returned, and errno is set appropriately.

$ cat   /proc/uptime ;uptime
104375436.65 104342102.07
10:12:33 up 1208 days,  1:10,  2 users,  load average: 0.01, 0.01, 0.07

--//我的计算:
2^32 = 4294967296
4294967296-300 = 4294966996 ,文档提到 429 million seconds,不对明显相差10被.难道Hz的单位1/10秒吗?不懂.
4294967296/60-300 = 429496429.6
10437543665+429496429.6 = 10867040094.6
--//这样与上面的结果比较接近了,再次验证看看.

$ strace -f -p 57447 ; cat /proc/uptime
...
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
times({tms_utime=2276, tms_stime=382, tms_cutime=0, tms_cstime=0}) = 10865578855
times({tms_utime=2276, tms_stime=382, tms_cutime=0, tms_cstime=0}) = 10865578855
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={22, 765539}, ru_stime={3, 829417}, ...}) = 0
^CProcess 57447 detached
104377639.45 2484149083.69

4294967296/2593.795/1^6 -300  = 1655562.27747374021462760164

104377639.45+1655562.27747374021462760164
10437763945+(4294967296/10-300) = 10867260374.6

--//存在很大的误差放弃!!

[20190401]那个更快的疑问.txt的更多相关文章

  1. [20190423]那个更快的疑问3.txt

    [20190423]那个更快的疑问3.txt --//前一阵子,做了11g在单表单条记录唯一索引扫描的测试,摘要如下:--//参考链接:http://blog.itpub.net/267265/vie ...

  2. [20190219]那个更快(11g).txt

    [20190219]那个更快(11g).txt --//前几天测试11g Query Result Cache RC Latches时,链接http://blog.itpub.net/267265/v ...

  3. 让你的 Node.js 应用跑得更快的 10 个技巧(转)

    Node.js 受益于它的事件驱动和异步的特征,已经很快了.但是,在现代网络中只是快是不行的.如果你打算用 Node.js 开发你的下一个Web 应用的话,那么你就应该无所不用其极,让你的应用更快,异 ...

  4. 让你的 Node.js 应用跑得更快的 10 个技巧

    Node.js 受益于它的事件驱动和异步的特征,已经很快了.但是,在现代网络中只是快是不行的.如果你打算用 Node.js 开发你的下一个Web 应用的话,那么你就应该无所不用其极,让你的应用更快,异 ...

  5. [20190322]测试相同语句遇到导致cursor pin S的疑问.txt

    [20190322]测试相同语句遇到导致cursor pin S的疑问.txt--//昨天测试遇到的情况,链接:http://blog.itpub.net/267265/viewspace-26388 ...

  6. Gradle更小、更快构建APP的奇淫技巧

    本文已获得原作者授权同意,翻译以及转载原文链接:Build your Android app Faster and Smaller than ever作者:Jirawatee译文链接:Gradle更小 ...

  7. [20171130]关于rman备份疑问.txt

    [20171130]关于rman备份疑问.txt --//前面测试太乱,重新做一些rman as copy相关测试. 1.环境:SCOTT@book> @ &r/ver1PORT_STR ...

  8. linux 下程序员专用搜索源码用来替代grep的软件ack(后来发现一个更快的: ag), 且有vim插件的

    发现一个比ack更快更好用的:  https://github.com/ggreer/the_silver_searcher   , 使用时命令为ag,它是基于ack的代码二次开发的,所有使用方法基本 ...

  9. freopen stdout 真的更快?

    freopen stdout 真的更快? 在一次数独作业中,我发现大部分同学提交的代码中都使用 freopen 来将 stdout 重新指向目标文件进行文件输出操作.我感到十分好奇,关于 freope ...

随机推荐

  1. SpringBoot配置Cors解决跨域请求问题

    一.同源策略简介 同源策略[same origin policy]是浏览器的一个安全功能,不同源的客户端脚本在没有明确授权的情况下,不能读写对方资源. 同源策略是浏览器安全的基石. 什么是源 源[or ...

  2. lua中 table 重构index/pairs元方法优化table内存占用

    转载请标明出处http://www.cnblogs.com/zblade/ lua作为游戏的热更新首选的脚本,其优势不再过多的赘述.今天,我主要写一下如何重写lua中的元方法,通过自己的重写来实现对l ...

  3. Linux笔记总结

    标签: Linux 1. 库  库是一种可执行代码的二进制形式,可以被操作系统载入内存执行.库有两种:静态库(.a..lib)和动态库(.so..dll). a. 静态库   之所以称为[静态库],是 ...

  4. 【原创】《windows驱动开发技术详解》第4章实验总结二

    1 实验要求(WDM驱动)     2 编写过程   2.1 确立整体架构   2.1.1 入口函数——DriverEntry   (1)作用 设置pDriverObject结构体,注册AddDevi ...

  5. [机器学习]集成学习--bagging、boosting、stacking

    集成学习简介 集成学习(ensemble learning)通过构建并结合多个学习器来完成学习任务. 如何产生"好而不同"的个体学习器,是集成学习研究的核心. 集成学习的思路是通过 ...

  6. 浅谈Web服务器和应用服务器的区别

    1Web服务器和应用服务器简介 通俗的讲,Web服务器传送页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序可以调用(call)的方法(methods).确切一点,你可以说:Web服务器专 ...

  7. python按引用赋值和深、浅拷贝

    按引用赋值而不是拷贝副本 在python中,无论是直接的变量赋值,还是参数传递,都是按照引用进行赋值的. 在计算机语言中,有两种赋值方式:按引用赋值.按值赋值.其中按引用赋值也常称为按指针传值(当然, ...

  8. mysql数据库中的数据导入与导出

    需求: 在本地电脑上的mysql中创建了一个数据库,并且在该数据库中创建了很多表,表中数据比较多: 现在想换一台电脑,但是又不想重新建数据库.建表.造数据. 解决方案: 利用mysql提供的命令,在本 ...

  9. 【golang-GUI开发】qt之signal和slot(一)

    想了很久,我决定还是先从signal和slot(信号槽)开始讲起. signal和slot大家一定不陌生,先看一段示例(选自文档): class Counter : public QObject { ...

  10. Ioc原理理解

    IoC理论的背景 我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 如果我们打开机械式手表的后盖,就会看到与上面类似 ...