Re: netmcore: becoming a worker after fork+exec ?

Gerd Stolpmann <[email protected]> Mon, 09 Sep 2013 13:27:29 +0200
Newsgroups gmane.comp.lang.ocaml.lib.net.devel
Message-ID <1378726049.10274.130.camel@zotac>
--===============7825024733052121905==
Content-Type: multipart/signed; micalg="pgp-sha1";
	protocol="application/pgp-signature"; 
	boundary="=-Gpa/P5K7WDKTSlX6GmQr"


--=-Gpa/P5K7WDKTSlX6GmQr
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Am Sonntag, den 08.09.2013, 17:46 -0400 schrieb Piotr Mardziel:
> Hello Gerd, thank you for the information!
>=20
> Would you say Netcamlbox are efficient modes (among the ocamlnet set of m=
odules, or plain old pipes) of communicating frequent but small blocks of d=
ata with a fork-exec'ed program? Seems like within the constraints of OSX; =
this process will be the only one capable of performing drawing operations =
(via SDL and OpenGL) and will thus be getting many, frequent but small comm=
unications from the workers.

This sounds like a good match. The efficiency of Netcamlbox and
Netmulticore should be about the same, because they both rely on the
same internal functions for value copying. If you compare Netcamlbox
with, say Netmcore_queue:

 - Netcamlbox has limited message size and limited number of slots.
   Netmcore_queue contents can be as large as data fit into the   =20
   underlying mempool.
 - Netcamlbox allows it that several senders fill the mail slots
   independently and in parallel. Netmcore_queue needs to get a
   common lock when a new value is added, so only one sender can
   do it at a time.
 - Netcamlbox is of course more restricted in functionality: it's
   only a message box, and you cannot add your own special data
   structures as in Netmulticore.

So, there are pros and cons. If there is an upper bound of the message
size, Netcamlbox will probably work better.

If you compare with Unix domain sockets serving datagrams, Netcamlbox
will probably win, because you don't have to convert your values to
string, but simply can put them as-is into the mailbox. This means
camlbox_send copies the value from the local memory of the sender
process to the shared mailbox, and on the receiver side you have the
choice between camlbox_get returning a pointer directly into the
mailbox, or the safer but slower camlbox_get_copy. So if camlbox_get is
an option, the value is only copied once, not twice.

Hope this helps,

Gerd

>=20
> Best,
> Piotr (Peter) Mardziel <[email protected]>
> http://www.cs.umd.edu/~piotrm
>=20
>=20
>=20
> On Sep 7, 2013, at 5:44 PM, Gerd Stolpmann <[email protected]> wrote=
:
>=20
> > Hi Piotr,
> >=20
> > I don't think this is even possible. The point is that fork() ensures
> > that master and worker have the mempool mapped at exactly the same
> > address (because the mapping is just inherited). If you exec in between=
,
> > the mempool is automatically unmapped in the child, and you would have
> > to map it again. But the process is re-initialized because of the exec,
> > and it is not sure that the address range is still free (and this is a
> > real problem, as processes are nowadays initialized with some randomnes=
s
> > to make addresses unpredictable), and so there is no good method to
> > re-map the mempool at the same address.
> >=20
> > So that's the background why there isn't the option of passing file
> > names or descriptors to Netmcore_mempool.
> >=20
> > I don't know what you have in mind, but maybe Netcamlbox is already
> > sufficient? This module doesn't suffer from this problem, because every
> > process can here map the shared memory block at different addresses.
> >=20
> > Gerd
> >=20
> >=20
> > Am Samstag, den 07.09.2013, 00:16 -0400 schrieb Piotr Mardziel:
> >> Hello ocamlnet developers,
> >>=20
> >> Is it possible to establish the master/worker relationship with a proc=
ess that has been fork+exec'ed (or Netsys_posix.spawn'ed) but is of the sam=
e executable as the process doing Netmcore.startup ?
> >>=20
> >> Let me explain. There is a problem on OSX in that forked child process=
es cannot access some OS functionality (for example SDL will not work on a =
forked child process). One has to exec in order to get this functionality b=
ack. I would like to be able to communicate with this process (of the same =
executable if need be) using the convenient netmcore modules but I don't se=
e a way for this process to get a handle on resources managed by the master=
 process. It seems like it is easy to get as far as the getting a handle to=
 the shared memory from which a Netmcore_mempool is created (by simply pass=
ing its name as a command argument to exec), but one cannot actually create=
 the resource suitable for interacting with the master and other workers, a=
s far as I can tell.
> >>=20
> >> Any info about this would be greatly appreciated.
> >>=20
> >> Best,
> >> Piotr (Peter) Mardziel <[email protected]>
> >> http://www.cs.umd.edu/~piotrm
> >>=20
> >>=20
> >>=20
> >>=20
> >> ----------------------------------------------------------------------=
--------
> >> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> >> Discover the easy way to master current and previous Microsoft technol=
ogies
> >> and advance your career. Get an incredible 1,500+ hours of step-by-ste=
p
> >> tutorial videos with LearnDevNow. Subscribe today and save!
> >> http://pubads.g.doubleclick.net/gampad/clk?id=3D58041391&iu=3D/4140/os=
tg.clktrk
> >> _______________________________________________
> >> Ocamlnet-devel mailing list
> >> [email protected]
> >> https://lists.sourceforge.net/lists/listinfo/ocamlnet-devel
> >>=20
> >=20
> > --=20
> > ------------------------------------------------------------
> > Gerd Stolpmann, Darmstadt, Germany    [email protected]
> > My OCaml site:          http://www.camlcity.org
> > Contact details:        http://www.camlcity.org/contact.html
> > Company homepage:       http://www.gerd-stolpmann.de
> > ------------------------------------------------------------
>=20
>=20

--=20
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    [email protected]
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

--=-Gpa/P5K7WDKTSlX6GmQr
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAABAgAGBQJSLbChAAoJEAaM4b9ZLB5ThrcH/09GJxM2j8uQopPh4HRf5Dkr
w+9dFC16DLcbDPKYzHV1Tg6uUKhwdur24aXHdjug8hJ1fvxNjUlsEtx2RoD57oIB
+7ds49CjsfgG7HIq4H/sdQXA6YUjqjRepIKTrvjMYnbCBTQETnmkNWU9koJZISiY
WBdwal2AqvXL5KicRHlTxVmP+cWJTGql6FMrmIEkSsM0Gx/tpVmLzK/Siz1fh3iT
Y4EemcjesZ01KS/AN6dWwHFk3Q7JjJBKyUQBtquUX0zd4TXHIsE7bBn9hCi0Aim8
VRVIoZ3upqvlggxUTqS038vhlBH0XbO4hABNpqZN46wGEAiP79oGUwEuTo6yU/A=
=v/Dw
-----END PGP SIGNATURE-----

--=-Gpa/P5K7WDKTSlX6GmQr--



--===============7825024733052121905==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
--===============7825024733052121905==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Ocamlnet-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ocamlnet-devel

--===============7825024733052121905==--