caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Anil Madhavapeddy <anil@recoil.org>
To: Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
Cc: Stephen Dolan <stephen.dolan@cl.cam.ac.uk>,
	Jiten Pathy <jpathy@fssrv.net>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Multicore runtime
Date: Mon, 8 Sep 2014 16:56:52 +0100	[thread overview]
Message-ID: <FE011996-4EF9-4C37-B43C-B4E2C226A678@recoil.org> (raw)
In-Reply-To: <CAGrdgiUrF86W6ooyXCH3jYjX0aGCER8O7u1vqvBjojQDv=E3Kg@mail.gmail.com>

On 8 Sep 2014, at 15:49, Jesper Louis Andersen <jesper.louis.andersen@gmail.com> wrote:

> 
> On Mon, Sep 8, 2014 at 12:05 PM, Stephen Dolan <stephen.dolan@cl.cam.ac.uk> wrote:
> Generally, we're going to try to avoid blocking C calls and instead
> use select/poll/kqueue/epoll to handle blocking I/O. From the fiber's
> point of view, this looks like normal blocking I/O, except if a system
> call returns EWOULDBLOCK we'll switch to another fiber until the I/O
> is ready.
> 
> 
> The problem is that for file descriptors representing (kernel) file objects, they never return EWOULDBLOCK since you can always write to them (rather subtle semantics). But once you write to them, that thread is off to kernelspace and you only get it back milliseconds later when the write is complete. In the meantime that thread is placed in uninterruptible sleep. The async File I/O implementations are not portable either, which is why everyone ends up with having process pools for this or ends up spawning threads. Go's rationale is that file I/O is probably going to take so long anyway that it doesn't really cost too much to create another thread (given that you also run a thread cache of where to hand off the domain). This URI has a high-level overview of the Go style:
> 
> http://morsmachine.dk/go-scheduler
> 
> and there are nice isomorphisms to the concept of fiber (G) and domain (P) and thread (M).


Indeed, our fiber model is compatible with filesystem I/O, but does not
*mandate* that implementations support threads if a better-than-POSIX
model is available on the target operating system.  Async I/O works fine
on Windows for instance, and does not require a thread-per-operation.

Much of the platform portability code (which requires excruciating testing
and is not something we want to replicate) for async filesystem I/O is
already present in libuv upstream:

  https://github.com/joyent/libuv

I'd be most interested in hearing from anyone that would like to work on
a Ctypes binding to libuv, since that could provide the basis for an
excellent platform-independent I/O library as an alternative to the Unix
module.

best,
Anil

  parent reply	other threads:[~2014-09-08 15:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-07 21:47 Jiten Pathy
2014-09-08 10:05 ` Stephen Dolan
2014-09-08 10:27   ` Peter Zotov
2014-09-08 10:45     ` Roberto Di Cosmo
2014-09-08 10:45   ` Leonardo Laguna Ruiz
2014-09-08 11:06     ` Adrien Nader
2014-09-08 14:49   ` Jesper Louis Andersen
2014-09-08 15:08     ` [Caml-list] format of .annot files Francois Berenger
2014-09-08 15:56     ` Anil Madhavapeddy [this message]
2014-09-08 17:32       ` [Caml-list] Multicore runtime Jesper Louis Andersen
2014-09-09  2:24         ` Yotam Barnoy
2014-09-09 15:06           ` Stephen Dolan
2014-09-09 15:26             ` Yotam Barnoy
2014-09-10 22:01               ` Stephen Dolan
2014-09-10 22:42                 ` Yotam Barnoy
2014-09-11  8:39                   ` Stephen Dolan
2014-09-11  8:53                     ` Malcolm Matalka
2014-09-11 13:42                       ` Yotam Barnoy
2014-09-12 10:42                       ` Stephen Dolan
  -- strict thread matches above, loose matches on Subject: below --
2014-05-29 23:04 Jiten Pathy
2014-06-05 17:01 ` Stephen Dolan

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=FE011996-4EF9-4C37-B43C-B4E2C226A678@recoil.org \
    --to=anil@recoil.org \
    --cc=caml-list@inria.fr \
    --cc=jesper.louis.andersen@gmail.com \
    --cc=jpathy@fssrv.net \
    --cc=stephen.dolan@cl.cam.ac.uk \
    /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).