Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java akka remote clustering with play framework

I am building a system of clustered computers with several nodes. there is a master node that is suppose to schedule task to several nodes in the cluster. the nodes are separate PCs that are connected to the master node via network cables. the whole system is expected to be implemented with java akka and play framework platform. is there a way to implement this with akka remote clustering with play framework.

I am aware of the remote calculator tutorials but it seems to be runned with the SBT platform but I will love to know if a similar tutorials exist with the play framework.

Or any link to help me with my project

thank you

like image 232
faisal abdulai Avatar asked Jan 15 '23 12:01

faisal abdulai


1 Answers

An instance of Play! framework application can connect to a remote Akka node (i.e: your master node) using a simple configuration.

There are two ways:

  1. override the default actor system
  2. define a new actor system

I suggest you to use the second one. In this case you have to add in application.conf something like

master {
    akka {
        actor {
            provider = "akka.remote.RemoteActorRefProvider"
        }
        remote {
            transport = "akka.remote.netty.NettyRemoteTransport"
            netty {
                hostname = "your-master-host-name"
                port = 0
            }
        }
    }
}

Then in your Play! app you can connect to te remote master node in this way

 ActorSystem system = ActorSystem.create("master", ConfigFactory.load().getConfig("master"))

 ActorRef master = system.actorFor("akka://master@your-master-host-name:your-master-port/user/master")

If you prefer to override de default Play Akka actor system. Here is the reference configuration: http://www.playframework.org/documentation/2.0.3/AkkaCore

For the master and computational cluster nodes I suggest you to use the architecture and the code described here: http://letitcrash.com/post/29044669086/balancing-workload-across-nodes-with-akka-2

If your master and computational nodes does not required a web or REST interface you can implement them as simple Java program.

In the cited article the node are not exposed remotely. To do that just add an application.conf in master node app:

master {
    akka {
        actor {
            provider = "akka.remote.RemoteActorRefProvider"
        }
        remote {
            transport = "akka.remote.netty.NettyRemoteTransport"
            netty {
                hostname = "your-master-host-name"
                port = your-master-port
            }
        }
    }
}

And instantiate it in with actorOf method

ActorSystem system = ActorSystem.create("master", ConfigFactory.load().getConfig("master"))

ActorRef master = system.actorOf(new Props(Master.class), "master")

The computational nodes must be configured in the same way of Play! node.

Notice that only master node has a TCP-IP port defined. Non-master nodes use 0 port, which configure Akka to choose a random free port for them. This is correct because the only well-known host:port address you need is the master one, where every nodes, when its startup, has to point to.

like image 181
Federico Dal Maso Avatar answered Jan 28 '23 08:01

Federico Dal Maso