git.iko.soy/distributed-process
on master help sign in
Add latency test
82517c2Edsko de Vries
distributed-process/benchmarks/Latency.hsnew file+36
@@ -0,0 +1,36 @@
1+import System.Environment
2+import Control.Monad
3+import Control.Applicative
4+import Control.Distributed.Process
5+import Control.Distributed.Process.Node
6+import Network.Transport.TCP (createTransport, defaultTCPParameters)
7+import Data.Binary (encode, decode)
8+import qualified Data.ByteString.Lazy as BSL
9+
10+pingServer :: Process ()
11+pingServer = forever $ do
12+ them <- expect
13+ send them ()
14+
15+pingClient :: Int -> ProcessId -> Process ()
16+pingClient n them = do
17+ us <- getSelfPid
18+ replicateM_ n $ send them us >> (expect :: Process ())
19+ liftIO . putStrLn $ "Did " ++ show n ++ " pings"
20+
21+initialProcess :: String -> Process ()
22+initialProcess "SERVER" = do
23+ us <- getSelfPid
24+ liftIO $ BSL.writeFile "pingServer.pid" (encode us)
25+ pingServer
26+initialProcess "CLIENT" = do
27+ n <- liftIO $ getLine
28+ them <- liftIO $ decode <$> BSL.readFile "pingServer.pid"
29+ pingClient (read n) them
30+
31+main :: IO ()
32+main = do
33+ [role, host, port] <- getArgs
34+ Right transport <- createTransport host port defaultTCPParameters
35+ node <- newLocalNode transport initRemoteTable
36+ runProcess node $ initialProcess role
distributed-process/benchmarks/Throughput.hs+15−18
@@ -15,7 +15,7 @@ counter = go 0
15 b <- expect
15 b <- expect
16 case b of
16 case b of
17 Nothing -> go (n + 1)
17 Nothing -> go (n + 1)
18− Just them -> send them n
18+ Just them -> send them n >> go 0
19
19
20count :: Int -> ProcessId -> Process ()
20count :: Int -> ProcessId -> Process ()
21count n them = do
21count n them = do
@@ -25,22 +25,19 @@ count n them = do
25 n' <- expect
25 n' <- expect
26 liftIO $ print (n == n')
26 liftIO $ print (n == n')
27
27
28+initialProcess :: String -> Process ()
29+initialProcess "SERVER" = do
30+ us <- getSelfPid
31+ liftIO $ BSL.writeFile "counter.pid" (encode us)
32+ counter
33+initialProcess "CLIENT" = do
34+ n <- liftIO $ getLine
35+ them <- liftIO $ decode <$> BSL.readFile "counter.pid"
36+ count (read n) them
37+
28main :: IO ()
38main :: IO ()
29main = do
39main = do
30− args <- getArgs
40+ [role, host, port] <- getArgs
31− case args of
32− ["server", host, port] -> do
33− Right transport <- createTransport host port defaultTCPParameters
41+ Right transport <- createTransport host port defaultTCPParameters
34− node <- newLocalNode transport initRemoteTable
35− runProcess node $ do
36− us <- getSelfPid
37− liftIO $ BSL.writeFile "counter.pid" (encode us)
38− counter
39− ["client", host, port, n] -> do
40− Right transport <- createTransport host port defaultTCPParameters
41− node <- newLocalNode transport initRemoteTable
42+ node <- newLocalNode transport initRemoteTable
42− runProcess node $ do
43+ runProcess node $ initialProcess role
43− them <- liftIO $ decode <$> BSL.readFile "counter.pid"
44− count (read n) them
45− _ -> error "Invalid arguments"
46−
distributed-process/distributed-process.cabal+13
@@ -130,3 +130,16 @@ Executable distributed-process-throughput
130 Main-Is: benchmarks/Throughput.hs
130 Main-Is: benchmarks/Throughput.hs
131 ghc-options: -Wall
131 ghc-options: -Wall
132 Extensions: BangPatterns
132 Extensions: BangPatterns
133+
134+Executable distributed-process-latency
135+ if flag(benchmarks)
136+ Build-Depends: base >= 4.4 && < 5,
137+ distributed-process >= 0.3 && < 0.4,
138+ network-transport-tcp >= 0.3 && < 0.4,
139+ bytestring >= 0.9 && < 0.11,
140+ binary >= 0.5 && < 0.6
141+ else
142+ buildable: False
143+ Main-Is: benchmarks/Latency.hs
144+ ghc-options: -Wall
145+ Extensions: BangPatterns