在Oracle中开启AIO异步IO后可以一定程度上提升数据库IO性能,但同时也引入了丢失commit数据的风险。具体可以参见小荷同学的文章,但是这里存在一个疑问就是redo重做记录是同步写出还是在启用AIO后同样使用异步IO的API,我们可以通过跟踪lgwr后台进程的system call系统调用来说明该问题:

SQL> select * from v$version;BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - ProductionSQL> show parameter disk_asynch_ioNAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
disk_asynch_io                       boolean     TRUESQL> show parameter filesystemNAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
filesystemio_options                 string      SETALL[oracle@rh2 ~]$ ps -ef|grep dbw0_G10R2|grep -v grep
oracle   29168     1  0 19:02 ?        00:00:01 ora_dbw0_G10R2[oracle@rh2 ~]$ strace -p 29168.............................
io_submit(140140183375872, 34, {{0x7f74ee284e10, 0, 1, 0, 16},
{0x7f74ee290920, 0, 1, 0, 16}, {0x7f74ee286970, 0, 1, 0, 16}, {0x7f74ee290db0, 0, 1, 0, 16}  = 34io_getevents(140140183375872, 1, 1024, {{0x7f74ee284e10, 0x7f74ee284e10, 8192, 0},
0x7f74ee289710, 8192, 0}}, {600, 0}) = 12times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
times(NULL)                             = 480509951
getrusage(RUSAGE_SELF, {ru_utime={0, 417936}, ru_stime={0, 823874}, ...}) = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 417936}, ru_stime={0, 823874}, ...}) = 0
io_getevents(140140183375872, 1, 1024, {{0x7f74ee28c4b0, 0x7f74ee28c4b0, 8192, 0},
{0x7f74ee287290, 0x7f74ee287290, 8192, 0}, {0x7f74ee283988, 0x7f74ee283988, 8192, 0},
{0x7f74ee27fbf0, 0x7f74ee27fbf0, 8192, 0}, {0x7f74ee28a030, 0x7f74ee28a030, 8192, 0}, {0x7f74ee28fdb8, = 22/* 此处dbwr使用io_submit函数将I/O请求入列,io_submit是典型的asynchronous I/O system calls,可见Oracle针对数据文件写出已在使用异步IO */[oracle@rh2 ~]$ ps -ef|grep lgwr_G10R2|grep -v grep
oracle   29170     1  0 19:02 ?        00:00:01 ora_lgwr_G10R2[oracle@rh2 ~]$ strace -p 29170
.............................
io_submit(139932588023808, 2, {{0x7f4497f423c8, 0, 1, 0, 20}, {0x7f4497f42590, 0, 1, 0, 21}}) = 2io_getevents(139932588023808, 1, 1024, {{0x7f4497f423c8, 0x7f4497f423c8, 3584, 0}}, {600, 0}) = 1
times(NULL)                             = 480533371
io_getevents(139932588023808, 1, 1023, {{0x7f4497f42590, 0x7f4497f42590, 3584, 0}}, {600, 0}) = 1

以上io_submit system call说明当数据库启用AIO后lgwr同样使用异步IO写出重做记录到online logfile,换而言之当存储crash时的确可能出现redo记录丢失而造成的记录丢失情况。 实际控制lgwr是否使用异步IO的是一个隐藏参数_lgwr_async_io,该参数一般默认为false:

SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ2   FROM SYS.x$ksppi x, SYS.x$ksppcv y3   WHERE x.inst_id = USERENV ('Instance')4   AND y.inst_id = USERENV ('Instance')5   AND x.indx = y.indx6  AND x.ksppinm='_lgwr_async_io';NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
DESCRIB
--------------------------------------------------------------------------------
_lgwr_async_io
FALSE
LGWR Asynchronous IO enabling boolean flag

你可能要这样问:"既然该_lgwr_async_io参数默认为false,那么lgwr就应当使用同步IO而非async,这岂不矛盾?" 是的,理论上来说默认_lgwr_async_io参数为false,lgwr应当使用sync。但是在版本10.1.0.2到11.1.0.6存在一个“Bug:8357698 LGWR USES ASYNC IO INSPITE OF SETTING _LGWR_ASYNC_IO=FALSE”:

Abstract: LGWR USES ASYNC IO INSPITE OF SETTING _LGWR_ASYNC_IO=FALSE PROBLEM: -------- + Lgwr uses asynch IO irrespective of the setting _lgwr_async_io=false and consumes high CPU performing IO poll operations. + short stack and truss output show that the lgwr is waiting for asynch IO completion notification. This particular problem was dormant for a long time and highly affects the database performance. DIAGNOSTIC ANALYSIS: -------------------- LGWR Shortstack ~~~~~~~~~~~~~~~ aiowait()+540<-skgfospo()+216<-skgfrwat()+80<-ksfdwtio()+476<-ksfdwat1()+84<-k sfdrwat 0()+520<-kcrfw_post()+500<-kcrfw_redo_write()+2964<-ksbabs()+764<-ksbrdp() aiowait()+540<-skgfospo()+216<-skgfrwat()+80<-ksfdwtio()+476<-ksfdwat1()+84<-k sfdrwat 0()+520<-kcrfw_post()+500<-kcrfw_redo_write()+2964<-ksbabs()+764<-ksbrdp() aiowait()+540<-skgfospo()+216<-skgfrwat()+80<-ksfdwtio()+476<-ksfdwat1()+84<-k sfdrwat 0()+520<-kcrfw_post()+500<-kcrfw_redo_write()+2964<-ksbabs()+764<-ksbrdp() Truss output ~~~~~~~~~~~~~ = 1048576 67072 27640/38: kaio(AIONOTIFY, 0) = 0 27640/40: kaio(AIONOTIFY, 0) = 0 27640/43: kaio(AIONOTIFY, 0) = 0 27640/45: kaio(AIONOTIFY, 0) = 0 27640/1: kaio(AIOWAIT, 0xFFFFFFFF7FFFD480) = 1 27640/1: kaio(AIOWAIT, 0xFFFFFFFF7FFFD480) = 1 27640/1: kaio(AIOWAIT, 0xFFFFFFFF7FFFD480) = 1 27640/1: kaio(AIOWAIT, 0xFFFFFFFF7FFFD480) = 1 = 1048576 27640/42: kaio(AIONOTIFY, 0) = 0 27640/1: kaio(AIOWAIT, 0xFFFFFFFF7FFFD480) = 1 Note : The TRUSS output was taken with the filesystemio_options=setall. 1. Performed the test on solaris Box with the below settings : filesystemio_options=none disk_asynch_io=false _lgwr_async_io=TRUE 2. Performed another test on Linux with the following settings and it looks like the behaviour matches with Solaris and hence it looks like it may not be port specific . filesystemio_options=SETALL disk_asynch_io=TRUE _lgwr_async_io=TRUE/FALSE Linux_lgwr_true.out ) . Request you to review the uploaded files and update with the results of your analysis . As per Bug:8357698 LGWR USES ASYNC IO INSPITE OF SETTING _LGWR_ASYNC_IO=FALSE , the filesystemio_options & disk_asynch_io are overwriting _lgwr_async_io settings . Solution Most often high CPU consumption by lgwr is related to Async IO. You can try setting filesystemio_options=none & disk_asynch_io=false with obvious performance impact , but this may not be acceptable to you . As per Bug:8357698 LGWR USES ASYNC IO INSPITE OF SETTING _LGWR_ASYNC_IO=FALSE , the filesystemio_options & disk_asynch_io are overwriting _lgwr_async_io settings . 1] Move the Redologs to the filesystem where the async IO is not permitted . This will cause the lgwr process not to use async calls. OR 2] Use direct I/O, which is best done by mounting the corresponding filesystems unbuffered ( (using the"sync" option in Linux ext3, or the "forcedirectio" option in Solaris ufs, for example). For example : ========= On solaris: --------------- # mount_ufs -o forcedirectio /dev/rdsk/c2t3d0s0 /d17 If forcedirectio is specified and supported by the file system, then for the duration of the mount forced direct I/O will be used. If the filesystem is mounted using forcedirectio, then data is transferred directly between user address space and the disk. If the filesystem is mounted using noforcedirectio, then data is buffered in kernel address space when data is transferred between user address space and the disk. forcedirectio is a performance option that benefits only from large sequential data transfers. The default behavior is noforcedirectio. On linux : -------------- # mount -o sync /dev/rdsk/c2t3d0s0 /d17 The sync option has effect only for ext2, ext3, fat, vfat and ufs . The default is async . PS: We recommend you to involve your system administrator in chainging the moutn options of the OS file system .

由于Bug:8357698的存在,导致filesystemio_options和disk_asynch_io 2个参数可以覆盖_lgwr_async_io的设置,这个问题一直到11.1.0.6以后才得到修复,而在11.2中_lgwr_async_io参数干脆被取消了:

SQL> select * from v$version;BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - ProductionSQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ2   FROM SYS.x$ksppi x, SYS.x$ksppcv y3   WHERE x.inst_id = USERENV ('Instance')4   AND y.inst_id = USERENV ('Instance')5   AND x.indx = y.indx6  AND x.ksppinm='_lgwr_async_io';no rows selectedSQL> show parameter filesystemNAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
filesystemio_options                 string      setall
SQL> show parameter asyncNAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
disk_asynch_io                       boolean     TRUE
tape_asynch_io                       boolean     TRUEio_submit(139755827974144, 2, {{0x7f1b6e992450, 0, 1, 0, 256}, {0x7f1b6e9921f8, 0, 1, 0, 259}}) = 2
io_getevents(139755827974144, 2, 128, {{0x7f1b6e992450, 0x7f1b6e992450, 1024, 0}, {0x7f1b6e9921f8, 0x7f1b6e9921f8, 1024, 0}}, {600, 0}) = 2
times({tms_utime=3, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 480863691
semtimedop(2654212, 0x7fffadc3db80, 1, {3, 0}) = 0
times({tms_utime=3, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 480863808
times({tms_utime=3, tms_stime=4, tms_cutime=0, tms_cstime=0}) = 480863808
io_submit(139755827974144, 2, {{0x7f1b6e9921f8, 0, 1, 0, 256}, {0x7f1b6e992450, 0, 1, 0, 259}}) = 2
io_getevents(139755827974144, 2, 128, {{0x7f1b6e9921f8, 0x7f1b6e9921f8, 512, 0}, {0x7f1b6e992450, 0x7f1b6e992450, 512, 0}}, {600, 0}) = 2/* 在11.2中若启用了AIO,那么lgwr仍会沿用async IO */

总结: lgwr是否启用async IO取决于_lgwr_async_io隐藏参数,该参数默认为false,也就是说lgwr默认情况下应当使用sync同步IO。但是因为10.1.0.2到11.1.0.6间存在bug会导致_lgwr_async_io被disk_asynch_io和filesystemio_options参数覆盖而不起作用;在以上版本中若启用了AIO那么lgwr无疑会使用AIO,如果既想要启用AIO又不想因为lgwr使用async而造成隐患,那么可以将日志文件所在移动到不允许async IO的位置,或者使用direct/sync/forcedirectio选项来mount文件系统。在版本11.2以后_lgwr_async_io参数被废弃,lgwr是否启用async io完全取决于disk_asynch_io及filesystemio_options。

转载于:https://blog.51cto.com/maclean/1277797

Does LGWR use synchronous IO even AIO enabled?相关推荐

  1. Atitit  五种IO模型attilax总结 blocking和non-blocking synchronous IO和asynchronous I

    Atitit  五种IO模型attilax总结 blocking和non-blocking synchronous IO和asynchronous I   1.1. .3 进程的阻塞1 1.2. 网络 ...

  2. java ----IO/NIO/AIO

    1 使用File API里有很多关于File的使用方法: 案例:向磁盘创建文件 创建多级文件夹: 需要加s 把D盘的文件移动到C盘并且改为a.zip 2 文件遍历案例 找某盘下,大小为xxmb,后缀为 ...

  3. [编织消息框架][网络IO模型]AIO

    asynchronous I/O (the POSIX aio_functions)-----异步IO模型最大的特点是 完成后发回通知. 与NIO不同,当进行读写操作时,只须直接调用API的read或 ...

  4. BIO、伪异步 IO、AIO和NIO

    BIO 采用 BIO 通信模型的服务端, 通常由一个独立的 Acceptor 线程负责监听客户端的连接, 它接收到客户端连接请求之后为每个客户端创建一个新的线程进行链路处理, 处理完成之后, 通过输出 ...

  5. Java 网络IO编程总结(BIO、NIO、AIO均含完整实例代码)

    本文会从传统的BIO到NIO再到AIO自浅至深介绍,并附上完整的代码讲解. 下面代码中会使用这样一个例子:客户端发送一段算式的字符串到服务器,服务器计算后返回结果到客户端. 代码的所有说明,都直接作为 ...

  6. 关于java流的几个概念:IO、BIO、NIO、AIO,有几个人全知道?

    转载自 关于java流的几个概念:IO.BIO.NIO.AIO,有几个人全知道? 关于同步.阻塞的知识我之前的文章有介绍,所以关于流用到这些概念与之前多线程用的概念一样. 下面具体来看看java中的几 ...

  7. java中io.nio.aio_Java中网络IO的实现方式-BIO、NIO、AIO

    在网络编程中,接触到最多的就是利用Socket进行网络通信开发.在Java中主要是以下三种实现方式BIO.NIO.AIO. 关于这三个概念的辨析以前一直都是好像懂,但是表达的不是很清楚,下面做个总结完 ...

  8. java 修改最大nio连接数_关于java流的几个概念:IO、BIO、NIO、AIO,有几个人全知道?...

    关于同步.阻塞的知识我之前的文章有介绍,所以关于流用到这些概念与之前多线程用的概念一样. 下面具体来看看java中的几种流 IO/BIO BIO就是指IO,即传统的Blocking IO,即同步并阻塞 ...

  9. 【转】深入分析JAVA IO(BIO、NIO、AIO)

    IO的基本常识 1.同步 用户进程触发IO操作并等待或者轮询的去查看IO操作是否完成 2.异步 用户触发IO操作以后,可以干别的事,IO操作完成以后再通知当前线程继续处理 3.阻塞 当一个线程调用 r ...

最新文章

  1. java二叉树镜像_给定一个二叉树,检查它是否是镜像对称的。
  2. # 模糊图片边缘_PS大神给你变个魔术,如何巧用PS把模糊的照片变清晰
  3. android 勿扰模式代码,Android N Zen Mode (勿扰模式)设置流程
  4. centos的一次性任务at和周期性任务crontab
  5. SpringBoot中LogBack日志输出配置记录
  6. python教程视频哪个好-Python入门视频哪个好?
  7. 【leetcode】Trips and Users
  8. java最终类不能派生子类_最终类不能派生子类,最终方法不能被重写 (2.0分)_学小易找答案...
  9. JavaSE(二):Java语法(5)——Java数据类型转换
  10. gflags使用详解
  11. Word文档的两种密码忘记了,怎么办?
  12. 计算机分区硬盘有写保护,磁盘被写保护怎么解除的教程详解【图解】
  13. html网页中如何给文字加入下划线
  14. win10 蓝牙耳机 音量太小
  15. 【算法基础五】通讯录管理系统(自我评价)
  16. 怎样用计算机命令修复软件,chkdsk磁盘修复命令工具怎么用,怎样运行chkdsk工具修复?...
  17. 【测评】迅为4418/6818开发板安卓Android开发板
  18. 旋转协方差rot6d
  19. 【100个 Unity踩坑小知识点】| Unity 的 LOD技术(多细节层次)
  20. FLV科普12 FLV脚本数据解析-Metadata Tag解析

热门文章

  1. RabbitMQ在windows系统安装部署文档
  2. Java8中的HashMap分析
  3. php expat+DOM+SimpleXML XML读取
  4. nova虚拟机打不开console
  5. 基本数据结构和算法回顾
  6. 【ZJOI2013】k大数查询 BZOJ 3110
  7. 代码和产品发布的几种方式
  8. 使用create-react-app遇到问题解决方案汇总
  9. MongoError: topology was destroyed解决方法
  10. Oracle安装ORA-12154和ORA-12169问题的解决