caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* mixing Ocaml with another GC-ed language
@ 2000-02-25 13:37 STARYNKEVITCH Basile
  2000-02-29 10:24 ` Xavier Leroy
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: STARYNKEVITCH Basile @ 2000-02-25 13:37 UTC (permalink / raw)
  To: caml-list

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 1672 bytes --]

Hello All,

In a few weeks I will perhaps code in Ocaml inside a static code
analyzer tool written in C++ (don't ask me why.. it is a painful
subject [see the thread "convincing management to code in Ocaml" on
this same mailing list, that I started last year]).

It is not really plain C++ because I did code a (precise, mostly
copying, generational) garbage collector which is used in the
project. So Ocaml code will be called from (and will probably upcall
to) C++ code using my GC. So I do know my GC quite well (and studied
Ocaml's GC a bit also). My GC also support finalized objects, which it
does not move (so their address remain fixed).

Does any people have concrete experience mixing Ocaml with another
GC-ed language (e.g. Java or Common Lisp) inside the same program?

I do have my precise ideas on the problem (essentially, avoid mixing
pointers from both worlds, either by copying data or by using my
finalized C++ GCed objects which are not moved by my GC). But I will
be happy to hear from other people's experience. Any pitfalls to avoid
are interesting to hear.

The custom tag object (introduced in Ocaml3, see the Ocaml CVS
webserver) might also be helpful.

Regards

N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

---------------------------------------------------------------------
Basile STARYNKEVITCH   ----  Commissariat à l Energie Atomique 
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France
phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
email: Basile point Starynkevitch at cea point fr 



^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: Interpreter vs hardware threads
@ 2000-03-02 17:25 David Gurr
  0 siblings, 0 replies; 23+ messages in thread
From: David Gurr @ 2000-03-02 17:25 UTC (permalink / raw)
  To: williamc, caml-list, Xavier.Leroy

> >    (Of course, one could always ask the ocaml team that won the ICFP
> > competition in such spectacular fashion to knock off an
> > ocaml-to-event-driven-FSM compiler ...)
> 
> I'm not sure that OCaml is the best input language for generating
> FSMs, but, yes, generating FSMs from a high-level concurrent language
> is an excellent approach.  You get both ultimate execution speed and a
> readable, maintainable description of the program.  Have a look for
> instance at Esterel (another glorious INRIA product :-))
> 
> - Xavier Leroy
> 
And Lucid-Synchronie?  Any thoughts on JoCaml with Cilk-like threads?



^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Interpreter vs hardware threads
@ 2000-03-03  9:10 Edwin Young
  2000-03-06 13:42 ` William Chesters
  0 siblings, 1 reply; 23+ messages in thread
From: Edwin Young @ 2000-03-03  9:10 UTC (permalink / raw)
  To: 'caml-list@pauillac.inria.fr'

From: William Chesters [mailto:williamc@paneris.org]
> Judging by Max's .sig he's doing embedded telecoms boxes,
> something like a GSM HLR which juggles many thousands of concurrent
> transactions in some ghastly protocol or other.

If that's the case, perhaps he should investigate Erlang. Since it was
designed by Ericsson specifically for embedded telephony apps, it would seem
an ideal fit. It does indeed support thousands of concurrent threads
(internal to the interpreter rather than OS-based).

Regards,

--
Edwin Young



^ permalink raw reply	[flat|nested] 23+ messages in thread
* Re: Interpreter vs hardware threads
@ 2000-03-03 12:12 Juergen Pfitzenmaier
  0 siblings, 0 replies; 23+ messages in thread
From: Juergen Pfitzenmaier @ 2000-03-03 12:12 UTC (permalink / raw)
  To: caml-list

If William Chester is right with his guessing and Max Skaller wants
to use threads in ocamnl to handle thousands of concurrent phone calls,
then I would really go for hardware threads *with* ocaml. I would think
about how to translate (a subset of) ocaml into vhdl and put my program
into a fpga. I thought about such things some time ago and consider it
possible within reasonable time.

pfitzen



^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Interpreter vs hardware threads
@ 2000-03-07  8:30 Simon Peyton-Jones
  2000-03-08 20:02 ` Xavier Leroy
  0 siblings, 1 reply; 23+ messages in thread
From: Simon Peyton-Jones @ 2000-03-07  8:30 UTC (permalink / raw)
  To: 'Xavier Leroy', caml-redistribution; +Cc: Norman Ramsey (E-mail)


| The sad fact is that there doesn't exist any implementation technique
| for threads that satisfy both viewpoints at once.  Very lightweight
| threads do exist, see e.g. the call/cc-based threads of SML/NJ, but
| entail significant performance penalties not only on I/O, but also on
| the actual running speed of the sequential code.  "Heavyweight"
| threads such as LinuxThreads or Win32 threads are very efficient
| w.r.t. I/O, but are expensive to start and to context-switch.

Is that really so, Xavier?  What percentage performance penalty do
you think is involved?  1%?  10%?  Factor of 2?

Very-lightweight threads typically have to do
a stack-overflow check at the start of each function, but apart from the
I don't see that they are necessarily less efficient than heavyweight
threads.
For potentially-blocking I/O operations it is true that there is
some extra work to do, much like a context switch.  The pointers need
to be saved in a safe place in case GC strikes, and a global lock should
be released so that a new heavyweight thread can take over the business
of running the lightweight threads if the I/O blocks.  But none of
this seems really expensive in terms of % of computation time, does it?

Concurrent Haskell takes the very-lightweight approach.  Stacks are
allocated in the heap and can grow arbitrarily.  A thread that is
blocked on a channel that is not reachable is garbage collected
(something that came up earlier in this conversation).

But I agree that there are compromises.  Notably, a call to a
C procedure that cannot block nor cause GC can be done more 
efficiently, so there's some incentive to have two kinds of
call, which is really a pain.  But the biggest compromise is that
it's hard to do preemption on very lightweight threads, esp if you
want to support accurate GC too.

Beyond Concurrent Haskell, I'm working on a specification for
very-lightweight
style concurrency in C--.  The idea is this: what is the primitive
support required from the C-- runtime that lets you implement lightweight
concurrency. You provide the scheduler, synchronisation, etc etc; C-- only
provides the stuff that lets you run and suspend a computation.
If anyone is interested, a working draft is at
	http://research.microsoft.com/~simonpj/tmp/c--concurrency.ps.gz
I'd be delighted to get feedback.

Simon




^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Interpreter vs hardware threads
@ 2000-03-07  9:06 Simon Peyton-Jones
  0 siblings, 0 replies; 23+ messages in thread
From: Simon Peyton-Jones @ 2000-03-07  9:06 UTC (permalink / raw)
  To: 'STARYNKEVITCH Basile'; +Cc: caml-redistribution

|     Simon> If anyone is interested, a working draft is at
|     Simon> http://research.microsoft.com/~simonpj/tmp/c--concurrency.ps.gz
|     Simon> I'd be delighted to get feedback.
| 
| I'm getting 
| 
| Error - File Not Found

That's strange.  I got that for a while too, but it seems to work now.
This one works too:

	http://research.microsoft.com/~simonpj/tmp/c--conc.ps.gz

Simon



^ permalink raw reply	[flat|nested] 23+ messages in thread
* RE: Interpreter vs hardware threads
@ 2000-03-10 18:01 Manuel Fahndrich
  0 siblings, 0 replies; 23+ messages in thread
From: Manuel Fahndrich @ 2000-03-10 18:01 UTC (permalink / raw)
  To: 'Xavier Leroy', 'caml-list@inria.fr'
  Cc: Norman Ramsey (E-mail)


The advantage of heap closures in SML/NJ for efficient thread creation is
only present when the threads are super lightweight, that is completely
handled by the SML/NJ system via callcc/throw. If we want the threads to be
scheduled by the OS, because e.g. we are running on multi-processor
machines, or we don't want to block on IO, then each thread again needs some
C stack for the OS interaction, which destroys the heap closure advantage.

What we really need is an OS w/o a stack.

-Manuel


-----Original Message-----
From: Xavier Leroy [mailto:Xavier.Leroy@inria.fr]
Sent: Friday, March 10, 2000 12:00 AM
To: caml-redistribution@pauillac.inria.fr
Cc: Norman Ramsey (E-mail)
Subject: Re: Interpreter vs hardware threads


> | Very lightweight
> | threads do exist, see e.g. the call/cc-based threads of SML/NJ, but
> | entail significant performance penalties not only on I/O, but also on
> | the actual running speed of the sequential code.
> Is that really so, Xavier?  What percentage performance penalty do
> you think is involved?  1%?  10%?  Factor of 2?

For SML/NJ, I think their stackless execution model (all activation
records beging heap-allocated) entail a significant speed penalty for
sequential code -- at least 20%, I'd say.  But it sure gives you
blazingly fast thread creation.

The Concurrent Haskell approach that you describe is somehow less
lightweight than the SML/NJ approach.  In particular, thread creation
is going to be more expensive because of the cost of allocating and
setting up a new stack.  Also, the memory consumption of each thread
is going to be higher.  I guess the SML/NJ approach could accommodate
one million threads, while Concurrent Haskell sounds more in the 100 000s.
Still, I agree the solution you outline is pretty lightweight.

The expression "lightweight threads" is getting too vague.  I guess we
need several degrees of lightweightness, from SML/NJ's "ultra-lightweight
threads" to POSIX's "not so lightweight threads", with Haskell's
"pretty lightweight" threads and Caml's "lightweight, but no more"
threads...

> For potentially-blocking I/O operations it is true that there is
> some extra work to do, much like a context switch.  The pointers need
> to be saved in a safe place in case GC strikes, and a global lock should
> be released so that a new heavyweight thread can take over the business
> of running the lightweight threads if the I/O blocks.  But none of
> this seems really expensive in terms of % of computation time, does it?

You have to add to this the overhead on the I/O operation itself.  If
your threads build upon heavyweight threads for I/O, that should be
negligible.  (Say, one or two extra kernel context switches.)  But if
you have to perform I/O polling via select() (like OCaml bytecode
threads do for maximal portability), the overhead becomes significant.
(select() is one of the most expensive Unix system calls, in
particular because the kernel has to scan a huge set of file
descriptors just to determine which ones to wait upon; it's so bad
that Unix 98 introduced an alternate form, poll(), that does exactly
the same thing but with a more compact description of the f.d. sets.)

- Xavier Leroy



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2000-03-24 15:45 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-25 13:37 mixing Ocaml with another GC-ed language STARYNKEVITCH Basile
2000-02-29 10:24 ` Xavier Leroy
2000-03-01  3:48 ` Nice feature Max Skaller
2000-03-01  3:52 ` Interpreter vs hardware threads Max Skaller
2000-03-01 18:55   ` Michael Hicks
2000-03-01 20:02   ` Stefan Monnier
2000-03-02 18:18     ` William Chesters
2000-03-03 16:59       ` John Max Skaller
2000-03-06 17:35       ` Xavier Leroy
2000-03-06 23:11         ` John Max Skaller
2000-03-07 13:19         ` Julian Assange
2000-03-08 20:12           ` Xavier Leroy
2000-03-19  6:10             ` Julian Assange
2000-03-08 23:30           ` Max Skaller
2000-03-02 17:25 David Gurr
2000-03-03  9:10 Edwin Young
2000-03-06 13:42 ` William Chesters
2000-03-03 12:12 Juergen Pfitzenmaier
2000-03-07  8:30 Simon Peyton-Jones
2000-03-08 20:02 ` Xavier Leroy
2000-03-12  1:45   ` Julian Assange
2000-03-07  9:06 Simon Peyton-Jones
2000-03-10 18:01 Manuel Fahndrich

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).