ORACLE數據庫異步IO介紹

異步IO概念 css

    Linux 異步 I/O (AIO)是 Linux 內核中提供的一個加強的功能。它是Linux 2.6 版本內核的一個標準特性,固然咱們在2.4 版本內核的補丁中也能夠找到它。AIO 背後的基本思想是容許進程發起不少 I/O 操做,而不用阻塞或等待任何操做完成。稍後或在接收到 I/O 操做完成的通知時,進程就能夠檢索 I/O 操做的結果。 html

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

    若是IO請求須要大量時間執行的話,異步文件IO方式能夠顯著提升效率,由於在線程等待的這段時間內,CPU將會調度其餘線程進行執行,若是沒有其餘線程須要執行的話,這段時間將會浪費掉(可能會調度操做系統的零頁線程)。若是IO請求操做很快,用異步IO方式反而還低效,還不如用同步IO方式。 數據庫

   其它關於異步IO與同步IO的細節,能夠參考Boost application performance using asynchronous I/O這篇文章,網上不少"Linux異步IO"的文章實際上是翻譯自這篇文章。若是瞭解更多關於異步IO的細節,能夠細讀這篇文章。 服務器

 

異步IO好處 oracle

 

  異步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的這個功能的。 app

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. async

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

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. First, because a process can queue multiple requests for the kernel to handle, so the kernel can optimize disk activity by recording requests or combining individual requests that are adjacent on disk into fewer and larger requests.
  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使之生效。

clip_image001

[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的。

clip_image002

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的第2、三列都不爲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

相關文章
相關標籤/搜索