caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: Stephan Houben <stephanh@planet.nl>
Cc: caml-list@yquem.inria.fr
Subject: Re: Threading and SharedMem (Re: [Caml-list] Re: Is OCaml fast?)
Date: Tue, 30 Nov 2010 17:07:31 +0100	[thread overview]
Message-ID: <1291133251.16005.604.camel@thinkpad> (raw)
In-Reply-To: <4CF518A6.9000602@planet.nl>

Am Dienstag, den 30.11.2010, 16:30 +0100 schrieb Stephan Houben:
> On 11/30/2010 02:22 PM, Gerd Stolpmann wrote:
> > I don't think this is the reason. Many people can ignore Windows,
> > actually.
> >
> > The problem is more that your whole program needs then to be
> > restructured - multi-processing implies a process model (which is the
> > master, which are the workers). With multi-threading you can start
> > threads at all times without having to worry about that (i.e. supports
> > "programming without design" if you want to take that as a negative
> > point).
> >
> > This is what I want to fix with my Netmulticore library - it defines a
> > framework allowing you to start new processes at any time without having
> > to worry about the process hierarchy.
> 
> I have in fact read with much interest your blog at
> http://blog.camlcity.org/blog/parallelmm.html .
> 
> Your approach there is to really have separate programs for
> server and client. However, one nice thing about fork is that you don't
> have to restructure your program; you can just call fork down somewhere
> in some subroutine where you decide it is convenient, start doing some
> multicore computation, finish and return, and the caller needs never know
> that you did that. So you can indeed program without design using fork.

Well, I would not recommend that in all cases: fork duplicates all
memory, and if this is a lot, you can end up consuming a lot of RAM.
Even worse, the GC of the forked subprocess has to manage all of the
RAM, including the part that is not required for doing the computation
in the subprocess (the copy-on-write optimization of the OS gets you
nothing here).

Also, there can be subtle interactions between the parent and the child,
e.g. file descriptors are inherited, affecting whether closed
descriptors can be recognized.

So, use with care, and not without design. Forking in the middle of a
bigger program can be quite disastrous.

> Of course, the advantage of your approach is that you can now distribute
> the work over multiple machines. So I guess there is an appropriate
> place for all of these techniques.

I was recently working on an improved fork machinery, with some
indirection between the request for creating a new worker process, and
the actual fork. That's this netmulticore library I'm talking about. The
new process is not a child of the process requesting the creation, but
always a child of a common master process. This avoids all the problems
(memory issues, file descriptor issues, and a few more), at the cost of
having to transmit state to the new process.

> > Also, many practical problems are only O(n log n), at most. The cost for
> > serialization of data through a pipe cannot be neglected here. This
> > makes shared memory attractive, even if it is only available in a
> > restricted form (like write once memory).
> 
> Well, the original context was one of a benchmark which had an
> arbitrary rule that you can only use functions from the bundled libraries.
> And my proposal was to use the pipe for synchronisation and the shared memory
> for bulk communication.
> 
> If we drop the arbitrary rule there are faster options than pipes.
> (e.g. POSIX semaphores in a shared memory segment).

Yes, it's really arbitrary. All remaining solutions are very restricted
then, and don't have much to do with what you would choose for solving a
real-world problem. This makes this benchmark irrelevant.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann, Bad Nauheimer Str.3, 64289 Darmstadt,Germany 
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
Phone: +49-6151-153855                  Fax: +49-6151-997714
------------------------------------------------------------


  reply	other threads:[~2010-11-30 16:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fa.eehhGhbses+7RvDlflKpXQ8Uu34@ifi.uio.no>
     [not found] ` <fa.UVXWB7NnPNJbhh0Cf2OLmzYx/bQ@ifi.uio.no>
     [not found]   ` <fa.uksiRZ6fYFia4X1fXQaWa8z4Kio@ifi.uio.no>
     [not found]     ` <fa.Zv2Wkh0+DJAuXcOzq+qABiYFTP4@ifi.uio.no>
     [not found]       ` <fa.W5DnVSXs073N1X2rbtpyh7iGAcc@ifi.uio.no>
     [not found]         ` <fa.LGfjfIGKcYLW6PBxy7aMsEnvy/w@ifi.uio.no>
2010-11-30 15:30           ` Stephan Houben
2010-11-30 16:07             ` Gerd Stolpmann [this message]
2010-11-30 17:40               ` oliver
     [not found] <fa.B9mcuN46iEGhXlge41VUCLz69+Y@ifi.uio.no>
     [not found] ` <fa.D3cDWzaD9Uu03+KvekpwpBGCx7o@ifi.uio.no>
     [not found]   ` <fa.xsCCCeDYPj8J16i9UrdqxoOIQ0Y@ifi.uio.no>
     [not found]     ` <fa.SW2Swldk88Bs5ujaNHT8Yh4bXkg@ifi.uio.no>
     [not found]       ` <fa.V+M6RbukE/w/Aftpwxkx2MvkxlU@ifi.uio.no>
     [not found]         ` <fa.+OkqNL3AB4+5LA8wOnQD9WS59QQ@ifi.uio.no>
2010-11-30 14:04           ` Stephan Houben
2010-11-30 14:22             ` Gerd Stolpmann
2010-11-30 14:29             ` oliver
2010-11-30 15:17               ` Eray Ozkural
     [not found] <fa.sn187DUeFX1sJ62LL4s6SatUR/c@ifi.uio.no>
     [not found] ` <fa.PTndTGw0Otg08P5/YMoxmRptrPs@ifi.uio.no>
     [not found]   ` <fa.0ulojaV8bXHHiRN+1r6S98RGEsw@ifi.uio.no>
     [not found]     ` <fa.gQ7B1GYcdbBVupZowIyW2+1E/b4@ifi.uio.no>
     [not found]       ` <fa.ludbTMBmN7YGqnEwsRPwOGCpjrA@ifi.uio.no>
     [not found]         ` <fa.srfZThtnO8lApSpMeW3POD462Xg@ifi.uio.no>
2010-11-30  8:10           ` Stephan Houben
2010-11-30 12:55             ` oliver
2010-11-30 13:06               ` Eray Ozkural
2010-11-30 21:13                 ` Jon Harrop
2010-11-30 21:28                   ` Christophe Raffalli
2010-11-30 14:09               ` Gerd Stolpmann
2010-11-22 17:08 [Caml-list] Is OCaml fast? David Rajchenbach-Teller
2010-11-23  2:01 ` Isaac Gouy
2010-11-23 23:27   ` [Caml-list] " oliver
2010-11-24  0:23     ` Isaac Gouy
2010-11-24  1:36       ` [Caml-list] " Eray Ozkural
2010-11-24  2:13         ` Isaac Gouy
2010-11-24  4:39           ` [Caml-list] " Jeff Meister
2010-11-25 16:59             ` Stefan Monnier
     [not found]               ` <1534555381.33107.1290723160355.JavaMail.root@zmbs4.inria.fr>
2010-11-25 22:50                 ` [Caml-list] " Fabrice Le Fessant
2010-11-28 18:14                   ` oliver
2010-11-29 14:19                     ` Gerd Stolpmann
2010-11-29 16:12                       ` Threading and SharedMem (Re: [Caml-list] Re: Is OCaml fast?) Oliver Bandel
2010-11-29 16:24                         ` Gerd Stolpmann
2010-11-29 16:33                           ` Oliver Bandel

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=1291133251.16005.604.camel@thinkpad \
    --to=info@gerd-stolpmann.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=stephanh@planet.nl \
    /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).