caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Michael Ekstrand <michael+ocaml@elehack.net>
To: caml-list@inria.fr
Subject: OCaml runtime lock does not seem pathological
Date: Mon, 29 Jun 2009 12:08:17 -0500	[thread overview]
Message-ID: <874otz0xz2.fsf@jehiel.elehack.net> (raw)

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

Late last week, a presentation demonstrating substantial scaling
problems with Python's global interpreter lock[1] got a bit of buzz.  I
was interested to see whether OCaml's runtime suffered from a similar
problem, given that it too forbids multiple threads from concurrently
accessing the runtime.

The basic problem outlined is that Python's GIL implementation causes
substantial lock contention, particularly on multicore machines, which
causes computational threads to thrash against each other and can cause
computational threads to keep I/O threads from running.  This latter
problem can result in an obscure priority inversion.

The basic test which demonstrated this problem was a simple loop
counting down from 100000000.  On Python, if two such loops are run in
parallel using threads on a multicore machine, the program takes
substantially longer to finish if the loops are run sequentially.
Disabling one core speeds the program up, but it doesn't recover all of
its original speed.

I duplicated this test with the following code:

let rec count n =
    if n <= 0 then ()
    else count (pred n)
;;

(* count 100000000;; *)
(* count 100000000;; *)

let t1 = Thread.create count 100000000;;
let t2 = Thread.create count 100000000;;
Thread.join t1;;
Thread.join t2;;

Running sequentially on my 1.8 GHz Core 2 Duo laptop (Debian, AMD64)
takes 3.38s user time in byte code and 0.28s user time in native code.
Running threaded with both cores enabled takes the same time.  Running
threaded with the second core disabled also takes about the same time
(byte code is slightly slower).

The take-away from this is that while global locks can cause obscure
performance problems, a very simplistic test suggests that OCaml's
implementation avoids such problems and threaded solutions do scale (as
well as any non-multicore-compatible solution can).  I do not know how
the locking for the OCaml runtime is done, so I do not know if there are
deeper problems of this nature which more sophisticated testing would
reveal.

- Michael

1. http://blip.tv/file/2232410

-- 
mouse, n: A device for pointing at the xterm in which you want to type.
Confused by the strange files?  I cryptographically sign my messages.
For more information see <http://www.elehack.net/resources/gpg>.

[-- Attachment #2: Type: application/pgp-signature, Size: 196 bytes --]

             reply	other threads:[~2009-06-29 17:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-29 17:08 Michael Ekstrand [this message]
2009-06-30  1:31 ` Michael Ekstrand

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=874otz0xz2.fsf@jehiel.elehack.net \
    --to=michael+ocaml@elehack.net \
    --cc=caml-list@inria.fr \
    /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).