程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> ORACLE數據庫異步IO介紹,oracle異步io

ORACLE數據庫異步IO介紹,oracle異步io

編輯:Oracle教程

ORACLE數據庫異步IO介紹,oracle異步io


異步IO概念

    Linux 異步 I/O (AIO)是 Linux 內核中提供的一個增強的功能。它是Linux 2.6 版本內核的一個標准特性,當然我們在2.4 版本內核的補丁中也可以找到它。AIO 背後的基本思想是允許進程發起很多 I/O 操作,而不用阻塞或等待任何操作完成。稍後或在接收到 I/O 操作完成的通知時,進程就可以檢索 I/O 操作的結果。

    Linux IO模型(I/O models)分同步IO模型(synchronous models)和異步IO模型(asynchronous models)。 在同步IO中,線程啟動一個IO操作然後就立即進入等待狀態,直到IO操作完成後才醒來繼續執行。而異步IO方式中,線程發送一個IO請求到內核,然後繼續處理其他的事情,內核完成IO請求後,將會通知線程IO操作完成了

    如果IO請求需要大量時間執行的話,異步文件IO方式可以顯著提高效率,因為在線程等待的這段時間內,CPU將會調度其他線程進行執行,如果沒有其他線程需要執行的話,這段時間將會浪費掉(可能會調度操作系統的零頁線程)。如果IO請求操作很快,用異步IO方式反而還低效,還不如用同步IO方式。

   其它關於異步IO與同步IO的細節,可以參考Boost application performance using asynchronous I/O這篇文章,網上很多"Linux異步IO"的文章其實是翻譯自這篇文章。如果了解更多關於異步IO的細節,可以細讀這篇文章。

 

異步IO好處

 

  異步I/O的優點:異步I/O是和同步I/O相比較來說的,如果是同步I/O,當一個I/O操作執行時,應用程序必須等待,直到此I/O執行完。相反,異步I/O操作在後台運行,I/O操作和應用程序可以同時運行,提高了系統性能;使用異步I/O會提高I/O流量,如果應用是對裸設備進行操作,這種優勢更加明顯, 因此像數據庫,文件服務器等應用往往會利用異步I/O,使得多個I/O操作同時執行. 而且從官方文檔來看,ORACLE也是推薦ORACLE數據庫啟用異步IO的這個功能的。

With synchronous I/O, when an I/O request is submitted to the operating system, the writing process blocks until the write is confirmed as complete. It can then continue processing. With asynchronous I/O, processing continues while the I/O request is submitted and processed. Use asynchronous I/O when possible to avoid bottlenecks.

Some platforms support asynchronous I/O by default, others need special configuration, and some only support asynchronous I/O for certain underlying file system types.

Q: 2. What are the benefits of Asynchronous I/O?

A: The implementation of Asynchronous I/O on Red Hat Advanced Server allows Oracle processes to issue multiple I/O requests to disk with a single system call, rather than a large number of single I/O requests. This improves performance in two ways:

  1. Secondary, because the system does not put the process in sleep state while the hardware processes the request. So, the process is able to perform other tasks until the I/O complete.

This involves making use of I/O capabilities such as:

  • Asynchronous I/O: Asynchronous I/O does not reduce traffic but allows processes to do other things while waiting for IO to complete.
  • Direct I/O (bypassing the Operating System's File Caches) : Direct IO does not reduce traffic but may use a shorter code path / fewer CPU cycles to perform the IO.

 

 

啟用異步IO

   ORACLE數據庫是從ORACLE 9i Release 2開始支持異步IO特性的。之前的版本是不支持異步IO特征的。另外在ORACLE 9i R2和 ORACLE 10g R1中默認是禁用異步特性的,直到ORACLE 10g R2才默認啟用異步IO特性。

Q: 4. Can I use Asynchronous I/O with Oracle 8i or Oracle 9i release 1?

A: No. Asynchronous I/O feature is only available with Oracle RDBMS 9i release 2 (Oracle9iR2).

Q: 5. Is Asynchronous I/O active with Oracle RDBMS by default?

A: No. By default, Oracle9iR2 and Oracle10gR1 are shipped with asynchronous I/O support disabled.In 10gR2 asyncIO is enabled by default.

那麼如何啟用ORACLE數據庫的異步IO特性呢? 我們可以按照下面步驟操作:

 

1:首先要確認ORACLE數據庫所在的系統平台(操作系統)是否支持異步IO

   目前流行的Linux/Unix平台基本上都支持異步IO,但是一些老舊的版本就不一定了。可以搜索一下相關文檔了解清楚。

 

2: 檢查是否安裝libaio、libaio-devel相關包(似乎libaio-devel包不是必須的,測試環境沒有libaio-devel似乎也OK,當然最好也一起安裝)

[root@DB-Server ~]# rpm -qa | grep aio 
libaio-0.3.106-5
libaio-0.3.106-5
 
[root@DB-Server Server]# rpm -ivh libaio-devel-0.3.106-5.i386.rpm
warning: libaio-devel-0.3.106-5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...                ########################################### [100%]
   1:libaio-devel           ########################################### [100%]
[root@DB-Server Server]# rpm -ivh  libaio-devel-0.3.106-5.x86_64.rpm
warning: libaio-devel-0.3.106-5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159
Preparing...                ########################################### [100%]
   1:libaio-devel           ########################################### [100%]
 
[root@DB-Server Server]# rpm -qa | grep libaio
libaio-0.3.106-5
libaio-devel-0.3.106-5
libaio-devel-0.3.106-5
libaio-0.3.106-5

 

3:檢查系統是否支持異步I/O

根據文檔[Note 370579.1] ,可以通過查看slabinfo統計信息查看操作系統中AIO是否運行,slab是Linux的內存分配器,AIO相關的內存結構已經分配,kiocb值的第二列和第三列非0即是已使用

[root@DB-Server ~]# cat /proc/slabinfo | grep kio 
kioctx                62    110    384   10    1 : tunables   54   27    8 : slabdata     11     11      0
kiocb                  0      0    256   15    1 : tunables  120   60    8 : slabdata      0      0      0

kiocb值的第二列和第三列非0表示系統已經啟用異步IO。如上所示,表示異步I/O沒有在使用。

The kioctx and kiocb are Async I/O data structures that are defined in aio.h. If it shows a non zero value that means async io is enabled. source code loaded /usr/src/linux-<version>/include/linux/aio.h

 

4:修改、優化系統內核參數

Linux從2.6 kernel開始,已經取消了對IO size的限制,Oracle建議將aio-max-nr的值設置為1048576或更高。

[root@DB-Server ~]# cat /proc/sys/fs/aio-max-nr

65536

命令echo 1048576 > /proc/sys/fs/aio-max-nr修改參數,只對當前環境有效,如果系統重啟過後,則會使用默認值,所以最好修改參數文件/etc/sysctl.conf。編輯/etc/sysctl.conf 添加或修改參數fs.aio-max-nr = 1048576,保存後。運行sysctl -p使之生效。

[root@DB-Serveruat ~]# cat /proc/sys/fs/aio-max-nr

1048576

注意aio-max-size參數從RHEL4開始已經不存在了,詳情見文檔Kernel Parameter "aio-max-size" does not exist in RHEL4 / EL4 / RHEL5 /EL5 (文檔 ID 549075.1)。

 

5:檢查ORACLE軟件是否支持開啟AIO。

如下所示有輸出值,表示ORACLE軟件支持開啟AIO,其實從ORACLE 9i R2開始,ORACLE就已經支持開啟異步IO(AIO)了。不過10GR1以前版本需要手動開啟AIO,相對而言要麻煩一些。

[oracle@DB-Server ~]$ /usr/bin/ldd $ORACLE_HOME/bin/oracle | grep libaio
        libaio.so.1 => /usr/lib64/libaio.so.1 (0x00007f5a247f4000)
[oracle@DB-Server ~]$  /usr/bin/nm $ORACLE_HOME/bin/oracle | grep io_getevent 
                 w io_getevents@@LIBAIO_0.4

 

6:數據庫級別啟用異步I/O

將參數disk_asynch_io設置為true,其實ORACLE 10g R2中參數disk_asynch_io默認是為true的。

SQL> alter system set filesystemio_options = setall scope=spfile; 
 
System altered.
 
SQL> alter system set disk_asynch_io = true scope=spfile; 
 
System altered.

關於參數filesystemio_options有四個值: asynch、directio, setall,none. 一般建議設置為setall比較合適。

You can use the FILESYSTEMIO_OPTIONS initialization parameter to enable or disable asynchronous I/O or direct I/O on file system files. This parameter is platform-specific and has a default value that is best for a particular platform. It can be dynamically changed to update the default setting.

FILESYTEMIO_OPTIONS can be set to one of the following values:

 

   · ASYNCH: enable asynchronous I/O on file system files, which has no timing requirement for transmission.

            在文件系統文件上啟用異步I/O,在數據傳送上沒有計時要求。

· DIRECTIO: enable direct I/O on file system files, which bypasses the buffer cache.

            在文件系統文件上啟用直接I/O,繞過buffer cache。

· SETALL: enable both asynchronous and direct I/O on file system files.

            在文件系統文件上啟用異步和直接I/O。

· NONE: disable both asynchronous and direct I/O on file system files.

           在文件系統文件上禁用異步和直接I/O。

 

設置完成後重啟數據庫,驗證異步IO特性是否啟用。如下所示, kiocb的第二、三列都不為0,表示ORACLE的異步IO特性已經啟用。

[oracle@DB-Server ~]$ cat /proc/slabinfo | grep kio 
kioctx                60     80    384   10    1 : tunables   54   27    8 : slabdata      8      8      0
kiocb                  6     30    256   15    1 : tunables  120   60    8 : slabdata      2      2      0
[oracle@DB-Server ~]$ 
 

參考資料:

http://www.ibm.com/developerworks/linux/library/l-async/index.html

https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=73665184034240&parent=DOCUMENT&sourceId=223117.1&id=432854.1&_afrWindowMode=0&_adf.ctrl-state=11m9r3dm4l_242

https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=73689176803264&parent=DOCUMENT&sourceId=471846.1&id=225751.1&_afrWindowMode=0&_adf.ctrl-state=11m9r3dm4l_291

http://blog.sina.com.cn/s/blog_465a4a1e0100oizv.html

http://semiter.blog.51cto.com/1234477/1243325

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved