在測試Oracle的時候,很想測試下使用非同步IO的效能。但是非同步IO是需要專門配置的,否則的話,容易遇到很著名的“ORA-01578: ORACLE data block corrupted (file # 202, block # 257)”的問題。
那麼什麼是非同步IO呢,非同步IO有什麼好處?
一般說來,非同步I/O是和同步I/O相比較來說的,如果是同步I/O,當一個I/O操作執行時,應用程式必須等待,直到此I/O執行完. 相反,非同步I/O操作在後台運行,I/O操作和應用程式可以同時運行,提高了系統效能; 使用非同步I/O會提高I/O流量,如果應用是對裸裝置進行操作,這種優勢更加明顯, 因此象資料庫,檔案伺服器等應用往往會利用非同步I/O,使得多個I/O操作同時執行.
Oracle在預設情況是不使用非同步IO的。可查看參數filesystemio_options(預設值為none),有四種選項
■ ASYNCH: enable asynchronous I/O on file system files, which has no timing requirement for transmission.
■ DIRECTIO: enable direct I/O on file system files, which bypasses the buffer cache.
■ SETALL: enable both asynchronous and direct I/O on file system files.
■ NONE: disable both asynchronous and direct I/O on file system files.
Oracle : 11.2.0.0.0
Linux:debian 2.6.18-6-amd64
具體步驟如下:
1、首先用root使用者安裝以下必要的包
# aptitude search libaio
i libaio-dev - Linux kernel AIO access library - development files
i libaio1 - Linux kernel AIO access library - shared library
# aptitude install libaio1 libaio-dev
2、在系統級支援非同步I/O
Oracle建議將aio-max-nr的值設定為1048576或更高。
# echo > /proc/sys/fs/aio-max-nr 1048576
3、在資料庫級啟用非同步I/O
SQL>alter system set disk_asynch_io=TRUE scope=spfile;
SQL>alter system set filesystemio_options=setall scope=spfile;
SQL>shutdown immediate
$ cd $ORACLE_HOME/rdbms/lib
$ ln -s /usr/lib/libaio.so.1 skgaio.o
$ make PL_ORALIBS=-laio -f ins_rdbms.mk async_on
SQL>startup
4、檢查非同步I/O是否在使用
用以下命令即可檢查非同步IO是否在使用,kiocb的值不為0即是已使用。與kernel 2.4.x不同,沒有顯示kiobuf,因為從kernel 2.5.43開始,kiobuf已經從核心中被移除。
$ cat /proc/slabinfo | grep kio
kioctx 64 110 384 10 1 : tunables 54 27 8 : slabdata 11 11 0
kiocb 13 315 256 15 1 : tunables 120 60 8 : slabdata 21 21 44