CloudHaskell running on AWS

117 Views Asked by At

I have created 3 EC2 Ubuntu instances on AWS and trying to run this code:

module Main where

remotableDecl [ [d|
  distribute :: ([NodeId], Int) -> Process ()
  distribute (slaves, x) = do
    let x' = myMath x
        nextNode = slaves !! (x' `mod` (length slaves))
    say $ show x ++ " - 1 = " ++ show x'
    unless (x' == 0) $
      void $ spawn nextNode $ $(mkClosure 'distribute) (slaves, myMath x)
  |]]

remoteTable = __remoteTableDecl initRemoteTable

master :: Backend -> [NodeId] -> Process ()
master backend slaves = do
  liftIO . putStrLn $ "Slaves: " ++ show slaves
  distribute (slaves, 15)
  terminateAllSlaves backend

main :: IO ()
main = do
  prog <- getProgName
  args <- getArgs

  case args of
    ["master", host, port] -> do
      backend <- initializeBackend host port remoteTable
      startMaster backend (master backend)
    ["slave", host, port] -> do
      backend <- initializeBackend host port remoteTable
      startSlave backend

by these commands as stated here https://hackage.haskell.org/package/distributed-process-simplelocalnet-0.2.3.2/docs/Control-Distributed-Process-Backend-SimpleLocalnet.html

$ stack exec -- test slave 172.31.3.226 8080 &

$ stack exec -- test slave 172.31.3.227 8080 &

$ stack exec -- test master 172.31.3.228 8080

IPs are private IPs of AWS instances. But when I run as master, there is no slaves connected. This is the output:

Slaves: []

Tue Jul 26 17:45:04 UTC 2016 pid://172.31.3.228:8000:0:10: 15 - 1 = 14

test: divide by zero

There should be slaves connected in the output, but there is not.

0

There are 0 best solutions below