Skip to content
Alberto edited this page Oct 19, 2016 · 26 revisions

Transient is a general purpose library whose salient features are distributed processing and Web programming, where everithing is composable using standard haskell classes and operators (Applicative, Alternative, Monad).

People asked me for a complete distributed transient application example which may run network communications among different processes.

This is a runnable example at: https://ide.c9.io/agocorona/transienttest

It is a distributed program with N nodes (independen processes) that is accessed with a Web interface made of widgets using many of the primitives of the transient stack. It shows three different distributed applications: A map-reduce widget which count the words in a text, a federated chat server and a node monitor which display the nodes connected.

The source code of the example has less than 200 lines of code including browser interface!:

https://github.com/agocorona/transient-universe/blob/master/examples/distributedApps.hs

transientt

transientt2

It is necessary to sign in in Cloud9. Then, clone this project. Then you may be able to run your own copy within your own personal cloud9 instance.

In the bash console, execute three application nodes with init.sh:

agocorona:~/workspace $ cd transientinstaller
agocorona:~/workspace/transientinstaller (master) $ cat init.sh 
./distributedApps  -p start/localhost/8080 &
./distributedApps  -p start/localhost/8081/add/localhost/8080/y &
./distributedApps  -p start/localhost/8082/add/localhost/8080/y & 

agocorona:~/workspace/transientinstaller (master) $ ./init.sh

Executing: "start/localhost/8081/add/localhost/8080/y"
Executing: "start/localhost/8080"
Executing: "start/localhost/8082/add/localhost/8080/y"
.. more messages ...
Known nodes: 
[("localhost",8082,[]),("localhost",8080,[]),("localhost",8081,[])]

A cluster of three nodes will be started.

agocorona:~/workspace/transientinstaller (master) $ ps  | grep distrib
   3179 pts/1    00:00:00 distributedApps
   3180 pts/1    00:00:00 distributedApps
   3181 pts/1    00:00:00 distributedApps

Connect with the first node at port 8080 by pointing the browser to:

http://transienttest-youruser.c9users.io/

to enter in the second node: http://transienttest-youruser.c9users.io:8081

to enter in the third node: @http://transienttest-youruser.c9users.io:8082

All widgets execute in the cluster. This means that chat messages are propagated to all the nodes and you can chat across browsers connected to any of the nodes. and map-reduce requests initiated in one of the nodes are executed in the three nodes. The node list is updated when a node is added or deleted.

To know what each element of the program does, the best option is to take a look at the tutorial. There are a lot of unconventional things going there in order to preserve composability, so be patient. This is not simple to understand, but it is simple to use. I will expand the documentation as soon as I can.

Warning: This example is at the limit of the capacity of the free cloud9 instance. Please do not send big queries to map-reduce. this will shut down the conections and will be no response. kill the processes and restart them again with init.hs

if you want to compile it in your machine:

  > stack install ghcjs-hplay  --compiler ghcjs-0.2.0.9006020_ghc-7.10.3
  > stack install ghcjs-hplay
  > mkdir static
  > ghcjs -o static/out distributedApps.hs
  > ghc distributedApps.hs

to run nodes, use init.hs as example. It run three nodes and connect them:

> cat init.hs
./distributedApps  -p start/localhost/8080 &
./distributedApps  -p start/localhost/8081/add/localhost/8080/y &
./distributedApps  -p start/localhost/8082/add/localhost/8080/y & 

There are ephemeral instances running now at: http://transienttest-agocorona.c9users.io for 24h aprox from this notice to play with them if you don't want to clone and run your own.

Drop me a line in the chat!. I will be connected.

Clone this wiki locally