transient-haskell / transient

A full stack, reactive architecture for general purpose programming. Algebraic and monadically composable primitives for concurrency, parallelism, event handling, transactions, multithreading, Web, and distributed computing with complete de-inversion of control (No callbacks, no blocking, pure state)
MIT License
631 stars 28 forks source link

An example using the "real" nodes on different machines (or processes) #5

Closed AlexeyRaga closed 7 years ago

AlexeyRaga commented 8 years ago

An example that shows how to use the distributed features on "real" nodes would be appreciated: how to create remote nodes, should listen be called only for the local node or for all nodes, how to wait until all the nodes connect, etc.

agocorona commented 7 years ago

Alex:

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

It is a distributed program with N nodes and that is accessed with a web interface made of widgets using the transient stack. It show 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.

sign in in Cloud9 and clone it.

In the console, execute three nodes by:

> cd transientinstaller
> ./init.sh

A cluster of three nodes will be started.

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

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

if you want to compile it:

  > 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 copy.

agocorona commented 7 years ago

transientt

agocorona commented 7 years ago

transientt2