DConf 2013 Day 2 Talk 4: Web Development in D by Vladimir Panteleev

Adam D. Ruppe destructionator at gmail.com
Mon Jun 3 12:27:00 PDT 2013


vibe.d really puts cgi.d to shame when it comes to scalability. 
With 100 concurrent connections, cgi.d (especially in 
embedded_http and fastcgi modes, scgi and cgi are a little 
behind) can hold its own. Not great, I got 5000 requests per 
second on my box, the same ballpark as C# in the video, but not 
too bad.

In the question section though he started to talk about event 
loops. I've been thinking about that too. It isn't tied into 
cgi.d yet, but I've written a linux loop built on epoll:

https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/eventloop.d

It uses a pipe back to itself for the injection of arbitrary 
events. Works something like this:

// this helps listening on file descriptors
FileEventDispatcher dispatcher;

// args are fd, on read ready, on write ready, on error
dispatcher.addFile(0, (int fd) {
     ubyte[100] buffer;
     auto got = unix.read(fd, buffer.ptr, buffer.length);
     if(got == -1)
          throw new Exception("wtf");
     if(got == 0)
        exit;
     else
         writeln(fd, " sent ", cast(string) buffer[0 .. got]);
}, null, null);

// you can also listen to events identified by type

addListener(delegate void(int a) { writeln("got ", a); });
addListener(delegate void(File a) { writeln("got ", a); });
send(20); // calls the listener above
send(stdin); // works with fancier types too

loop(); // enters the loop
}


I really like the idea of dispatching things based on type, it is 
so convenient and lets you plug anything in.

The FileEventDispatcher is different because all file descriptors 
are the same type, and we might want to differentiate it based on 
descriptor number. But you could also do addListener(FdReady) or 
something like that, i havent used this for a while.



Anyway my goal here is to prove that we can have one generic 
event loop that all libraries can use. My implementation probably 
isn't phobos bound, I'm settling for "works for me" and "proves 
it can work" but maybe the experience or some code will help when 
it is time to do a standard one.


I've plugged in my terminal.d to it (optionally, use 
-version=with_eventloop)) but that's it so far. Eventually I'll 
probably put simpledisplay and cgi.d in there as well and really 
see how it is coming together. If all goes well, we can have one 
program, one event loop, and all those various inputs handled.


More information about the Digitalmars-d-announce mailing list