From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id AD81BBBAF for ; Tue, 24 Aug 2010 01:29:52 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AngBAKygckzU4xEIkGdsb2JhbACDF49fjUQVAQEBAQkJDAcRAx+qYZIxAoEggVKBUHME X-IronPort-AV: E=Sophos;i="4.56,259,1280700000"; d="scan'208";a="57711485" Received: from moutng.kundenserver.de ([212.227.17.8]) by mail2-smtp-roc.national.inria.fr with ESMTP; 24 Aug 2010 01:29:52 +0200 Received: from office1.lan.sumadev.de (dslb-094-219-213-232.pools.arcor-ip.net [94.219.213.232]) by mrelayeu.kundenserver.de (node=mrbap0) with ESMTP (Nemesis) id 0LvPmd-1Ovu0K1DZz-010VOx; Tue, 24 Aug 2010 01:29:51 +0200 Received: from [192.168.0.29] (dslb-084-058-025-016.pools.arcor-ip.net [84.58.25.16]) by office1.lan.sumadev.de (Postfix) with ESMTPA id 93A135F702; Tue, 24 Aug 2010 01:29:50 +0200 (CEST) Subject: Re: [Caml-list] node.ocaml From: Gerd Stolpmann To: Jeffrey Barber Cc: caml-list@inria.fr In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Date: Tue, 24 Aug 2010 01:29:48 +0200 Message-ID: <1282606188.3357.422.camel@thinkpad> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:IA4C/1BPq/Fl44iAsRTJCbl1c5pdQvj3MxIb2L5qbYX Z2WhTFWpoaTm49SAd3bSwmJ/7pyl595g25UWs5Ppeq64E+0Y1Y A9Sfq9XNo3d/weyy/CRDLM8JxNEJoj06vzO5bKL+KX0yn/bSAF rh7OiiqK4LW14HDkBZPNbB3cOZQZS21ONsp4nwL+LU0TCD1/l5 yYFVfTSCfwXc+piPGENNw== X-Spam: no; 0.00; node:01 ocaml:01 gerd:01 stolpmann:01 ocamlnet:01 ocamlnet:01 event-driven:01 descriptors:01 ocamlnet-:01 ocamlnet-:01 abstraction:01 high-level:01 callbacks:01 ocaml:01 gerd:01 You may also look at ocamlnet (http://projects.camlcity.org/projects/ocamlnet.html), which provides a stack of abstractions for event-driven programming: - The Netsys library defines an object type for sets of file descriptors one can poll: http://projects.camlcity.org/projects/dl/ocamlnet-3.0test5/doc/html-main/Netsys_pollset.pollset.html There is right now only an implementation for poll(), but no fancy things like what libevent provides (but this is just lack of time). - Above that, there is the equeue library with its main interface Unixqueue: http://projects.camlcity.org/projects/dl/ocamlnet-3.0test5/doc/html-main/Unixqueue.html This provides a queue of events, and a mechanism to consume events. - Above that, there is the engines API: http://projects.camlcity.org/projects/dl/ocamlnet-3.0test5/doc/html-main/Uq_engines.html This is an abstraction allowing easy composition of code. An engine represents a suspended I/O operation to which one can attach continuations. There are even implementations of high-level protocols using these APIs (most hooking in at the Unixqueue level), and this includes HTTP, Telnet, FTP (partly), and SunRPC. Companies are using this already in products, so this is really a mature implementation. It is interesting that in your code the callbacks are implemented on the C side. I think this is generally more complicated than doing the same in Ocaml which is way more a "callback-friendly" language. Gerd Am Samstag, den 21.08.2010, 22:27 -0500 schrieb Jeffrey Barber: > I've been working with libevent2 and OCaml for the past couple of > weeks to build node.ocaml. It is far from done, but it is interesting > enough to share. > > node.ocaml as of now contains a web server and a terminal server that > provides asynchronous programming to OCaml to enable some of my > research. The first example server is a key value pair server that > brings OCaml's Hashtbl to http and terminal IO: > > example code: > http://github.com/mathgladiator/node.ocaml/blob/master/test/kvp.ml > > This is the first test program, and it works fairly well in a single > threaded environment. I was inspired by node.js to build an evented io > system, and so I begged the question "how does 'OCaml's FFI' compare > with v8's in node.js". In my virtual machine environment (ubuntu > 10.04), I got the following results doing 10,000 requests 50 at a > time: > > node.js with the "Hello World" script: > 2100 requests/second > > node.ocaml with kvp.ml: > 5300 requests/second > > This seems to me to be a very positive first benchmark considering I > haven't optimized anything yet nor have I hacked caml_copy_string yet. > > The code is licensed under BSD and available > http://github.com/mathgladiator/node.ocaml . > > Any thoughts/questions are appreciated; thank you for your time. > > -J > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs -- ------------------------------------------------------------ Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de Phone: +49-6151-153855 Fax: +49-6151-997714 ------------------------------------------------------------