Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
yome committed Jun 18, 2008
0 parents commit 4cec1d6
Show file tree
Hide file tree
Showing 51 changed files with 4,054 additions and 0 deletions.
48 changes: 48 additions & 0 deletions termite/CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
========================================================================
Mon Jun 16 00:22:38 2008

- Clean up code, remove experimental nameserver stuff as it is not
really needed

========================================================================
Thu Mar 13 00:39:57 2008

- Cleaned up initialization, so that no set! would be used
- A node will now properly report an error in the primordial thread
if the tcp port is already used


========================================================================
Tue Mar 11 01:01:29 2008

- Fixed a problem with MATCH macro
- TAGS are now unique objects and only get an UUID assigned if
"exported" (ie sent to another node) to avoid the creation of symbols
that will not be garbage collected (bug reported by Nicholas Walton)


========================================================================
Wed Feb 13 22:21:59 2008

- Removed useless code from match.scm that was impeding compilation
(reported by Guillaume Cartier)
- Termite is now licensed under the same term as Gambit is, as it will
simplify inter-operation with Gambit's code

========================================================================

Wed Feb 6 19:45:59 2008
Version 0.11

- Updated export list
- Minor code cleanup

========================================================================

Thu Nov 15 01:02:19 2007
Version 0.10

- Changed the format of Termite from an "included in Gambit" format to
a Gambit library format

========================================================================
18 changes: 18 additions & 0 deletions termite/INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# These are the installation instructions for Termite

#1 Install the latest Gambit-C

#2 Get Termite and untar it in Gambit's lib/ directory

cd /usr/lobal/Gambit-C/current/lib

wget http://toute.ca/termite.tar.gz
tar -xzvf termite.tar.gz

# Optional:
# Manually copy the "tsi" file from Termite's directory to
# Gambit's "bin" directory
# That's for convenience so you can start a console that acts
# like gsi but has Termite already loaded

# All done!
718 changes: 718 additions & 0 deletions termite/LICENSE

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions termite/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
Termite is Copyright 2005-2008 by Guillaume Germain
(guillaume.germain@gmail.com), All Rights Reserved.

Termite is released under the same license as Gambit itself,
see the LICENSE file.

* See the 'INSTALL' file for installation instructions. *

The current code should be considered as beta quality. That is,
some of it isn't yet implemented using a very good style, might
contains some bug, will probably change in the near future, and the
interaction with Gambit might be a little 'rough' for now.

Don't hesitate to bug me (guillaume.germain@gmail.com) if something
doesn't work as it should, if you have questions or if you have
feature requests.

--------------------------------------------------------

Here is some incomplete documentation about the system.


Some Notes
----------

See "examples/start1.sh" for a minimal Termite program.

The global environment should be the same on every node, because it
isn't included in the serialization of ojects.

One should avoid to make references to unserializable objects in
closures and continuations, else things will fail.

The programs should not use mutations. Instead, rely on the fact that
passing messages around /is/ a representation of mutable state. See
"examples/cons.scm" for an example. Still, mutable data structures
can be hidden behind processes with some care. Have a look at
'data.scm' for examples.

To stay in the "spirit" of Termite, one should not use SET!, SET-CAR!,
SET-CDR!, VECTOR-SET!, STRING-SET! and similar functions. Better
integration in the future with Gambit might prevent those forms and
functions from being available.


Datatypes:
---------

NODE -> node ID
(make-node ip-address tcp-port#)

TAG -> universally unique identifier
(make-tag)


Functions and special forms:
---------------------------

(node-init node)

Necessary to initialize the system.

(spawn thunk)

Start a new process executing the 'body' code and return its PID.


(spawn-link thunk)

Start a new process executing the 'body' code and linking that process
to the current one and return its PID.


(remote-spawn node thunk)

Spawn a new thunk on a remote node and return its PID.


(self)

Get the PID of the running process.


(current-node)

Get the current node we're executing on.


(! pid message)
Send message to process.


(? [timeout [default-value]])

Receive a message, block for 'timeout' seconds if no messages. An
exception will be raised if no default-value is specified.


(?? pred? [timeout [default-value]])
Receive a message for which (pred? message) is true.


(recv
(pattern . code)
(pattern (where clause) . code)
(after seconds . code))

Selectively receive a message that match a pattern, and destructure
it. The last clause can optionally be a 'timeout' clause, with code
to execute if no messages received after a certain amount of time.


(!? pid message [timeout [default-value]])

Remote procedure call (or synchronous message). This requires
doing something like:

(recv
...
((from token message) (! from (list token reply)))
...)


(shutdown!)

Nicely terminate the execution of the current process.


(terminate! pid)

Forcefully terminate the execution of a local process.
1 change: 1 addition & 0 deletions termite/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.13
5 changes: 5 additions & 0 deletions termite/benchmarks/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The files in this folder are the implementations for the benchmarks
that were used in the Termite paper (http://toute.ca/termite.pdf).

They were run automatically by a Perl script that I'm too ashamed of
to include here.
6 changes: 6 additions & 0 deletions termite/benchmarks/bench.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(define-macro (time* . code)
(let ((t0 (gensym)))
`(let ((,t0 (time->seconds (current-time))))
(begin ,@code)
(inexact->exact
(round (* 1000 (- (time->seconds (current-time)) ,t0)))))))
2 changes: 2 additions & 0 deletions termite/benchmarks/config-dinos.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(define node1 (make-node "dino11" 3000))
(define node2 (make-node "dino12" 3001))
2 changes: 2 additions & 0 deletions termite/benchmarks/config-single-node.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(define node1 (make-node "127.0.0.1" 3000))
(define node2 (make-node "127.0.0.1" 3000))
2 changes: 2 additions & 0 deletions termite/benchmarks/config.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(define node1 (make-node "127.0.0.1" 3000))
(define node2 (make-node "127.0.0.1" 3001))
14 changes: 14 additions & 0 deletions termite/benchmarks/fib.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-module(fib).

-export([run/1, fib/1]).


fib(X) when X < 2 -> X;
fib(X) ->
fib(X-1)+fib(X-2).

run([Arg]) ->
N = list_to_integer(Arg),
{Time, _} = timer:tc(fib,fib,[N]),
io:format("(fib erlang ~w ~w)~n", [N, round(Time / 1000)]),
halt(0).
14 changes: 14 additions & 0 deletions termite/benchmarks/fib.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/local/Gambit-C/bin/gsi -:dar1

(include "bench.scm")

(define (fib n)
(if (< n 2)
n
(+ (fib (- n 1))
(fib (- n 2)))))

(define (main n)
(let ((n (string->number n)))
(write `(fib termite ,n ,(time* (fib n))))
(newline)))
34 changes: 34 additions & 0 deletions termite/benchmarks/migrate.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(declare (block))

(include "bench.scm")

(define (run n)
(let ((this (self)))
(spawn
(lambda ()
(let loop ((n n))
(if (> n 0)
(begin
(if (even? n)
(migrate-task node2)
(migrate-task node1)))
(begin
(! this 'done)
(shutdown!)))
(loop (- n 1))))))
(?))

(define (main n)
(cond
((equal? (current-node) node1)
;; code for node 1
(write `(migrate
termite
,n
,(time* (run n))))
(newline)
(remote-spawn node2 (lambda () (exit)))
(? 1 'done))

;; code for node2
(else (?))))
27 changes: 27 additions & 0 deletions termite/benchmarks/nrev.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-module(nrev).

-export([run/1, nrev/1, iota/1]).


iota(X) ->
iota (X-1, []).

iota(0, L) ->
[0|L];

iota(X, L) ->
iota(X-1, [X|L]).

nrev([]) ->
[];

nrev([A|B]) ->
nrev(B) ++ [A].


run([Arg]) ->
N = list_to_integer(Arg),
L = iota(N),
{Time, _} = timer:tc(nrev,nrev,[L]),
io:format("(nrev erlang ~w ~w)~n", [N, round(Time / 1000)]),
halt(0).
23 changes: 23 additions & 0 deletions termite/benchmarks/nrev.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/local/Gambit-C/bin/gsi -:dar1

(include "bench.scm")

(define (iota n)
(define (i n acc)
(if (= n 0)
acc
(i (- n 1)
(cons n acc))))
(i n '()))

(define (nrev lst)
(if (null? lst)
lst
(append (nrev (cdr lst))
(list (car lst)))))

(define (main n)
(let* ((n (string->number n))
(lst (iota n)))
(write `(nrev termite ,n ,(time* (nrev lst))))
(newline)))
43 changes: 43 additions & 0 deletions termite/benchmarks/pingpong.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-module(pingpong).

-export([run/1, bench/3, pingpong_player/1, iota/1]).


iota(0) -> [];
iota(N) -> [N] ++ iota(N - 1).

pingpong_player(N) ->
receive
{From, done} ->
From ! N,
exit(normal);
{From, Ball} ->
From ! {self(), Ball}
end,
pingpong_player(N + 1).

bench(Duration, Len, Remote) ->
Player1 = spawn(pingpong, pingpong_player, [0]),
Player2 = spawn(Remote, pingpong, pingpong_player, [1]),
Player1 ! {Player2, iota(Len)},
receive
after Duration -> ok
end,
Player1 ! {self(), done},
Player2 ! {self(), done},
receive
X ->
io:format("(pingpong erlang ~w ~w)~n",
[Len, round(X / (Duration / 1000))])
end.

run([Len, Node]) ->
Remote = case Node of
"remote" ->
receive X -> X end;
_ -> list_to_atom(Node)
end,
Duration = 5000,
bench(Duration, list_to_integer(Len), Remote),
spawn(Remote, erlang, halt, [0]),
halt(0).
Loading

0 comments on commit 4cec1d6

Please sign in to comment.