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:
- 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数据库是从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
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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 ~]$
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
参考资料:
http://www.ibm.com/developerworks/linux/library/l-async/index.html
http://blog.sina.com.cn/s/blog_465a4a1e0100oizv.html
http://semiter.blog.51cto.com/1234477/1243325
ORACLE数据库异步IO介绍的更多相关文章
- 【python】-- 事件驱动介绍、阻塞IO, 非阻塞IO, 同步IO,异步IO介绍
事件驱动介绍 一.前言 通常,我们写服务器处理模型的程序时,有以下几种模型: (1)每收到一个请求,创建一个新的进程,来处理该请求: (2)每收到一个请求,创建一个新的线程,来处理该请求: (3)每收 ...
- oracle启用异步IO(db file async I/O submit)
市局双随机awr报告中有大量db file async I/O submit等待事件 参考两篇文章: [案例]Oracle等待事件db file async I/O submit产生原因和解决办法 d ...
- Select、Poll、Epoll、 异步IO 介绍
一.概念相关介绍 同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一下本文的上下文. 本文讨论的背景是Linux环境下的net ...
- PL/SQLDeveloper导入导出Oracle数据库方法
前一篇博客介绍了Navicat工具备份Oracle的方法,这篇博客介绍一下使用PL/SQL Developer工具导入导出Oracle数据库的方法. PL/SQL Developer是Oracle数据 ...
- [转]PL/SQLDeveloper导入导出Oracle数据库方法
原文地址:http://www.2cto.com/database/201405/305452.html 1.Oracle数据库导出步骤 1.1 Tools→Export User Objects.. ...
- Golang连接Oracle数据库
Golang连接Oracle的库有很多,比较常见的如下: 不过,oralce 只提供了 oci8 的接口,必须通过它来调用,所以下面方案都逃不过相关设置. 1.go-db-oracle 地址: htt ...
- 阻塞IO, 非阻塞IO, 同步IO,异步IO
阻塞IO, 非阻塞IO, 同步IO,异步IO 介绍 先说明几个概念 用户空间与内核空间 为了保证用户进程不能直接操作内核(kernel),保证内核的安全,操心系统将虚拟空间(内存)划分为两部分,一部分 ...
- 《Windows核心编程系列》十谈谈同步设备IO与异步设备IO之异步IO
同步设备IO与异步设备IO之异步IO介绍 设备IO与cpu速度甚至是内存访问相比较都是比较慢的,而且更不可预测.虽然如此,通过使用异步设备IO我们仍然能够创造出更高效的程序. 同步IO时,发出IO请求 ...
- JNDI连接池连接Oracle数据库
今天做了一个评论的小功能,要求用JNDI连接池连接Oracle数据库,以前只是测试了是否连接的上,现在没想到一个JNDI连接池连接Oracle数据库,纠结了好久,原来都是Oracle数据库的问题,这是 ...
随机推荐
- ASP.NET MVC 网站开发总结(四)——校友平台开发总结
又历经一个多月的努力,学校的一个校友平台项目也接近内测的尾声了,简单的总结一下这次的项目开发. 与上次做Wing工作室的门户网站相比,同样是团队开发,参与的人员多了一个,用的时间也差不多一个月,但从总 ...
- [工具] GIF 动画每帧合并到一张 PNG
功能:将 GIF 动画每帧合并到一张 PNG 需求:配合 ImageMagick 图像处理软件. 下载:[工具]Gif2Png_Aone_1.0.0.zip 使用方法: 请到 ImageMagick ...
- HTML标签小结
HTML:超文本标记语言 超:超链接 超文本:超出文本(可加入图片,文字,音频视频播放器) 标记:标签 HTML文档 以<html...>开始 , 以</html> ...
- 安装Sublime Text 3汉化插件
一.Sublime Text工具介绍: Sublime Text 是一个代码编辑器(Sublime Text 2是收费软件,但可以无限期试用),也是HTML和散文先进的文本编辑器.Sublime Te ...
- sql传入组合字符串批量操作
批量操作时我们可以传入一个有规律的ID或则是其他唯一值字段的组合字符串,然后:select/update/inset......where 字段 in(传入的组合字符串),而且很多时候我们还涉及到其 ...
- Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)
题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...
- HR人力资源战略流程制定
HR人力资源战略 是指根据企业总体战略的要求,为适应企业生存和发展的需要,对企业人力资源进行开发,提高职工队伍的整体素质,从中发现和培养出一大批优秀人才,所进行的长远性的人力资源管理方面的专业谋划和方 ...
- java栈和堆区别
1, 垃圾回收机制仅仅作用于堆内存,与栈内存无关; 2, 栈:stack 栈的存取速度比堆快,效率高 保存局部变量和对象的引用值 3, 堆:保存较大的变量 4, 栈有一个很重要的特殊性,就是存在栈中的 ...
- slid.es – 创建在线幻灯片和演示文稿的最佳途径
slid.es 提供了一种创建在线幻灯片和演示文稿的简单方法,让你通过几个简单的步骤制作效果精美的在线演示文稿.基于 HTML5 和 CSS3 实现,在现代浏览器中效果最佳. 您可能感兴趣的相关文章 ...
- 变量作用域&函数作用域
一. 变量作用域 1)全局变量 在全局环境下声明的变量被视为全局变量. 在没有使用var进行声明的时候,变量就被定义为全局变量.在ES5的严格模式下,如果变量没有使用var来声明是会报错的. 2)局部 ...