From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 73AA5BBAF for ; Sun, 24 Oct 2010 22:54:57 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEAAM6xExZELGa/2dsb2JhbACiT7odhUgEgVqCeoV5 X-IronPort-AV: E=Sophos;i="4.58,233,1286143200"; d="scan'208,217";a="75666468" Received: from recoil.dh.bytemark.co.uk (HELO dark.recoil.org) ([89.16.177.154]) by mail4-smtp-sop.national.inria.fr with SMTP; 24 Oct 2010 22:54:57 +0200 Received: (qmail 12985 invoked by uid 634); 24 Oct 2010 20:54:56 -0000 X-Spam-Level: * X-Spam-Check-By: dark.recoil.org Received: from user-64-9-236-165.googlewifi.com (HELO user-64-9-236-165.googlewifi.com) (64.9.236.165) (smtp-auth username remote@recoil.org, mechanism cram-md5) by dark.recoil.org (qpsmtpd/0.83) with ESMTPA; Sun, 24 Oct 2010 21:54:55 +0100 Subject: Re: [Caml-list] Asynchronous IO programming in OCaml Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: multipart/alternative; boundary=Apple-Mail-1-408844920 From: Anil Madhavapeddy In-Reply-To: Date: Sun, 24 Oct 2010 13:54:50 -0700 Cc: Jon Harrop , caml-list@yquem.inria.fr Message-Id: References: <044101cb7367$10f94b30$32ebe190$@com> To: Jake Donham X-Mailer: Apple Mail (2.1081) X-Virus-Checked: Checked by ClamAV on dark.recoil.org X-Spam: no; 0.00; ocaml:01 anil:01 anil:01 ocaml:01 event-driven:01 off-list:01 async:01 event-driven:01 off-list:01 async:01 threads:01 threads:01 wrote:01 wrote:01 caml-list:01 --Apple-Mail-1-408844920 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 24 Oct 2010, at 09:17, Jake Donham wrote: > On Sun, Oct 24, 2010 at 3:34 AM, Jon Harrop = 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. >=20 > Not a tutorial, but here is a minimal TCP server in LWT: >=20 > = http://github.com/avsm/ocaml-cohttpserver/blob/master/server/http_tcp_serv= er.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= --Apple-Mail-1-408844920 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii
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:


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
--Apple-Mail-1-408844920--