欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

[20190417]隐含参数_SPIN_COUNT.txt

程序员文章站 2022-04-19 15:35:14
[20190417]隐含参数_SPIN_COUNT.txt--//在探究latch spin计数之前,先简单探究_SPIN_COUNT.实际上oracle现在版本latch spin的数量不再是2000,而是记录在--//x$ksllclass里面.通过例子说明:1.环境:SYS@book> @ v ......

[20190417]隐含参数_spin_count.txt

--//在探究latch spin计数之前,先简单探究_spin_count.实际上oracle现在版本latch spin的数量不再是2000,而是记录在
--//x$ksllclass里面.通过例子说明:

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

sys@book> select * from x$ksllclass ;
addr                   indx    inst_id       spin      yield   waittime     sleep0     sleep1     sleep2     sleep3     sleep4     sleep5     sleep6     sleep7
---------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
00000000861986c0          0          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861986ec          1          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198718          2          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
0000000086198744          3          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198770          4          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
000000008619879c          5          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987c8          6          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987f4          7          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
8 rows selected.

sys@book> select class_ksllt,count(*) from x$kslltr group by class_ksllt;
class_ksllt   count(*)
----------- ----------
          2          1
          0        581
sys@book> select class_ksllt,decode(class_ksllt,2,kslltnam) name,count(*) from x$kslltr group by  class_ksllt,decode(class_ksllt,2,kslltnam);
class_ksllt name               count(*)
----------- ------------------ --------
          0                         581
          2 process allocation        1

--//还可以看出仅仅1个latch属于2类(latch name='process allocation').其它都是0类.实际上即使是0类,后面的sleep0-7不再使用.
--//可以发现缺省全部spin=20000.

2.测试1:
sys@book> alter system set "_spin_count"=200 scope=memory;
system altered.

--//实际上动态修改无效.重新登录会话:
sys@book> select * from x$ksllclass ;
addr                   indx    inst_id       spin      yield   waittime     sleep0     sleep1     sleep2     sleep3     sleep4     sleep5     sleep6     sleep7
---------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
00000000861986c0          0          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861986ec          1          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198718          2          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
0000000086198744          3          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198770          4          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
000000008619879c          5          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987c8          6          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987f4          7          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
8 rows selected.

--//spin数量不变.实际上动态修改,对应exclusive latch无效.仅仅对shared latch有效,导致实际spin 数量等于_spin_count*2.(我当前没有测试)
--//参考链接:http://andreynikolaev.wordpress.com/2011/01/14/spin-tales-part-2-shared-latches-in-oracle-9-2-11g/

3.测试2:
sys@book> alter system set "_spin_count"=200 scope=spfile ;
system altered.

--//重启数据库观察:
sys@book> select * from x$ksllclass ;
addr                   indx    inst_id       spin      yield   waittime     sleep0     sleep1     sleep2     sleep3     sleep4     sleep5     sleep6     sleep7
---------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
00000000861986c0          0          1        200          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861986ec          1          1        200          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198718          2          1        200          0          1       8000       8000       8000       8000       8000       8000       8000       8000
0000000086198744          3          1        200          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198770          4          1        200          0          1       8000       8000       8000       8000       8000       8000       8000       8000
000000008619879c          5          1        200          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987c8          6          1        200          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987f4          7          1        200          0          1       8000       8000       8000       8000       8000       8000       8000       8000
8 rows selected.
--//这样更改才生效.
sys@book> alter system reset "_spin_count";
system altered.

--//实际上可以但是设置_latch_class_n参数.
sys@book> alter system set "_latch_class_0"=1000 scope=spfile;
system altered.

--//重启数据库观察:
sys@book> select * from x$ksllclass ;
addr                   indx    inst_id       spin      yield   waittime     sleep0     sleep1     sleep2     sleep3     sleep4     sleep5     sleep6     sleep7
---------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
00000000861986c0          0          1       1000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861986ec          1          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198718          2          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
0000000086198744          3          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198770          4          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
000000008619879c          5          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987c8          6          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987f4          7          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
8 rows selected.

--//你甚至指定特定的latch采用特定的类.还可以修改后面的yield,waittime,sleep0-sellp7值.例子:
*._latch_classes='8:3'
*._latch_class_3='100 0 1 10000 20000 30000 40000 50000 60000 70000 80000'

sys@book> select * from v$latchname where name='process allocation';
    latch# name                                           hash
---------- ---------------------------------------- ----------
         8 process allocation                       2600548697

--//_latch_classes 里面8 值latch#,后面3值类.可以指定多个,例子:
--//alter system set "_latch_classes"='46:3 103:3' scope=spfile;
--//还原:
sys@book> alter system reset "_latch_class_0";
system altered.

4.加强记忆我找一个latch测试看看:
--//上午测试是process allocation,现在测试看看类0的修改是否有效.
select addr,name,level#,latch#,gets,misses,sleeps,immediate_gets,immediate_misses,waiters_woken,waits_holding_latch,spin_gets,wait_time from v$latch_parent   where lower(name) like '%'||lower('test excl. parent l0')||'%'
addr             name                                         level#     latch#       gets     misses     sleeps immediate_gets immediate_misses waiters_woken waits_holding_latch  spin_gets  wait_time
---------------- ---------------------------------------- ---------- ---------- ---------- ---------- ---------- -------------- ---------------- ------------- ------------------- ---------- ----------
00000000600098d8 test excl. parent l0                              0          4          7          0          0              0                0             0                   0          0          0

--//latch#=4.
sys@book> create pfile='/tmp/@.ora' from spfile ;
file created.

--//修改/tmp/book.ora 加入:
*._latch_classes='4:3'
*._latch_class_3='100 0 1 10000 20000 30000 40000 50000 60000 70000 50000'

sys@book> startup pfile=/tmp/@.ora
oracle instance started.
total system global area  643084288 bytes
fixed size                  2255872 bytes
variable size             205521920 bytes
database buffers          427819008 bytes
redo buffers                7487488 bytes
database mounted.
database opened.

sys@book> select * from x$ksllclass ;
addr                   indx    inst_id       spin      yield   waittime     sleep0     sleep1     sleep2     sleep3     sleep4     sleep5     sleep6     sleep7
---------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
00000000861986c0          0          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861986ec          1          1      20000          0          1       1000       1000       1000       1000       1000       1000       1000       1000
0000000086198718          2          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
0000000086198744          3          1        100          0          1      10000      20000      30000      40000      50000      60000      70000      50000
0000000086198770          4          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
000000008619879c          5          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987c8          6          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
00000000861987f4          7          1      20000          0          1       8000       8000       8000       8000       8000       8000       8000       8000
8 rows selected.

sys@book> select class_ksllt,decode(class_ksllt,2,kslltnam,3,kslltnam) name,count(*) from x$kslltr group by  class_ksllt,decode(class_ksllt,2,kslltnam,3,kslltnam);
class_ksllt name                                       count(*)
----------- ---------------------------------------- ----------
          0                                                 580
          3 test excl. parent l0                              1
          2 process allocation                                1
--//latch_name='test excl. parent l0',class_ksllt=3.

$ cat p4.sh
#! /bin/bash
vdate=$(date '+%h%m%s')
echo $vdate

source peek.sh "$1" 20 | timestamp.pl >| /tmp/peekx_${vdate}.txt &

sqlplus -s -l / as sysdba <<eof  >| /tmp/latch_free_${vdate}.txt &
$(seq 20 | xargs -i {} echo -e '@latch_free \n host sleep 1')
eof

sleep 1
# 参数如下: @ exclusive_latch.txt latch_name willing why where  sleep_num
sqlplus /nolog @ exclusive_latch.txt "$1" 1 4 5 10 > /dev/null &
sleep 2
sqlplus /nolog @ exclusive_latch.txt "$1" 1 6 7 10 > /dev/null &
p=$!
strace -ftrt  -p $p -o /tmp/pp_${vdate}.txt > /dev/null &
wait

$ . p4.sh 'test excl. parent l0'
172843
process 29626 attached - interrupt to quit
process 29628 attached
process 29645 attached
process 29626 suspended
[1]   done                    source peek.sh "$1" 20 | timestamp.pl >|/tmp/peekx_${vdate}.txt
[3]   done                    sqlplus /nolog @ exclusive_latch.txt "$1" 1 4 5 10 > /dev/null
[2]   done                    sqlplus -s -l / as sysdba  >|/tmp/latch_free_${vdate}.txt <<eof
$(seq 20 | xargs -i {} echo -e '@latch_free \n host sleep 1')
eof

process 29626 resumed
process 29645 detached
process 29626 detached
[4]-  done                    sqlplus /nolog @ exclusive_latch.txt "$1" 1 6 7 10 > /dev/null
process 29628 detached
[5]+  done                    strace -ftrt -p $p -o /tmp/pp_${vdate}.txt > /dev/null

--// /tmp/pp_172843.txt
29628      0.000081 write(10, "\n", 1)  = 1 <0.000026>
29628      0.000149 select(0, [], [], [], {0, 10000}) = 0 (timeout) <0.010082>
29628      0.010161 select(0, [], [], [], {0, 20000}) = 0 (timeout) <0.020110>
29628      0.020195 select(0, [], [], [], {0, 30000}) = 0 (timeout) <0.030115>
29628      0.030207 select(0, [], [], [], {0, 40000}) = 0 (timeout) <0.040118>
29628      0.040216 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050120>
29628      0.050209 select(0, [], [], [], {0, 60000}) = 0 (timeout) <0.060129>
29628      0.060218 select(0, [], [], [], {0, 70000}) = 0 (timeout) <0.070140>
29628      0.070230 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050124>
29628      0.050213 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050118>
29628      0.050207 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050124>
29628      0.050216 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050134>
29628      0.050224 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050117>
29628      0.050207 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050120>
29628      0.050209 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050117>
29628      0.050206 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050120>
29628      0.050211 select(0, [], [], [], {0, 50000}) = 0 (timeout) <0.050125>
--//可以发现一样有效.

$ awk '/select/ {print $nf}' /tmp/pp_172843.txt | tr -d '<>' | xargs | sed 's/ /+/g' | bc -l
7.899805
--//接近8秒.spin占用时间不多.