自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ORACLE數(shù)據(jù)庫(kù)異步IO介紹

數(shù)據(jù)庫(kù) Oracle
Linux 異步 I/O (AIO)是 Linux 內(nèi)核中提供的一個(gè)增強(qiáng)的功能。它是Linux 2.6 版本內(nèi)核的一個(gè)標(biāo)準(zhǔn)特性,當(dāng)然我們?cè)?.4 版本內(nèi)核的補(bǔ)丁中也可以找到它。AIO 背后的基本思想是允許進(jìn)程發(fā)起很多 I/O 操作,而不用阻塞或等待任何操作完成。稍后或在接收到 I/O 操作完成的通知時(shí),進(jìn)程就可以檢索 I/O 操作的結(jié)果。

  異步IO概念

  Linux 異步 I/O (AIO)是 Linux 內(nèi)核中提供的一個(gè)增強(qiáng)的功能。它是Linux 2.6 版本內(nèi)核的一個(gè)標(biāo)準(zhǔn)特性,當(dāng)然我們?cè)?.4 版本內(nèi)核的補(bǔ)丁中也可以找到它。AIO 背后的基本思想是允許進(jìn)程發(fā)起很多 I/O 操作,而不用阻塞或等待任何操作完成。稍后或在接收到 I/O 操作完成的通知時(shí),進(jìn)程就可以檢索 I/O 操作的結(jié)果。

  Linux IO模型(I/O models)分同步IO模型(synchronous models)和異步IO模型(asynchronous models)。 在同步IO中,線程啟動(dòng)一個(gè)IO操作然后就立即進(jìn)入等待狀態(tài),直到IO操作完成后才醒來(lái)繼續(xù)執(zhí)行。而異步IO方式中,線程發(fā)送一個(gè)IO請(qǐng)求到內(nèi)核,然后繼續(xù)處理其他的事情,內(nèi)核完成IO請(qǐng)求后,將會(huì)通知線程IO操作完成了

  如果IO請(qǐng)求需要大量時(shí)間執(zhí)行的話,異步文件IO方式可以顯著提高效率,因?yàn)樵诰€程等待的這段時(shí)間內(nèi),CPU將會(huì)調(diào)度其他線程進(jìn)行執(zhí)行,如果沒(méi)有其他線程需要執(zhí)行的話,這段時(shí)間將會(huì)浪費(fèi)掉(可能會(huì)調(diào)度操作系統(tǒng)的零頁(yè)線程)。如果IO請(qǐng)求操作很快,用異步IO方式反而還低效,還不如用同步IO方式。

  其它關(guān)于異步IO與同步IO的細(xì)節(jié),可以參考Boost application performance using asynchronous I/O這篇文章,網(wǎng)上很多"Linux異步IO"的文章其實(shí)是翻譯自這篇文章。如果了解更多關(guān)于異步IO的細(xì)節(jié),可以細(xì)讀這篇文章。

  異步IO好處

  異步I/O的優(yōu)點(diǎn):異步I/O是和同步I/O相比較來(lái)說(shuō)的,如果是同步I/O,當(dāng)一個(gè)I/O操作執(zhí)行時(shí),應(yīng)用程序必須等待,直到此I/O執(zhí)行完。相反,異步I/O操作在后臺(tái)運(yùn)行,I/O操作和應(yīng)用程序可以同時(shí)運(yùn)行,提高了系統(tǒng)性能;使用異步I/O會(huì)提高I/O流量,如果應(yīng)用是對(duì)裸設(shè)備進(jìn)行操作,這種優(yōu)勢(shì)更加明顯, 因此像數(shù)據(jù)庫(kù),文件服務(wù)器等應(yīng)用往往會(huì)利用異步I/O,使得多個(gè)I/O操作同時(shí)執(zhí)行. 而且從官方文檔來(lái)看,ORACLE也是推薦ORACLE數(shù)據(jù)庫(kù)啟用異步IO的這個(gè)功能的。

  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:

  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.

  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數(shù)據(jù)庫(kù)是從ORACLE 9i Release 2開(kāi)始支持異步IO特性的。之前的版本是不支持異步IO特征的。另外在ORACLE 9i R2和 ORACLE 10g R1中默認(rèn)是禁用異步特性的,直到ORACLE 10g R2才默認(rèn)啟用異步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數(shù)據(jù)庫(kù)的異步IO特性呢? 我們可以按照下面步驟操作:

  1:首先要確認(rèn)ORACLE數(shù)據(jù)庫(kù)所在的系統(tǒng)平臺(tái)(操作系統(tǒng))是否支持異步IO

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

  2: 檢查是否安裝libaio、libaio-devel相關(guān)包(似乎libaio-devel包不是必須的,測(cè)試環(huán)境沒(méi)有l(wèi)ibaio-devel似乎也OK,當(dāng)然最好也一起安裝)

 

  1. [root@DB-Server ~]# rpm -qa | grep aio  
  2. libaio-0.3.106-5 
  3. libaio-0.3.106-5 
  4.   
  5. [root@DB-Server Server]# rpm -ivh libaio-devel-0.3.106-5.i386.rpm 
  6. warning: libaio-devel-0.3.106-5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159 
  7. Preparing...                ########################################### [100%] 
  8.    1:libaio-devel           ########################################### [100%] 
  9. [root@DB-Server Server]# rpm -ivh  libaio-devel-0.3.106-5.x86_64.rpm 
  10. warning: libaio-devel-0.3.106-5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1e5e0159 
  11. Preparing...                ########################################### [100%] 
  12.    1:libaio-devel           ########################################### [100%] 
  13.   
  14. [root@DB-Server Server]# rpm -qa | grep libaio 
  15. libaio-0.3.106-5 
  16. libaio-devel-0.3.106-5 
  17. libaio-devel-0.3.106-5 
  18. libaio-0.3.106-5 

 

  3:檢查系統(tǒng)是否支持異步I/O

  根據(jù)文檔[Note 370579.1] ,可以通過(guò)查看slabinfo統(tǒng)計(jì)信息查看操作系統(tǒng)中AIO是否運(yùn)行,slab是Linux的內(nèi)存分配器,AIO相關(guān)的內(nèi)存結(jié)構(gòu)已經(jīng)分配,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表示系統(tǒng)已經(jīng)啟用異步IO。如上所示,表示異步I/O沒(méi)有在使用。

  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-/include/linux/aio.h

  4:修改、優(yōu)化系統(tǒng)內(nèi)核參數(shù)

  Linux從2.6 kernel開(kāi)始,已經(jīng)取消了對(duì)IO size的限制,Oracle建議將aio-max-nr的值設(shè)置為1048576或更高。

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

  65536

  命令echo 1048576 > /proc/sys/fs/aio-max-nr修改參數(shù),只對(duì)當(dāng)前環(huán)境有效,如果系統(tǒng)重啟過(guò)后,則會(huì)使用默認(rèn)值,所以最好修改參數(shù)文件/etc/sysctl.conf。編輯/etc/sysctl.conf 添加或修改參數(shù)fs.aio-max-nr = 1048576,保存后。運(yùn)行sysctl -p使之生效。

 

 

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

  1048576

  注意aio-max-size參數(shù)從RHEL4開(kāi)始已經(jīng)不存在了,詳情見(jiàn)文檔Kernel Parameter "aio-max-size" does not exist in RHEL4 / EL4 / RHEL5 /EL5 (文檔 ID 549075.1)。

  5:檢查ORACLE軟件是否支持開(kāi)啟AIO。

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

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

  6:數(shù)據(jù)庫(kù)級(jí)別啟用異步I/O

  將參數(shù)disk_asynch_io設(shè)置為true,其實(shí)ORACLE 10g R2中參數(shù)disk_asynch_io默認(rèn)是為true的。

 

 

  1. SQL> alter system set filesystemio_options = setall scope=spfile;  
  2.   
  3. System altered. 
  4.   
  5. SQL> alter system set disk_asynch_io = true scope=spfile;  
  6.   
  7. System altered.

  關(guān)于參數(shù)filesystemio_options有四個(gè)值: asynch、directio, setall,none. 一般建議設(shè)置為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.

  在文件系統(tǒng)文件上啟用異步I/O,在數(shù)據(jù)傳送上沒(méi)有計(jì)時(shí)要求。

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

  在文件系統(tǒng)文件上啟用直接I/O,繞過(guò)buffer cache。

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

  在文件系統(tǒng)文件上啟用異步和直接I/O。

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

  在文件系統(tǒng)文件上禁用異步和直接I/O。

  設(shè)置完成后重啟數(shù)據(jù)庫(kù),驗(yàn)證異步IO特性是否啟用。如下所示, kiocb的第二、三列都不為0,表示ORACLE的異步IO特性已經(jīng)啟用。

  [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

  本文轉(zhuǎn)自:http://www.cnblogs.com/kerrycode/

  作者:瀟湘隱者

  本文版權(quán)歸作者所有,歡迎轉(zhuǎn)載,但未經(jīng)作者同意必須保留此段聲明,且在文章頁(yè)面明顯位置給出原文連接.

【責(zé)任編輯:honglu TEL:(010)68476606】
責(zé)任編輯:honglu 來(lái)源: 博客園
相關(guān)推薦

2015-10-28 17:39:04

ORACLE AIO異步IO

2011-05-17 13:43:23

Oracle數(shù)據(jù)庫(kù)

2009-08-24 18:09:13

C#調(diào)用Oracle數(shù)

2010-04-15 13:01:25

Oracel數(shù)據(jù)庫(kù)

2010-03-18 09:28:14

Oracle數(shù)據(jù)庫(kù)遷移

2010-04-02 12:23:30

Oracle數(shù)據(jù)庫(kù)

2010-05-07 17:39:02

Oracle數(shù)據(jù)庫(kù)性能

2010-04-20 11:41:55

Oracle數(shù)據(jù)庫(kù)

2010-04-23 14:32:01

Oracle數(shù)據(jù)庫(kù)

2011-03-22 14:49:35

Oracle數(shù)據(jù)庫(kù)重定義表

2010-04-23 16:05:50

Oracle數(shù)據(jù)庫(kù)

2011-07-27 11:08:49

Oracle數(shù)據(jù)庫(kù)EM Console重

2011-05-25 10:56:19

Oracle數(shù)據(jù)庫(kù)Unix環(huán)境優(yōu)化

2011-09-02 10:37:15

Oraclesqlload用法

2010-04-19 12:16:53

Oracle數(shù)據(jù)庫(kù)

2010-04-07 09:31:02

Oracle數(shù)據(jù)庫(kù)

2011-08-11 16:08:55

Oracle數(shù)據(jù)庫(kù)ASHAWR

2010-04-15 15:42:11

Oracle數(shù)據(jù)庫(kù)

2011-08-05 13:17:34

Oracle數(shù)據(jù)庫(kù)閃回個(gè)性

2011-09-01 09:30:27

Oracle數(shù)據(jù)庫(kù)控制語(yǔ)句
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)