views:

145

answers:

4

Recently I stumbled across this pretty slick JS library called nodeJS that acts like a server side JS. The main feature of the language being Evented I/O and which gives the inherent capacity of I/O being completely non-blocking!!! using callbacks.

My question is if such kind of I/O mechanism which is completely non-blocking existed in the past (event driven I/O had been for a long time), why the high level and popular languages like C#, Java aren't quite popular with them (Java has NIO implementation though that supports non-blocking I/O). As we know a simple file read/write operation results in complete I/O blocking which is not the case with event driven I/O. Also I am trying to understand more about event driven I/O and how it is different from what we have in Java.

A: 

Java has bad support even for basic file I/O. These languages are created for fast creation of portable GUI applications, and not for optimized and OS dependent low level I/O operations.

ruslik
I can't tell, was this answer a joke?
Kirk Woll
This doesn't compare with evented I/O and criticising Java I/O. Yes Java non blocking I/O via multi-threading (not pure non-blocking I/O though) is different from event driven I/O(which is pure non-blocking I/O) but each has it's own pro's and con's. Please support your statement with examples.
A_Var
+1  A: 

Java: http://en.wikipedia.org/wiki/New_I/O

A multiplexed, non-blocking I/O facility for writing scalable servers

.NET: http://msdn.microsoft.com/en-us/library/dxkwh6zw.aspx

public IAsyncResult BeginReceive(
    byte[] buffer,
    int offset,
    int size,
    SocketFlags socketFlags,
    AsyncCallback callback,
    Object state
)
Kirk Woll
Kirk excellent!!. But can you explain more about New I/O. Is it event driven??. I am trying to compare it with nodeJS. The reason why nodeJS is so popular is because of it's event driven I/O.
A_Var
I'm not sure if it's "event" driven in the sense you mean, but this is an excellent tutorial: http://rox-xmlrpc.sourceforge.net/niotut/
Kirk Woll
@A_Var: An event-driven engine is actually just an abstraction of state machines. In languages where there is no built-in event-driven engine most developers simply write their own state machine using a while loop and switch statements (or a dispatch table). Sometimes developers can be bothered enough to generalize their state machine implementation to make an API out of it resulting in an event-driven library for the language. An example of this is Python's Twisted framework.
slebetman
+1  A: 

As I understand it, there's a widespread perception that multithreading is easier than event-driven, since in multithreaded programming every thread has a simple sequential flow of execution, while event-driven consists of lots of small fragments of code.

Of course, this is better stated elsewhere, see for example Q.2 of state-threads FAQ.

ninjalj
+2  A: 

Tcl had event driven I/O from the 1990's (if I'm not mistaken). Certainly before 2000 because it was when tclhttpd beat Apache in benchmark tests sometime in 2000 that people really started paying attention to non-blocking I/O. When people saw that, they started re-writing web servers. One of the early result of that was Lighttpd: one of the first non-blocking web servers written in C. At that time, using event-driven I/O in tcl via the fileevent command was already considered standard practice in the tcl world.

AOLserver had (and still does) have a tcl core and it's hosting one of the busiest sites on the web (at least in the early days): http://www.aol.com/. Though the server itself is written in C, it uses tcl's C API to implement event handling and I/O. The reason AOLserver used tcl's I/O subsystem is because it uses tcl as a scripting language and the developers thought that since someone else have written it then might as well use it.

I believe AOLserver was first released in 1995. That should confirm that event-driven I/O was already available in tcl back in the mid 1990s.

Tcl is one of the earliest, if not the earliest language to have an event-driven engine built it. The event subsystem was originally implemented for the Tk library and was later merged into tcl itself.

slebetman