在AWS

时间:2016-07-25 17:57:50

标签: amazon-web-services haskell amazon-ec2 cloud-haskell

我在AWS上创建了3个EC2 Ubuntu实例并尝试运行此代码:

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

通过这里所述的命令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&amp;

$ stack exec - test slave 172.31.3.227 8080&amp;

$ stack exec - test master 172.31.3.228 8080

IP是AWS实例的私有IP。但是当我作为主人运行时,没有连接的奴隶。这是输出:

奴隶:[]

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

测试:除以零

输出中应该连接了从属设备,但没有。

0 个答案:

没有答案