On 24 Oct 2010, at 09:17, Jake Donham wrote:

On Sun, Oct 24, 2010 at 3:34 AM, Jon Harrop <jon@ffconsultancy.com> wrote:
Is there a tutorial on using something like LWT for asynchronous programming
in OCaml? I'm looking for an example like an echo server that handles
clients concurrently without blocking threads, so it can handle thousands of
clients without significant performance degradation.

Not a tutorial, but here is a minimal TCP server in LWT:

  http://github.com/avsm/ocaml-cohttpserver/blob/master/server/http_tcp_server.ml

This should work fine for a couple of thousand clients or so, but you'll begin to see degradation as the number of clients increase. This is because LWT internally uses select(2) to wait for file-descriptors, and not the newer kqueue(2) or epoll(2) interfaces. You can read more about the "C10K problem" here: http://www.kegel.com/c10k.html

I've got a stripped-down version of LWT that uses these newer event-driven kernel interfaces (and so should be able to cross the 10,000 client barrier fairly easily), but it won't be ready for release for another month or so.  Drop me an email off-list if you want to try it out earlier.

Async disk I/O under Linux is annoyingly problematic if you aren't using direct I/O (and hence page/block-aligned structures). Avoid if possible :)

Anil