caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Jeremie Dimino <jeremie@dimino.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Asynchronous IO programming in OCaml
Date: Thu, 28 Oct 2010 12:11:55 +0200	[thread overview]
Message-ID: <8762wm8w44.fsf@frosties.localdomain> (raw)
In-Reply-To: <20101028092841.GA23531@aurora> ("Jeremie Dimino"'s message of "Thu, 28 Oct 2010 11:28:41 +0200")

Jérémie Dimino <jeremie@dimino.org> writes:

> On Thu, Oct 28, 2010 at 11:00:59AM +0200, Goswin von Brederlow wrote:
>> NUMA has memory dedicated to each core. Each core can access its memory
>> fast. Accessing some other cores memory on the other hand is slower (and
>> will have to fight for access with that core).
>
> And so that is a bad solution for Lwt since it runs on one system
> thread.

Does that matter? The copying would be going on in the kernel and use
multiple cores even if the read requests all came from one core I think.

>> Nah, if you can detect the error then handing is easy. The problem is
>> detecting. Write() itself can fail and that is easy to detect. But
>> write() succeeding doesn't mean the data has been written
>> successfully. You can still get an error after that which you only get
>> on fsync().
>
> Take for example buffered channels, when you would have to flush the
> buffer, you would launch a thread calling write and let the program
> continue to write onto the channel, assuming that the write succeed. But
> if one write fails, you would get the error latter. And worst, if the
> program stop using the buffer after the flush, it will never get the
> error.
>
> Jérémie

True. Your program will have to handle errors.

Normaly I would say that a flush/sync on a channel/file has to block the
thread and continue only on error or success. Otherwise you would be
talking more about barriers and simulate them with flush/sync (since
userspace lacks an interface for them). Doing error handling with
barriers is indeed more tricky.

But I was more thinking of having async writes with error reporting. Say
you have 1000 "threads" that need to write something. They all call
my_write(). The my_write() function issues an async write request,
blocks the "thread" and continues some other "thread". Once the write
request has complete the "thread" is woken up and gets a success or
failure message. "thread" here doesn't mean an actual system
thread. More a logical thread like handling of a specific connection.

Even more async would be to pass a callback to the my_write() that gets
called on success or failure and have my_write() return directly. Again
error hadnling is easy since you have the callback to handle it. So
my_write would look something like this:

let my_write fd off str fn = ...
val my_write : Unix.file_descr Int64.t string (Unix.error option -> unit) -> unit
(** Write string <str> to file <fd> at offset <off> and call <fn> with
    None on success or Some error on failure. *)

The program can then decide to continue (do something else after
my_write) or to block (put the rest of the code into the callback and
return).

MfG
        Goswin


  reply	other threads:[~2010-10-28 10:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-24 10:34 Jon Harrop
2010-10-24 12:51 ` [Caml-list] " philippe
2010-10-24 12:52 ` Dario Teixeira
2010-10-24 16:33   ` oliver
2010-10-24 18:50     ` Dario Teixeira
2010-10-24 19:04       ` bluestorm
2010-10-24 20:02       ` oliver
2010-10-24 21:51     ` Michael Ekstrand
2010-10-24 16:17 ` Jake Donham
2010-10-24 20:54   ` Anil Madhavapeddy
2010-10-24 22:50     ` Jérémie Dimino
2010-10-25  3:42       ` Markus Mottl
2010-10-25  7:49         ` Richard Jones
2010-10-25  8:42       ` Goswin von Brederlow
2010-10-25 11:10         ` Jérémie Dimino
     [not found]           ` <AANLkTimP77PDEChW3Yt6uUy_qxYpj6EOZWQ_==id-LBC@mail.gmail.com>
     [not found]             ` <20101025143317.GB32282@aurora>
2010-10-25 15:34               ` Yaron Minsky
2010-10-25 17:26                 ` Jérémie Dimino
2010-10-27  9:33                   ` Goswin von Brederlow
2010-10-27 11:18                     ` Jérémie Dimino
2010-10-27 13:43                       ` Goswin von Brederlow
2010-10-27 15:30                         ` Jérémie Dimino
2010-10-28  9:00                           ` Goswin von Brederlow
2010-10-28  9:28                             ` Jérémie Dimino
2010-10-28 10:11                               ` Goswin von Brederlow [this message]
2010-10-25 15:58           ` DS
2010-10-24 20:42 ` Goswin von Brederlow

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=8762wm8w44.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@inria.fr \
    --cc=jeremie@dimino.org \
    /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).