git.iko.soy/distributed-process
on master help sign in
Add latency test
commit82517c2381cdc877c3deef124483794236ec9c57 authorEdsko de Vries <edsko@well-typed.com> dateFri 7 Sep 2012, 07:27 (14 years ago) parent188f6aa
3 files changed+64−18
distributed-process/benchmarks/Latency.hs+36 distributed-process/benchmarks/Throughput.hs+15−18 distributed-process/distributed-process.cabal+13
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
1515 b <- expect
1616 case b of
1717 Nothing -> go (n + 1)
18− Just them -> send them n
18+ Just them -> send them n >> go 0
1919
2020count :: Int -> ProcessId -> Process ()
2121count n them = do
@@ -25,22 +25,19 @@ count n them = do
2525 n' <- expect
2626 liftIO $ print (n == n')
2727
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+
2838main :: IO ()
2939main = do
30− args <- getArgs
31− case args of
32− ["server", host, port] -> do
33− 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− runProcess node $ do
43− them <- liftIO $ decode <$> BSL.readFile "counter.pid"
44− count (read n) them
45− _ -> error "Invalid arguments"
46−
40+ [role, host, port] <- getArgs
41+ Right transport <- createTransport host port defaultTCPParameters
42+ node <- newLocalNode transport initRemoteTable
43+ runProcess node $ initialProcess role
distributed-process/distributed-process.cabal+13
@@ -130,3 +130,16 @@ Executable distributed-process-throughput
130130 Main-Is: benchmarks/Throughput.hs
131131 ghc-options: -Wall
132132 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