Re: How do you do this?



Jeff Fox wrote:
I am sure that different people do this simple thing
in different ways. I would be interested in how you do
it in your Forth product.

SwiftForth, VFX, gForth, bigForth, iForth, tforth, win32Forth,
aforth, eforth, notforth, thisforth, thatforth (maybe not newforth)
etc. can all talk to other computers on a network and
those other computers could also be running the
same Forth so that they can run programs in parallel.
Some already have facilites to do this and to
exchange messages and use semiphores, mutexs,
and channels. Some can just click on an html
link for instance and pull a document into the editor
from a remote location.


ANS Forth is too powerful to execute from an untrusted source without
either user impersonation or some form of sandbox. Win32Forth provides
neither, nor does it communicate with other instances of Win32Forth
"out of the box". The editor does some limited communication with a
running process, but it is primitive and not particualrly satisfactory.


It is clearly completely trivial to have the programs
all pre-compiled and pre-loaded as part of the Forth
systems dictionaries so that one only has to send
a short message to a node to tell it to run any
Forth code already in the dictionary. And using
the network to load and launch a Forth should be easy.
And one could send Forth source code as a message and
get a system to evaluate it when there is a complete Forth
system on the end node.

Security is a big issue here. I know of no Forth equivalent of
JavaScript.


My question is how would you deal with problem of
sending a program to a node that is not already on that
node and getting it to execute. As an example lets take a very
trivial Forth code example:

: DEMO ( n1 n2 -- n1 n2+n1 n2+n1 )
over + dup ;

Compile that code and produce a binary image
that is appropriate for the target Forth node that gets
it as a message. Then encapsulate it in some
way to make it suitable for transmission to
the other node, send it and have the other end
run it.

The other node should be in a low power or
sleep mode if possible. When it gets the message
it should get an interrupt or use some mechanism
to come out of low power sleep and process the
incoming message. The message should then
be executed and the worker processor should then
go back into low power mode and wait for the
next message.

Now I imagine that some optimziing compilers
complicate the problem, but basically it is a pretty
simple problem.

One could tokenize the definition of DEMO and
get its word count and make a list with a count
that would include ' over ' + ' dup ' exit
and the worker system could get the count
and read and execute each Forth word.
Then it whould send an ack back to the source
of the message and wait for another message.

But of course that would defeat some optimizers.

So one could also compile the code with optimization
and then count the code then send a counted binary
sequence in the message and have it get loaded and
executed by the worker system. This would let one take
advantage of their compiler optimization.

Do you think this is a simple problem or a hard problem?

Hard. But for different reasons; see below.


How would you or do you do this in your system?

How much code will or does it take?
What are the code components and thier sizes?


Are you asking the question about implementation on shared nothing
federated type systems, or tightly coupled shared something systems? Or
Transputer-type CPU to CPU interconnects? Function shipping and its
efficency would be very different depending on the architecture
employed.

You mention networks, so assuming a shared nothing and that we pass
"code" (either binary or source for compilation), a simple scheme would
be to pass some key (such as the SHA-1 of the code we wish to execute),
and have the receiving platform either execute some previously compiled
token with the same SHA, or request the code if it doesn't have it in
its cache/dictionary. That would reduce the transmission and compile
time on later executions. It also allows an optimiser at the receiving
end to make local decisions as whether to optimise or not, based on
execution frequency, availability of compile resources etc. Function
coalescing (streaming multiple functions into a single request) and
function cascading (passing of functions elsewhere if the selected
processor doesn't have the resources) may be beneficial to throughput.

How long does it take from the time that you begin
loading the message on one end until the worker
processor has completed the process and is
waiting for next command? (give units not just a number)

Basically, there are too many questions about your question to answer
it in the detail you wish; you need to tighten the specification of the
problem.

In a blocking function on shared nothing, the network transmission time
will dominate on short running functions; it's a well known phenomenon
in loosely coupled systems, as is the problem of load balancing.

There's an old saying; all CPUs wait at the same speed. The statistics
you wish to compare are irrelevant. Your system may take 10us; mine may
take 20us. But I may be able to drive a single $100 processor at 100%,
while you struggle to drive 10 for $20 at 5%. This is a lot harder than
measuring the response time of a single blocking function.

Lastly; I'm guessing (sorry!) but has this anything to do with
Forthlets?

--
Regards
Alex McDonald

.



Relevant Pages

  • Re: How do you do this?
    ... I don't think that is what ANS says, but I will let you ANS folks ... I thought that Win32Forth supported serial and didn't care if it was ... be to pass some key (such as the SHA-1 of the code we wish to execute), ... availability of compile resources etc. ...
    (comp.lang.forth)
  • How do you do this?
    ... and read and execute each Forth word. ... So one could also compile the code with optimization ... executed by the worker system. ...
    (comp.lang.forth)
  • Re: Bytecode
    ... Bytecode systems have various advantages. ... but the compression has both ... And it's very simple to compile ... execution tokens and a lookup table, and then execute or compile. ...
    (comp.lang.forth)
  • Re: How do you do this?
    ... either user impersonation or some form of sandbox. ... I don't think that is what ANS says, but I will let you ANS folks ... arbitrary strings or code to execute. ... I thought that Win32Forth supported serial and didn't care if it was ...
    (comp.lang.forth)
  • Re: FORTH: BEGIN as compile-time and no run-time?!?!?!?!? Help
    ... BEGIN is executed at compile time to push on the stack an address ... > IMMEDIATE identifies words to be executed at compile time. ... > cases will either execute it or compile some reference to it depending on a ...
    (comp.lang.asm.x86)

Loading