aio

[高并发Java 八] NIO和AIO

不问归期 提交于 2019-12-17 16:17:20
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> IO感觉上和多线程并没有多大关系,但是NIO改变了线程在应用层面使用的方式,也解决了一些实际的困难。而AIO是异步IO和前面的系列也有点关系。在此,为了学习和记录,也写一篇文章来介绍NIO和AIO。 1. 什么是NIO NIO是New I/O的简称,与旧式的基于流的I/O方法相对,从名字看,它表示新的一套Java I/O标 准。它是在Java 1.4中被纳入到JDK中的,并具有以下特性: NIO是基于块(Block)的,它以块为基本单位处理数据 (硬盘上存储的单位也是按Block来存储,这样性能上比基于流的方式要好一些) 为所有的原始类型提供(Buffer)缓存支持 增加通道(Channel)对象,作为新的原始 I/O 抽象 支持锁(我们在平时使用时经常能看到会出现一些.lock的文件,这说明有线程正在使用这把锁,当线程释放锁时,会把这个文件删除掉,这样其他线程才能继续拿到这把锁)和内存映射文件的文件访问接口 提供了基于Selector的异步网络I/O 所有的从通道中的读写操作,都要经过Buffer,而通道就是io的抽象,通道的另一端就是操纵的文件。 2. Buffer Java中Buffer的实现。基本的数据类型都有它对应的Buffer Buffer的简单使用例子: package test; import

What is the status of POSIX asynchronous I/O (AIO)?

纵然是瞬间 提交于 2019-12-17 06:22:23
问题 There are pages scattered around the web that describe POSIX AIO facilities in varying amounts of detail. None of them are terribly recent. It's not clear what, exactly, they're describing. For example, the "official" (?) web site for Linux kernel asynchronous I/O support here says that sockets don't work, but the "aio.h" manual pages on my Ubuntu 8.04.1 workstation all seem to imply that it works for arbitrary file descriptors. Then there's another project that seems to work at the library

io_submit() blocks until a previous operation will be completed

大城市里の小女人 提交于 2019-12-11 13:58:00
问题 I'm using the Linux kernel AIO through libaio , and I have to submit the next reading operation before the previous one was completed. The problem is that io_submit() blocks for some time and, as I can deduce from the interval, it waits the previous operation to be completed. I know that I can enqueue a several operations with a single io_submit() , but it is not an option for me, because I don't know how exactly the next read operation would like when it's already a time to submit the first

aio on osx: Is it implemented in the kernel or with user threads? Other Options?

为君一笑 提交于 2019-12-10 09:49:51
问题 I am working on my small c++ framework and have a file class which should also support async reading and writing. The only solution other than using synchronous file i/o inside some worker threads I found is aio. Anyways I was looking around and read somewhere, that in Linux, aio is not even implemented in the kernel but rather with user threads. Is the same true for OSX? Another concern is aio's functionality of callbacks which has to spawn an extra thread for each callback since you can't

AIO support on Linux

落花浮王杯 提交于 2019-12-09 19:44:46
问题 Does anyone know where I can get up to date information about the state on Kernel support for aio on the latest Linux Kernel?. Google searches bring up web pages that may be hopelessly out of date. Edit: More specifically, I am interested in non-file related descriptors like pipes and sockets. Stuff on the web indicate that there is no support, is this still the case? Edit2: What I am looking for is something similar to Windows OVERLAPPED IO 回答1: AIO support has been included in the linux

java I/O 模型简述

安稳与你 提交于 2019-12-07 20:57:39
同步与异步&阻塞与非阻塞 五大I/O模型详解 java I/O模型简述 概述 从同步与异步&阻塞与非阻塞的概念,到具体的I/O模型,再到具体的Java语言实现,都是层层递进,本篇就从Java语言来看I/O模型的大概情况。 整个Java I/O模型,大致可以分为三类 BIO:JDK1.4之前的阻塞IO NIO:JDK1.4及以后的版本非阻塞IO AIO:JDK1.7之后,又叫NIO.2 一、BIO阻塞IO 1、基本概念 BIO,即为Blocking I/O,阻塞IO,大致流程为: 1、服务端建立ServerSocket,以一个端口启动 2、等待客户端建立socket连接,如果没有连接,一直阻塞 3、一个socket建立连接之后,从线程池中去一个线程取处理socket 2、代码分析 public class BlockingIOServer { public static void main(String[] args) throws IOException { int port = 10000; ExecutorService threadPool = Executors.newFixedThreadPool(10); ServerSocket server = new ServerSocket(port); while(true){ Socket client = server

How to get user data for aio signal handler in Mac OS X

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 08:49:24
问题 I am attempting to use the aio_* functions for asynchronous file IO under Mac OS X, but I am having problems with getting some form of user data into the signal handler. This is the code that sets up an operation: class aio_context { public: aio_context(int fildes, boost::uint64_t offset, const MyBufferClassPtr &buffer) { // The aiocb struct must be zeroed memset(&m_aiocb, 0, sizeof(struct aiocb)); // Set what to do m_aiocb.aio_fildes = fildes; m_aiocb.aio_buf = buffer->data(); m_aiocb.aio

Asynchronous I/O Linux

谁说我不能喝 提交于 2019-12-06 13:01:02
问题 Need an async I/O Processing Plan to use async I/O through aio* calls on Linux The situation: I have opened socket with AF_INET and SOCK_STREAM flags (TCP) Have limit high watermark for send buffers Want to write to that socket asynchronously, and when send buffer overflows, want to disconnect an socket So, I have questions: When I made async call to aio_write on TCP socket, when I/O completion will arrives - when buffer written out into socket buffer or delivery is confirmed? How I can

How to get user data for aio signal handler in Mac OS X

假装没事ソ 提交于 2019-12-05 17:59:31
I am attempting to use the aio_* functions for asynchronous file IO under Mac OS X, but I am having problems with getting some form of user data into the signal handler. This is the code that sets up an operation: class aio_context { public: aio_context(int fildes, boost::uint64_t offset, const MyBufferClassPtr &buffer) { // The aiocb struct must be zeroed memset(&m_aiocb, 0, sizeof(struct aiocb)); // Set what to do m_aiocb.aio_fildes = fildes; m_aiocb.aio_buf = buffer->data(); m_aiocb.aio_nbytes = buffer->size(); m_aiocb.aio_offset = offset; // Set notification m_aiocb.aio_sigevent.sigev

BIO、NIO、AIO有什么区别?

梦想的初衷 提交于 2019-12-05 11:00:10
BIO:线程发起 IO 请求,不管内核是否准备好 IO 操作,从发起请求起,线程一直阻塞,直到操作完成。 NIO:线程发起 IO 请求,立即返回;内核在做好 IO 操作的准备之后,通过调用注册的回调函数通知线程做 IO 操作,线程开始阻塞,直到操作完成。 AIO:线程发起 IO 请求,立即返回;内存做好 IO 操作的准备之后,做 IO 操作,直到操作完成或者失败,通过调用注册的回调函数通知线程做 IO 操作完成或者失败。 BIO 是一个连接一个线程。 NIO 是一个请求一个线程。 AIO 是一个有效请求一个线程。 BIO:同步并阻塞,服务器实现模式为一个连接一个线程,即客户端有连接请求时服务器端就需要启动一个线程进行处理,如果这个连接不做任何事情会造成不必要的线程开销,当然可以通过线程池机制改善。 NIO:同步非阻塞,服务器实现模式为一个请求一个线程,即客户端发送的连接请求都会注册到多路复用器上,多路复用器轮询到连接有I/O请求时才启动一个线程进行处理。 AIO:异步非阻塞,服务器实现模式为一个有效请求一个线程,客户端的 IO 请求都是由 OS 先完成了再通知服务器应用去启动线程进行处理。 适用场景分析 BIO 方式适用于连接数目比较小且固定的架构,这种方式对服务器资源要求比较高,并发局限于应用中,JDK1.4 以前的唯一选择,但程序直观简单易理解。 NIO