Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit 4cec1d607ff8477599b403c203273196a4d23797 @yome yome committed Jun 18, 2008
Showing with 4,054 additions and 0 deletions.
  1. +48 −0 termite/CHANGELOG
  2. +18 −0 termite/INSTALL
  3. +718 −0 termite/LICENSE
  4. +131 −0 termite/README
  5. +1 −0 termite/VERSION
  6. +5 −0 termite/benchmarks/README
  7. +6 −0 termite/benchmarks/bench.scm
  8. +2 −0 termite/benchmarks/config-dinos.scm
  9. +2 −0 termite/benchmarks/config-single-node.scm
  10. +2 −0 termite/benchmarks/config.scm
  11. +14 −0 termite/benchmarks/fib.erl
  12. +14 −0 termite/benchmarks/fib.scm
  13. +34 −0 termite/benchmarks/migrate.scm
  14. +27 −0 termite/benchmarks/nrev.erl
  15. +23 −0 termite/benchmarks/nrev.scm
  16. +43 −0 termite/benchmarks/pingpong.erl
  17. +51 −0 termite/benchmarks/pingpong.scm
  18. +16 −0 termite/benchmarks/pingpong2.scm
  19. +37 −0 termite/benchmarks/pingpong_gambit.scm
  20. +41 −0 termite/benchmarks/qsort.erl
  21. +49 −0 termite/benchmarks/qsort.scm
  22. +32 −0 termite/benchmarks/ring.erl
  23. +35 −0 termite/benchmarks/ring.scm
  24. +34 −0 termite/benchmarks/ring_gambit.scm
  25. +16 −0 termite/benchmarks/self.erl
  26. +19 −0 termite/benchmarks/self.scm
  27. +17 −0 termite/benchmarks/self_gambit.scm
  28. +162 −0 termite/benchmarks/smith.erl
  29. +103 −0 termite/benchmarks/smith.scm
  30. +17 −0 termite/benchmarks/spawn.erl
  31. +18 −0 termite/benchmarks/spawn.scm
  32. +16 −0 termite/benchmarks/spawn_gambit.scm
  33. +17 −0 termite/benchmarks/tak.erl
  34. +17 −0 termite/benchmarks/tak.scm
  35. +199 −0 termite/data.scm
  36. +93 −0 termite/deftype.scm
  37. +28 −0 termite/examples/cell.scm
  38. +6 −0 termite/examples/config.scm
  39. +56 −0 termite/examples/cons.scm
  40. +117 −0 termite/examples/supervisor.scm
  41. +415 −0 termite/match-support.scm
  42. +25 −0 termite/match.scm
  43. +106 −0 termite/otp/gen_event.scm
  44. +79 −0 termite/otp/gen_server.scm
  45. +57 −0 termite/recv.scm
  46. +87 −0 termite/termite#.scm
  47. +925 −0 termite/termite.scm
  48. +12 −0 termite/test/test_node1.scm
  49. +1 −0 termite/test/test_node2.scm
  50. +3 −0 termite/tsi
  51. +60 −0 termite/uuid.scm
@@ -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
+
+========================================================================
@@ -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!
Oops, something went wrong.
@@ -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.
@@ -0,0 +1 @@
+0.13
@@ -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.
@@ -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)))))))
@@ -0,0 +1,2 @@
+(define node1 (make-node "dino11" 3000))
+(define node2 (make-node "dino12" 3001))
@@ -0,0 +1,2 @@
+(define node1 (make-node "127.0.0.1" 3000))
+(define node2 (make-node "127.0.0.1" 3000))
@@ -0,0 +1,2 @@
+(define node1 (make-node "127.0.0.1" 3000))
+(define node2 (make-node "127.0.0.1" 3001))
@@ -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).
@@ -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)))
@@ -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 (?))))
@@ -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).
@@ -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)))
@@ -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).
Oops, something went wrong.

0 comments on commit 4cec1d6

Please sign in to comment.