`

未完 Java: IO & NIO(new I/O)

阅读更多
适用:
event and data-driven apps
selector(The Selector class plays the role of a Reactor in the Reactor pattern scenario.)  reactor proactor


http://www.kegel.com/c10k.html
引用
level-triggered & edge-triggered 中断:
http://stackoverflow.com/questions/1966863/level-vs-edge-trigger-network-event-mechanisms
http://venkateshabbarapu.blogspot.com/2013/03/edge-triggered-vs-level-triggered.html
level:在某个持续的状态下,会一直被触发
edge:事件发生的时候被触发,且处理事件期间不会被重复触发

completion notification VS readiness notification(notification 即 event notification):


https://chamibuddhika.wordpress.com/2012/08/11/io-demystified/
引用
The socket/file descriptors are abstracted
using Channels and Selector encapsulates the selection system call.



Scalable Event Multiplexing: epoll vs. kqueue:
http://www.eecs.berkeley.edu/~sangjin/2012/12/21/epoll-vs-kqueue.html


non-blocking and asynchronous io 之间的区别到底是什么?
https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014882947
http://doc.akka.io/docs/akka/2.3.8/general/terminology.html


http://stackoverflow.com/questions/3867042/one-thread-per-client-doable?lq=1
引用
The JVM for Linux is using one to one thread mapping. This means that every Java thread is mapped to one native OS thread.
So creating a thousand of threads or more is not a good idea because it will impact your performance (context switching, cache flushes / misses, synchronization latency etc). It also doesn't make any sense if you have less than a thousand of CPUs.
The only adequate solution for the serving many clients in parallel is to use asynchronous I/O. Please see this answer on Java NIO for details.


http://stackoverflow.com/questions/592303/asynchronous-io-in-java
引用
Java's NIO package (as of Java6), provides support for non-blocking I/O only, via Selectors. Java7 is hopefully going to ship with NIO.2, which includes asynchronous I/O support.
Non-blocking IO the kernel calls don't block under buffer-full(on writes) and buffer-empty(on reads), these states result in soft-error returns from the respective APIs.However non-blocking IO still copies data between user-space and kernel-space causing an unwanted extra copying of data which has a significant overhead when a lot of data is involved.The kernel then(may)copy the data yet again into packet size pieces with networking protocol overhead around it.Some network stacks/hardware drivers may support scatter gather to optimize the in kernel stages,but worst case is 3 copies.
Async IO accepts to remove the extra copying action during the data transition between user-space and kernel-space.This allows the kernel to directly access the data from user-space.To achieve this the application prepares memory and posts an IO request to the kernel.Control returns back to the application (the API is much like non-blocking).At some future point in time the kernel may access the user-space memory while performing the IO.Once done the kernel fires a signal like callback into user-space via the completion handler to notify the application of the IO result of request.
From a programming basis, non-blocking io (based usually on select) means that you still have to identify which sockets have incomming data on them. Async IO results in you getting a callback (or event) telling you the results of the IO action. There is also less kernel work to do, in theory asnyc io done in the kernal allows higher throughput and/or lower latency


Scalable IO in Java:
http://gee.cs.oswego.edu/dl/cpjslides/nio.pdf
Reactor Pattern Explained - Part 1:(part 2 / 3 等见链接)
http://jeewanthad.blogspot.com/2013/02/reactor-pattern-explained-part-1.html


Reactor和Proactor模式比较
http://liuxun.org/blog/reactor-he-proactor-mo-shi-bi-jiao/
Reactor: http://daimojingdeyu.iteye.com/blog/828696

待整理:何谓 IO? 及 Synchronous I/O vs Asynchronous I/O(Blocking I/O vs Non-Blocking I/O):
http://xcybercloud.blogspot.com/2009/06/network-io-blockingnon-blocking-vs.html
http://www.ibm.com/developerworks/library/j-nio2-1/
http://blog.csdn.net/historyasamirror/article/details/5778378
http://www.artima.com/articles/io_design_patterns2.html
http://www.cppblog.com/pansunyou/archive/2012/12/06/139343.html
http://www.developer.com/java/article.php/10922_3837316_3/Non-Blocking-IO-Made-Possible-in-Java.htm
http://stackoverflow.com/questions/5529137/java-non-blocking-and-asynchronous-io-with-nio-nio-2-jsr203-reactor-proact
http://stackoverflow.com/questions/2625493/asynchronous-vs-non-blocking?rq=1
http://www.cnblogs.com/zhuYears/archive/2012/09/28/2690194.html
http://tutorials.jenkov.com/java-nio/buffers.html#flip
http://blog.csdn.net/wuxianglong/article/details/6604817
http://docs.oracle.com/javase/1.4.2/docs/guide/nio/
http://stackoverflow.com/questions/1455117/best-model-for-an-nio-implementation
http://www.daniweb.com/software-development/computer-science/threads/384575/synchronous-vs-asynchronous-blocking-vs-non-blocking
http://stackoverflow.com/questions/8546273/is-non-blocking-i-o-really-faster-than-multi-threaded-blocking-i-o-how
引用
I/O includes multiple kind of operations like reading and writing data from hard drives, accessing network resources, calling web services or retrieving data from databases. Depending on the platform and on the kind of operation, asynchronous I/O will usually take advantage of any hardware or low level system support for performing the operation. This means that it will be performed with as little impact as possible on the CPU.
At application level, asynchronous I/O prevents threads from having to wait for I/O operations to complete. As soon as an asynchronous I/O operation is started, it releases the thread on which it was launched and a callback is registered. When the operation completes, the callback is queued for execution on the first available thread.
If the I/O operation is executed synchronously, it keeps its running thread doing nothing until the operation completes. The runtime doesn't know when the I/O operation completes, so it will periodically provide some CPU time to the waiting thread, CPU time that could have otherwise be used by other threads that have actual CPU bound operations to perform.
So, as @user1629468 mentioned, asynchronous I/O does not provide better performance but rather better scalability. This is obvious when running in contexts that have a limited number of threads available, like it is the case with web applications. Web application usually use a thread pool from which they assign threads to each request. If requests are blocked on long running I/O operations there is the risk of depleting the web pool and making the web application freeze or slow to respond.
One thing I have noticed is that asynchronous I/O isn't the best option when dealing with very fast I/O operations. In that case the benefit of not keeping a thread busy while waiting for the I/O operation to complete is not very important and the fact that the operation is started on one thread and it is completed on another adds an overhead to the overall execution.


Java™ I/O, NIO, and NIO.2:
http://docs.oracle.com/javase/7/docs/technotes/guides/io/

IO
  



New I/O
  
New I/O APIs:
http://docs.oracle.com/javase/1.4.2/docs/guide/nio/

Asynchronous I/O, or non-blocking I/O, is a form of input/output processing that permits other processing to continue before the transmission has finished.

核心概念: Channel 的 Multiplexed(多路复用):
A selector is a multiplexor of selectable channels, which in turn are a special type of channel that can be put into non-blocking mode. To perform multiplexed I/O operations, one or more selectable channels are first created, put into non-blocking mode, and registered with a selector. Registering a channel specifies the set of I/O operations that will be tested for readiness by the selector, and returns a selection key that represents the registration.
Selector 的 readiness selection
引用
readiness selection 是什么?举个例子,以 network programming 为例, readiness selection 指 the ability to choose a socket that will not block when read or written.
http://underpop.online.fr/j/java/java-network-programming/javanp3-CHP-12-SECT-5.html



Java NIO vs. IO:
https://blogs.oracle.com/slc/entry/javanio_vs_javaio
http://tutorials.jenkov.com/java-nio/nio-vs-io.html

NIO Performance Improvement compared to traditional IO in Java:
http://stackoverflow.com/questions/7611152/nio-performance-improvement-compared-to-traditional-io-in-java
分享到:
评论

相关推荐

    Java I/O学习笔记: 磁盘操作 字节操作 字符操作 对象操作 网络操作 NIO & AIO Java I/O

    Java I/O学习笔记: 磁盘操作 字节操作 字符操作 对象操作 网络操作 NIO & AIO Java I/O Java是一种面向对象的编程语言,由Sun Microsystems于1995年推出。它是一种跨平台的语言,意味着可以在不同的操作系统上运行...

    Java IO, NIO and NIO.2(Apress,2015)

    Java I/O, NIO, and NIO.2 is a power-packed book that accelerates your mastery of Java's various I/O APIs. In this book, you'll learn about classic I/O APIs (File, RandomAccessFile, the stream classes ...

    【图解】深入分析Java IO&NIO;工作机制

    【图解】深入分析Java I_O工作机制,从传统IO分析至NIO,调优以及原理,不可用于商业用途,如有版权问题,请联系删除!

    java学习笔记1(java io/nio)

    java学习笔记1(java io/nio)设计模式

    Java面试手册PDF

    压缩包内只有一个文件,Java面试手册.pdf 目录: Java基础题 Java集合 异常&反射 IO&NIO 多线程 JVM Linux MySQL Spring Mybatis Nginx Redis Dubbo SpringBoot Kafka SpringCloud 简历

    Java IO, NIO and NIO.2 原版pdf by Friesen

    New I/O (NIO), and NIO.2 categories. You learn what each category offers in terms of its capabilities, and you also learn about concepts such as paths and Direct Memory Access. Chapters 2 through 5 ...

    NIO与I/O的区别

    NULL 博文链接:https://haifeng0730.iteye.com/blog/1507931

    Java IO_NIO

    1、Java IO_NIO 2、Java+IO.pdf

    NIO学习系列:连网和异步IO

    NULL 博文链接:https://zhangshixi.iteye.com/blog/683767

    Java NIO 英文文字版

    Many serious Java programmers, especially enterprise Java programmers, consider the new I/O API--called NIO for New Input/Output--the most important feature in the 1.4 version of the Java 2 Standard ...

    java nio 中文版

    这些新的I/O特性主要包含在java.nio软件包及其子包中,并被命名为New I/O(NIO)。通过本书,您将学会如何使用这些令人兴奋的新特性来极大地提升Java应用程序的I/O效率。  目录 前言 第一章 简介 第二章 缓冲...

    java nio中文版

    java NIO是 java New IO 的简称,在 jdk1.4 里提供的新 api 。 Sun 官方标榜的特性如下: – 为所有的原始类型提供 (Buffer) 缓存支持。 – 字符集编码解码解决方案。 – Channel :一个新的原始 I/O 抽象。 – 支持...

    Java IO, NIO and NIO.2

    Input/output (I/O) is not a sexy subject, but it’s an important part of non-trivial applications. This book introduces you to most of Java’s I/O capabilities as of Java 8 update 51.

    java io 与java nio区别

    java频道\java io 与java nio区别.txt

    Java IO NIO and NIO 2 无水印pdf

    Java IO NIO and NIO 2 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn...

    Java NIO 中文 Java NIO 中文 Java NIO 中文文档

    Java NIO 深入探讨了 1.4 版的 I/O 新特性,并告诉您如何使用这些特性来极大地提升您所写的 Java 代码的执行效率。这本小册子就程序员所面临的有代表性的 I/O 问题作了详尽阐述,并讲解了 如何才能充分利用新的 I/O ...

    Java IO NIO and NIO 2 epub

    Java IO NIO and NIO 2 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    java nio proraming pdf

    java.nio (NIO stands for non-blocking I/O) is a collection of Java programming language APIs that offer features for intensive I/O operations. It was introduced with the J2SE 1.4 release of Java by ...

    JAVA非阻塞NIO_IO2

    本书介绍了 Java 平台上的高级输入/输出,具体点说,就是使用 Java 2 标准版(J2SE)软件 ...名为 New I/O(NIO)。通过本书,您将学会如何使用这些令人兴奋的新特性来极大地提升 Java 应 用程序的 I/O 效率。

Global site tag (gtag.js) - Google Analytics