caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
To: Yotam Barnoy <yotambarnoy@gmail.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Question about Lwt/Async
Date: Mon, 7 Mar 2016 16:16:20 +0100	[thread overview]
Message-ID: <CAGrdgiWbxMNHzFX4sy85wZGHP=2r_EqU8AKdrXT09Sdk9VXapg@mail.gmail.com> (raw)
In-Reply-To: <CAN6ygO=ocZ9q_p75g=h1d+8zvqCQFPQW_AqM=2D5ZBvjAjQMmQ@mail.gmail.com>

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

On Mon, Mar 7, 2016 at 2:38 AM, Yotam Barnoy <yotambarnoy@gmail.com> wrote:

> Also, what happens to general utility functions that aren't rewritten for
> Async/Lwt -- as far as I can tell, being in non-monadic code, they will
> always starve other threads, since they cannot yield to another Async/Lwt
> thread. Is this perception correct?


Yes.

On one hand, your observation is negative in the sense that now your code
has "color" in the sense that it is written for one library only. And you
have to transform code to having the right color before it can be used.
This is not the case if the concurrency model is at a lower level[0].

On the other hand, your observation is positive: cooperative scheduling
makes the points in which the code can switch explicit. This gives the
programmer far more control over when you are done with a task and start to
process the next task. You can also avoid the preemption check in the code
all the time. If your code manipulates lots of shared data, it also
simplifies things since you don't usually have to protect data with a mutex
in a single-threaded context as much[1]. Cooperative models, if carefully
managed, can exploit structure in the problem domain, whereas a preemptive
model needs to fit all.

My personal opinion is that the preemptive model eventually wins over the
cooperative model, much like it has in most (all popular) operating
systems. It is simply more productive to take an up-front performance hit
as a sacrifice for a system which is more robust against stray code
misbehaving. If a cooperative system fails, it is fails catastrophically.
If a preemptive system fails, it degrades in performance.

But given I have more than 10 years of Erlang programming behind me by now,
I'm obviously biased toward certain computational models :)

[0] Erlang would be one such example, where the system is preemptively
scheduling for you and you can use any code in any place without having to
worry about blocking for latency. Go is quasi-preemptive because it checks
on function calls, but in contrast to Erlang a loop is not forced to factor
through a recursion, so it can in principle run indefinitely. Haskell (GHC)
is quasi-preemptive as well, checking on memory allocation boundaries. So
the thing to look out for in GHC is latency from processing large arrays
with no allocation, say.

[1] Erlang has two VM runtimes for this reason. One is single-threaded and
can avoid lots of locks which is far faster for certain workloads, or on
embedded devices with a single core only.

-- 
J.

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

  parent reply	other threads:[~2016-03-07 15:17 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07  1:38 Yotam Barnoy
2016-03-07  7:16 ` Malcolm Matalka
2016-03-07  9:08   ` Simon Cruanes
2016-03-07 14:06     ` Yotam Barnoy
2016-03-07 14:25       ` Ashish Agarwal
2016-03-07 14:55         ` rudi.grinberg
2016-03-07 14:59           ` Ivan Gotovchits
2016-03-07 15:05             ` Ivan Gotovchits
2016-03-08  6:55         ` Milan Stanojević
2016-03-08 10:54           ` Jeremie Dimino
2016-03-07 15:16 ` Jesper Louis Andersen [this message]
2016-03-07 17:03   ` Yaron Minsky
2016-03-07 18:16     ` Malcolm Matalka
2016-03-07 18:41       ` Yaron Minsky
2016-03-07 20:06         ` Malcolm Matalka
2016-03-07 21:54           ` Yotam Barnoy
2016-03-08  6:56             ` Malcolm Matalka
2016-03-08  7:46               ` Adrien Nader
2016-03-08 11:04               ` Jeremie Dimino
2016-03-08 12:47                 ` Yaron Minsky
2016-03-08 13:03                   ` Jeremie Dimino
2016-03-09  7:35                     ` Malcolm Matalka
2016-03-09 10:23                       ` Gerd Stolpmann
2016-03-09 14:37                         ` Malcolm Matalka
2016-03-09 17:27                           ` Gerd Stolpmann
2016-03-08  9:41     ` Francois Berenger
2016-03-11 13:21     ` François Bobot
2016-03-11 15:22       ` Yaron Minsky
2016-03-11 16:15         ` François Bobot
2016-03-11 17:49           ` Yaron Minsky
2016-03-08  5:59 ` Milan Stanojević

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='CAGrdgiWbxMNHzFX4sy85wZGHP=2r_EqU8AKdrXT09Sdk9VXapg@mail.gmail.com' \
    --to=jesper.louis.andersen@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=yotambarnoy@gmail.com \
    /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).