caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yaron Minsky <yminsky@janestreet.com>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: Anil Madhavapeddy <anil@recoil.org>, caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Non-blocking IO interface design
Date: Tue, 10 Apr 2012 08:40:49 -0400	[thread overview]
Message-ID: <CACLX4jRyRLboJHavvxbLp+x2h=AkC+KTj3iMnrCX41zRBJzKfw@mail.gmail.com> (raw)
In-Reply-To: <8CE84D3ACD2A43659ABB1EF6BAFE8A9A@erratique.ch>

On Tue, Apr 10, 2012 at 4:21 AM, Daniel Bünzli
<daniel.buenzli@erratique.ch> wrote:
> Anil,
>
> Thanks for the analysis.
>
>> The I/O loop is being called twice for the non-blocking version, as it receives
>> the `Await signal, does the Unix syscall, and then jumps into decode_src. Presumably
>> a full non-blocking version would have to register with a select handler if it
>> gets an EAGAIN at this point,
>
>
> Yes.
>
>> In terms of the number of system calls, the non-blocking one is more efficient,
>> as it uses a 16KB buffer versus the 4K reads done by the blocking version.
>
>
> Yes, the 4K reads are a limitation of pervasives channels. For each mechanism I used the largest buffer that the OCaml runtime uses.
>
>> Looking at the two decoders in src/se.ml, it looks like the non-blocking one
>> allocates closures on every loop, which the blocking one doesn't. This is so it
>> can store the continuation in d.k for the next loop.
>
>
> Yes, that's a side effect of writing in continuation passing style in general since continuations are often partially applied functions.

I believe this particular performance issue is fixed in the upcoming
4.0 release, based on some work by OCamlPro.

>> So to summarise, instead of storing a continuation closure, it would probably be better
>> to explicitly store the state in d.k to minimise allocation?
>
>
> Maybe, but keep in mind that s-expressions are very simple to parse. It may be obvious in this case but depending on what you decode defining/storing the state may become complex. Cps is an easy and general way to solve the problem while keeping the whole thing reasonably readable. But do you maybe see another pattern that I don't ?
>
>> The library looks very useful by the way: I have exactly the same issue with several
>> Lwt-only protocol libraries we're developing at the moment. Would love to use yours before
>> the first release of them to make them more independent of the underlying I/O mechanism...
>
>
> That would be nice, I'm glad if you can somehow reuse the pattern.
>
>
> Best,
>
> Daniel
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2012-04-10 12:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-08 20:37 Daniel Bünzli
2012-04-09 19:28 ` Anil Madhavapeddy
2012-04-10  8:21   ` Daniel Bünzli
2012-04-10 12:40     ` Yaron Minsky [this message]
2012-04-14  9:46       ` Daniel Bünzli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACLX4jRyRLboJHavvxbLp+x2h=AkC+KTj3iMnrCX41zRBJzKfw@mail.gmail.com' \
    --to=yminsky@janestreet.com \
    --cc=anil@recoil.org \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).