[20180316]非同步IO和共享服務模式.txt

lfree發表於2018-03-16

[20180316]非同步IO和共享服務模式.txt

--//在共享伺服器模式下,不會使用非同步IO,透過例子證明.

1.環境:
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> alter system set filesystemio_options=asynch scope=spfile;
System altered.

--//重啟資料庫.

SCOTT@book> show sga
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes

SCOTT@book> show parameter disk_asynch_io
NAME                 TYPE    VALUE
-------------------- ------- ------
disk_asynch_io       boolean TRUE

SCOTT@book> show parameter filesystemio_options
NAME                 TYPE    VALUE
-------------------- ------- -------
filesystemio_options string  ASYNCH

SCOTT@book> create table t as select rownum id from dual connect by level<=2;
Table created.

SCOTT@book> ALTER TABLE t MINIMIZE RECORDS_PER_BLOCK ;
Table altered.
--//這樣可以實現每塊2條記錄.

SCOTT@book> insert into t select rownum+2 from dual connect by level <=8e4-2;
79998 rows created.

SCOTT@book> commit ;
Commit complete.

--//分析表略.

SCOTT@book> select OWNER,SEGMENT_NAME,SEGMENT_TYPE,HEADER_FILE,HEADER_BLOCK,BYTES,BLOCKS from dba_segments where owner=user and segment_name='T';
OWNER  SEGMENT_NAME         SEGMENT_TYPE       HEADER_FILE HEADER_BLOCK      BYTES     BLOCKS
------ -------------------- ------------------ ----------- ------------ ---------- ----------
SCOTT  T                    TABLE                        4          546  333447168      40704

--//佔用 333447168/1024/1024 = 318M

SCOTT@book> select object_id,data_object_id from dba_objects where owner=user and object_name='T';
OBJECT_ID DATA_OBJECT_ID
---------- --------------
     90467          90467

2.測試使用專用模式連線:
SCOTT@book> alter system flush buffer_cache;
System altered.

SCOTT@book> alter session set statistics_level=all;
Session altered.

SCOTT@book> @ &r/spid

       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
       274          5 49118                    DEDICATED 49119       21          3 alter system kill session '274,5' immediate;;

--//SERVER=DEDICATED,程式號=49119.啟動$ strace -f -p 49119  -c,然後執行:
SCOTT@book> select count(*) from t;
  COUNT(*)
----------
     80000

$ strace -f -p 49119  -c
Process 49119 attached - interrupt to quit
^CProcess 49119 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
99.62    0.028456          87       326           io_submit
  0.16    0.000045           1        86           pread
  0.13    0.000036           0       164           io_getevents
  0.09    0.000027           7         4           mmap
  0.00    0.000000           0         2           read
  0.00    0.000000           0         2           write
  0.00    0.000000           0        82           getrusage
  0.00    0.000000           0        32           times
------ ----------- ----------- --------- --------- ----------------
100.00    0.028564                   698           total

--//可以發現呼叫io_submit,io_getevents.說明啟動非同步IO.

3.測試使用共享模式連線:
$ rlsql scott/book@127.0.0.1:1521/book
..
SCOTT@127.0.0.1:1521/book> alter system flush buffer_cache;
System altered.

SCOTT@127.0.0.1:1521/book> alter session set statistics_level=all;
Session altered.

SCOTT@127.0.0.1:1521/book> @ &r/spid

       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
       261          1 49156                    SHARED    49063       20          1 alter system kill session '261,1' immediate;

$ ps -ef | grep 4906[3]
oracle   49063     1  0 15:33 ?        00:00:00 ora_s000_book

--//SERVER=SHARED,程式號=49063.查詢程式號49063對應ora_s000_book,說明使用共享服務模式.啟動 strace -f -p 49063  -c,然後執行:
SCOTT@book> select count(*) from t;
  COUNT(*)
----------
     80000

$ strace -f -p 49063  -c
Process 49063 attached - interrupt to quit
^CProcess 49063 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
99.84    0.011918          35       336           pread
  0.16    0.000019           1        27           getrusage
  0.00    0.000000           0         2           read
  0.00    0.000000           0         2           poll
  0.00    0.000000           0         2           sendto
  0.00    0.000000           0        25           times
  0.00    0.000000           0         1           restart_syscall
------ ----------- ----------- --------- --------- ----------------
100.00    0.011937                   395           total

--//使用pread,read函式.不存在呼叫io_submit,io_getevents函式.說明在共享模式下不會使用非同步IO.
--//加上上午的測試,說明在共享模式下,不會使用非同步IO以及直接路徑讀特性.
--//以後工作中遇到這類問題主要.
--//補充啟用DRCP連線的情況,好像使用很少有人使用這個特性.

4.測試drcp:

SYS@book> exec dbms_connection_pool.start_pool()
PL/SQL procedure successfully completed.

$ rlsql scott/book@127.0.0.1:1521/book:POOLED

SCOTT@127.0.0.1:1521/book:POOLED> alter session set statistics_level=all;
Session altered.

SCOTT@127.0.0.1:1521/book:POOLED> alter system flush buffer_cache;
System altered.

SCOTT@127.0.0.1:1521/book:POOLED> @ &r/spid
       SID    SERIAL# PROCESS                  SERVER    SPID       PID  P_SERIAL# C50
---------- ---------- ------------------------ --------- ------ ------- ---------- --------------------------------------------------
        94          1 49221                    POOLED    49204       31          1 alter system kill session '94,1' immediate;

--//SERVER=POOLED,程式號=49204.啟動 strace -f -p 49204  -c,然後執行:


SCOTT@127.0.0.1:1521/book:POOLED> @ &r/viewsess "physical reads direct"
NAME                                                                   STATISTIC#      VALUE        SID
---------------------------------------------------------------------- ---------- ---------- ----------
physical reads direct                                                          97          0         94
physical reads direct temporary tablespace                                    110          0         94
physical reads direct (lob)                                                   176          0         94

$ strace -f -p 49204  -c
...//等
.
SCOTT@127.0.0.1:1521/book:POOLED> select count(*) from t;
  COUNT(*)
----------
     80000

SCOTT@127.0.0.1:1521/book:POOLED> @ &r/viewsess "physical reads direct"
NAME                                                                   STATISTIC#      VALUE        SID
---------------------------------------------------------------------- ---------- ---------- ----------
physical reads direct                                                          97      40217         94
physical reads direct temporary tablespace                                    110          0         94
physical reads direct (lob)                                                   176          0         94

$ strace -f -p 49204  -c
Process 49204 attached - interrupt to quit
^CProcess 49204 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
98.17    0.019632          60       326           io_submit
  1.11    0.000221          74         3           munmap
  0.57    0.000113          28         4           write
  0.16    0.000031           2        13           mmap
  0.00    0.000000           0         4           read
  0.00    0.000000           0         1           poll
  0.00    0.000000           0         4           pread
  0.00    0.000000           0        39           getrusage
  0.00    0.000000           0        30           times
  0.00    0.000000           0       164           io_getevents
------ ----------- ----------- --------- --------- ----------------
100.00    0.019997                   588           total

--//可以發現啟動drcp連線呼叫io_submit,io_getevents,也就是會使用非同步IO以及直接路徑讀特性.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2151928/,如需轉載,請註明出處,否則將追究法律責任。

相關文章