NBIO: Java Non-blocking I/O Library

来源:百度文库 编辑:神马文学网 时间:2024/10/02 20:26:02
NBIO: Nonblocking I/O for Java
Matt Welsh, Harvard University
Last updated 11 July 2002
Introduction
NBIO is a library that implements nonblocking I/O facilities for Java. Surprisingly, the standard JDK libraries (as of JDK 1.3) do not provide nonblocking I/O. This means that in order to implement applications (such as web servers and other Internet services) that support many concurrent I/O streams, a large number of threads must be used. However, the overhead of threading (in Java, as well as more generally) limits the performance of such an implementation.
What is needed is a nonblocking I/O library that allows a small number of threads to be used, along with a select() or poll() like mechanism to test for incoming I/O events on a large number of streams. This is what NBIO provides.
NBIO is implemented using a native code wrapper to nonblocking I/O, as well as the poll() system calls and /dev/poll event-delivery mechanism. The native code for this is found in the jni directory. This library is known to work on Linux 2.2 and 2.4 systems, Solaris 7 and 8, FreeBSD, and HP/UX. Because it uses standard UNIX system calls, it should either work or be easy to port to a large number of other UNIX systems. A beta release for Windows 2000 systems is available - see below. NBIO isopen source software.
I am using NBIO as the basis for my thesis research onthe staged event-driven architecture (or SEDA). While NBIO provides a low-level nonblocking I/O library for Java, SEDA is a complete architecture and runtime system for building well-conditioned Internet services. In particular, our Java-based Web server, using NBIO, outperforms both Apache and Flash, which are written in C. More information can be found at theSEDA web pages.
Somebenchmark results comparing the use of NBIO with threaded server implementations can be found here. Newer results can be found in ourSOSP‘01 paper on SEDA.
NBIO is being used by a number of commercial products and open-source systems. One example isSwiftMQ, a free Java-based JMS Enterprise Messaging server, to provide superior scalability and performance for MQ-based applications.Read more here.
Note on JDK 1.4 java.nio package
The recently-announced JDK 1.4 beta includes the package java.nio which, among other things, provides nonblocking I/O primitives for Java. As it turns out I am on the expert group for the Sun Java Specification Request for this package (seethis link for more details). More details on this new API can be foundat this URL; as you can see, java.nio has been influenced somewhat by the NBIO APIs.
My plan is to continue developing and supporting NBIO until stable, released versions of JDK 1.4 are available on Linux both from Sun and IBM. At that point I will deprecate NBIO in favor of the new APIs, but NBIO will continue to be supported (although the development will be frozen). Migration from NBIO to java.nio should not be difficult. If you are in need of an efficient, working nonblocking I/O library for Java, my recommendation is to go ahead and use NBIO, and move over to java.nio once it is available.
Latest News
Code releases moved to SourceForge - July 11, 2002
I have decided to migrate hosting of the NBIO and SEDA projects to SourceForge.net.Access the SEDA/NBIO SourceForge pages here. Mailing lists have also moved to SourceForge - see below.
I have released NBIO v2.0 which is identical to v1.6 except that the package name has changed to seda.nbio.