unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Marko Rauhamaa <marko@pacujo.net>
To: Linas Vepstas <linasvepstas@gmail.com>
Cc: "Guile User" <guile-user@gnu.org>, "Hans Åberg" <haberg-1@telia.com>
Subject: Re: GC thread performance
Date: Sat, 02 Dec 2017 10:50:29 +0200	[thread overview]
Message-ID: <87y3mltsx6.fsf@elektro.pacujo.net> (raw)
In-Reply-To: <CAHrUA376aefOXvkkx+J=NUd6unvctTB+vpj+4C1H14ndFn3hVw@mail.gmail.com> (Linas Vepstas's message of "Fri, 1 Dec 2017 13:49:35 -0600")

Linas Vepstas <linasvepstas@gmail.com>:
> I cannot speak to GC, but I freuqently encounter situations in guile
> where using the parallel constructs e.g. par-for-each, end up running
> slower than the single-threaded version. For example, using 2 or 3
> threads, I get a 2x and 3x speedup, great, but using 4x gives a
> slowdown, often 10x slower than single-threaded. I try to make sure
> that the insides of the loop are large and long-running, so that the
> cost of creating and scheduling threads is inconsequential.
>
> I have not attempted to determine the cause of this, but basically,
> that entire subsystem needs a careful review and measurement.

I'll have to speculate, too.

Guile guarantees the consistency of the data model under all
circumstances. Bad synchronization between threads is allowed to cause
unspecified behavior, but it should never trigger a SIGSEGV. In
practice, that means excessive locking: all data access needs to take
place in a critical section.

Linux (at least) has locking primitives that have virtually no overhead
when there is no contention. However, when there is contention, the
context is switched to the kernel and a memory barrier causes the CPU
hardware to flush its memory cache.

The same issue hampers C developers as well, although the newest C
standards explicitly shift to the coder the responsibility for the
consistency of the data model. Thus, in principle, a C programmer can
try clever tricks to eke out performance with multithreading.

CPython has famously grappled with the same performance issues. The
so-called GIL effectively turns every Python program into a
single-threaded process. The point of multithreading is not a gain in
performance. Rather, it is a programming paradigm to multiplex events.

These and other issues with multithreading have caused many of us to
reject multithreading as a paradigm altogether. Use event-driven
programming for multiplexing and multiprocessing for performance.


Marko



  parent reply	other threads:[~2017-12-02  8:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-27 22:40 GC thread performance Hans Åberg
2017-11-27 23:05 ` Stefan Israelsson Tampe
2017-11-27 23:13   ` Hans Åberg
2017-11-27 23:23     ` Marko Rauhamaa
2017-11-27 23:44       ` Hans Åberg
2017-12-01 19:49         ` Linas Vepstas
2017-12-01 23:23           ` Hans Åberg
2017-12-02  8:50           ` Marko Rauhamaa [this message]
2017-12-02 14:20             ` Hans Åberg
2017-12-03 22:15               ` Arne Babenhauserheide
2017-12-04  9:38                 ` Hans Åberg
2017-12-02 14:30             ` Chris Vine

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

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y3mltsx6.fsf@elektro.pacujo.net \
    --to=marko@pacujo.net \
    --cc=guile-user@gnu.org \
    --cc=haberg-1@telia.com \
    --cc=linasvepstas@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 read-only IMAP folder(s) and NNTP newsgroup(s).