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

[20190306]共享服务模式与SDU.txt

程序员文章站 2022-07-01 14:58:50
[20190306]共享服务模式与SDU.txt--//一些文档提到共享服务模式,服务端SDU=65535,测试验证看看.--//链接:https://blogs.sap.com/2013/02/07/oracle-sqlnet-researching-setting-session-data-un ......

[20190306]共享服务模式与sdu.txt

--//一些文档提到共享服务模式,服务端sdu=65535,测试验证看看.
--//链接:https://blogs.sap.com/2013/02/07/oracle-sqlnet-researching-setting-session-data-unit-sdu-size-and-how-it-can-go-wrong/
official oracle 11g r2 documentation

under typical database configuration, oracle net encapsulates data into buffers the size of the session data unit (sdu)
before sending the data across the network. oracle net sends each buffer when it is filled, flushed, or when an
application tries to read data. adjusting the size of the sdu buffers relative to the amount of data provided to oracle
net to send at any one time can improve performance, network utilization, and memory consumption. when large amounts of
data are being transmitted, increasing the sdu size can improve performance and network throughput.

the amount of data provided to oracle net to send at any one time is referred to as the message size. oracle net assumes
by default that the message size will normally vary between 0 and 8192 bytes, and infrequently, be larger than 8192
bytes. if this assumption is true, then most of the time, the data is sent using one sdu buffer.

the sdu size can range from 512 bytes to 65535 bytes. the default sdu for the client and a dedicated server is 8192
bytes. the default sdu for a shared server is 65535 bytes.

the actual sdu size used is negotiated between the client and the server at connect time and is the smaller of the
client and server values. configuring an sdu size different from the default requires configuring the sdu on both the
client and server computers, unless you are using shared servers. for shared servers, only the client value must be
changed because the shared server defaults to the maximum value.
--//注意理解最后一段: for shared servers, only the client value must be changed because the shared server defaults to
--//the maximum value.也就是在共享服务器模式下服务端sdu设置65535,以client端要设置为准,我开始理解错误.
--//实际上服务端应该也是可以改变的,修改dispatchers参数.

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

--//在client建立sql脚本e2.txt:
r:\>cat e1.txt
select sysdate,p2,time_since_last_wait_micro from v$session_wait_history where sid=&&1 and event='sql*net more data from client';

r:\> cat e2.txt
select /*
0014567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
0024567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
...snip...
5994567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
6004567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
*/ sysdate
from dual;

r:\>ls -l  e2.txt
-rw-rw-rw-   1 user     group       61235 mar  6 16:46 e2.txt

--//说明服务端监听配置以及sqlnet.ora采用缺省配置sdu.
--//修改client端sqlnet.ora加入default_sdu_size=65535
r:\>grep -i sdu e:\app\oracle\product\12.2.0\dbhome_1\network\admin\sqlnet.ora
default_sdu_size=65535

2.测试1:
--//首先测试专用模式:
r:\>sqlplus scott/book@192.168.100.78:1521/book:dedicated
scott@192.168.100.78:1521/book:dedicated> @ spid
 sid    serial# process                  server    spid  pid  p_serial# c50
---- ---------- ------------------------ --------- ----- --- ---------- --------------------------------------------
  67         73 12224:12764              dedicated 13418  29         30 alter system kill session '67,73' immediate;

--//sid=67,使用专用连接.

scott@192.168.100.78:1521/book:dedicated> @ e1.txt  67
no rows selected

scott@192.168.100.78:1521/book:dedicated> @e2.txt
sysdate
-------------------
2019-03-06 16:51:42

scott@192.168.100.78:1521/book:dedicated> @ e1.txt  67
sysdate                     p2 time_since_last_wait_micro
------------------- ---------- --------------------------
2019-03-06 16:51:48         64                          5
2019-03-06 16:51:48        229                          5
2019-03-06 16:51:48        138                          7

--//你可以发现会话出现sql*net more data from client等待事件,而且出现3次(注v$session_wait_history视图记录遇到的最后10个等
--//待事件),这是因为sql语句超长,而我客户端设置default_sdu_size=65535,但是服务端sdu缺省是8192,这样协调选择最小的sdu值.

3.测试2:
--//测试共享模式:
r:\>sqlplus scott/book@192.168.100.78:1521/book:shared
scott@192.168.100.78:1521/book:shared> @ spid
 sid    serial# process                  server    spid  pid  p_serial# c50
---- ---------- ------------------------ --------- ----- --- ---------- ---------------------------------------------
 261         31 12988:8108               shared    59542  20          1 alter system kill session '261,31' immediate;
--//sid=261

scott@192.168.100.78:1521/book:shared> @ e1.txt 261
no rows selected

scott@192.168.100.78:1521/book:shared> @ e2.txt
sysdate
-------------------
2019-03-06 16:55:46

scott@192.168.100.78:1521/book:shared> @ e1.txt 261
no rows selected
--//可以发现在采用共享服务连接模式,执行脚本大小61k,并没有出现sql*net more data from client等待事件.说明这种情况下sdu确实
--//设置很大.

r:\>ls -l e2.txt
-rw-rw-rw-   1 user     group       67355 mar  6 16:57 e2.txt
--//增加e2.txt 大小大于65535字节,重复测试看看:

scott@192.168.100.78:1521/book:shared> @ e1.txt 261
no rows selected

scott@192.168.100.78:1521/book:shared> @ e2.txt
sysdate
-------------------
2019-03-06 16:58:13

scott@192.168.100.78:1521/book:shared> @ e1.txt 261
sysdate                     p2 time_since_last_wait_micro
------------------- ---------- --------------------------
2019-03-06 16:58:15         31                        126

--//当脚本大小变大时,出现'sql*net more data from client'等待事件.

4.疑问:
--//自己觉得好奇的是oracle为什么这样设置,这样设置有什么好处.如果设置很大,使用共享模式消耗network buffer不是很大吗?
--//共享池不是要设置很大吗?
--//参考链接:http://blog.itpub.net/267265/viewspace-2214856/.

--//重新测试:
--//修改服务端的sqlnet.ora,default_sdu_size=65535
$ grep -i sdu /u01/app/oracle/product/11.2.0.4/dbhome_1/network/admin/sqlnet.ora
default_sdu_size=65535
#default_sdu_size=32767

$ cat /home/oracle/xxx430/testh/b.sh
#!/bin/bash
for i in $(seq 100)
do
nohup   sqlplus -s scott/book@192.168.100.78:1521/book:shared <<eof > /dev/null 2>&1 &
select sysdate from dual ;
host sleep 30
quit;
eof
done

sys@book> select name,pool,bytes from v$sgastat where name like '%network%';
name                 pool              bytes
-------------------- ------------ ----------
network buffer       shared pool       73808

$ . /home/oracle/xxx430/testh/b.sh

sys@book> select name,pool,bytes from v$sgastat where name like '%network%';
name                 pool              bytes
-------------------- ------------ ----------
network buffer       shared pool    33292408
--//33292408/1024/1024 = 31.75m

sys@book> select (33292408-73808)/100 from dual;
(33292408-73808)/100
--------------------
              332186

--//332186/1024= 324.4k.每个连接消耗324k. 332186/65535 = 5.06883344777599755855,5个sdu???
--//另外我在10g下做了测试10g下好像sdu最大32767.

--//好奇心测试看看sdu不同的情况下network buffer的消耗,方法如下:
1.修改sdu值
2.查询select name,pool,bytes from v$sgastat where name like '%network%';,记下bytes数量
3.执行$ seq 100 | xargs -i{} -p 100 bash -c 'sqlplus -s scott/book@192.168.100.78:1521/book:shared <<< "host sleep 20" '
4.查询select name,pool,bytes from v$sgastat where name like '%network%';,记下bytes数量
5.重复测试

--//画一个表格:
sdu    开始network buffer   结束network buffer  差值                          差值/100/sdu
-------------------------------------------------------------------------------------------------------------------------
10000  3344376               8399608            8399608-3344376 = 5055232     5055232/100/10000 = 5.05523200000000000000
20000  3344376               13399584     13399584-3344376 = 10055208    10055208/100/20000 = 5.02760400000000000000
30000  3344376               18399728          18399728-3344376 = 15055352    15055352/100/30000 = 5.01845066666666666666
40000  3344376               23399600          23399600-3344376 = 20055224    20055224/100/40000 = 5.01380600000000000000
50000  3344376               28399784          28399784-3344376 = 25055408    25055408/100/50000 = 5.01108160000000000000
60000  3344376               33400168          33400168-3344376 = 30055792    30055792 /100/60000 = 5.00929866666666666666
65535  3344376               36167632          36167632-3344376 = 32823256    32823256/100/65535 = 5.00850782024872205691
70000  3344376               36167760          36167760-3344376 = 32823384    32823384/100/5 = 65646.76800000000000000000
---------------------------------------------------------------------------------------------------------------------------
--//注:最后sud设置70000,实际上协调2者sdu=65535.
--//按照http://www.askmaclean.com/archives/%e5%85%b1%e4%ba%ab%e6%b1%a0%e4%b8%ad%e7%9a%84network-buffer.html的理解:
为什么共享服务器模式下会用到共享池中的network buffer,而独享服务器模式下没有呢?因为在独享服务器模式下每个会话所分配的三
个sdu是从pga中获取的;当使用共享服务器模式时会话与服务进程形成一对多的映射关系,这三个sdu 的network buffer同uga一样转移
到了sga中。

--//可不可这样理解实际上不是3个sdu,而是5个呢?不知道我的理解是否正确.不过我在10g测试情况不同:

sys@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

sdu    开始network buffer   结束network buffer  差值                          差值/100/sdu
-------------------------------------------------------------------------------------------------------------------------
10000  139824               12025456            12025456-139824 = 11885632    11885632/100/10000 = 11.88563200000000000000
20000  139824               14025456            14025456-139824 = 13885632    13885632/100/20000 = 6.94281600000000000000
30000  139824               16025424            16025424-139824 = 15885600    15885600/100/30000 = 5.29520000000000000000
32767  139824               16579040            16579040-139824 = 16439216    16439216/100/32767 = 5.01700369273964659566
40000  139824               16579024            16579024-139824 = 16439200    16439200/32767/100 = 5.01699880977813043610
-------------------------------------------------------------------------------------------------------------------------

--//可以看出10g sdu最大是32767.
--//后面的差值/100/sdu很大时才接近5个sdu.

5.最后注意收尾.
--//取消修改设置为缺省值.略.