caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
To: Stephen Dolan <stephen.dolan@cl.cam.ac.uk>
Cc: Jiten Pathy <jpathy@fssrv.net>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Multicore runtime
Date: Mon, 8 Sep 2014 16:49:22 +0200	[thread overview]
Message-ID: <CAGrdgiUrF86W6ooyXCH3jYjX0aGCER8O7u1vqvBjojQDv=E3Kg@mail.gmail.com> (raw)
In-Reply-To: <CA+mHimMNNOvBLnRvU-aiYe87j2KLzyxVc5OrGVvPEf1MDV9XAg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1653 bytes --]

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.
>

This doesn't work for a (portable) implementation of File I/O which is why
everyone else (Go, Erlang, Haskell, ...) either has a pool of threads for
handling these (Erlang), or they just create another thread for handling
it, up to a point (Go). Network I/O is simple however, since you can batch
those on a standard epoll/kqueue/poll/select loop.

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).


-- 
J.

[-- Attachment #2: Type: text/html, Size: 2382 bytes --]

  parent reply	other threads:[~2014-09-08 14:49 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 [this message]
2014-09-08 15:08     ` [Caml-list] format of .annot files Francois Berenger
2014-09-08 15:56     ` [Caml-list] Multicore runtime Anil Madhavapeddy
2014-09-08 17:32       ` 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='CAGrdgiUrF86W6ooyXCH3jYjX0aGCER8O7u1vqvBjojQDv=E3Kg@mail.gmail.com' \
    --to=jesper.louis.andersen@gmail.com \
    --cc=caml-list@inria.fr \
    --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).