-
Notifications
You must be signed in to change notification settings - Fork 28
Running example(s)
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 running 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 (less than 200 lines of code including browser interface!):
https://github.com/agocorona/transient-universe/blob/master/examples/distributedApps.hs
It is necessary to sign in in Cloud9. Then, clone this project.
In the console, execute three 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.
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 ephimeral 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.
| Intro
| How-to
| Backtracking to undo IO actions and more
| Finalization: better than exceptions
| Event variables: Publish Suscribe
| Checkpoints(New), suspend and restore
| Remote execution: The Cloud monad
| Clustering: programming the cloud
| Mailboxes for cloud communications
| Distributed computing: map-reduce