git.iko.soy/distributed-process
on master help sign in
fixed bugs in PingTransport benchmark and TCP
commit9ba9186939677e4f53212a51a588a001891efa6d authorAdam C. Foltzer <acfoltzer@gmail.com> dateWed 22 Feb 2012, 20:17 (15 years ago) parent931436b
2 files changed+12−9
benchmarks/PingTransport.hs+8−7 network-transport/src/Network/Transport/TCP.hs+4−2
benchmarks/PingTransport.hs+8−7
@@ -5,12 +5,12 @@ import Network.Transport.TCP (mkTransport, TCPConfig (..))
55
66import Control.Monad (forever, replicateM_)
77import Criterion.Main (Benchmark, bench, defaultMain, nfIO)
8−import Data.Binary
8+import Data.Serialize
99import Data.Maybe (fromJust)
1010import Data.Int
1111import System.Environment (getArgs, withArgs)
1212
13−import qualified Data.ByteString.Lazy.Char8 as BS
13+import qualified Data.ByteString as BS
1414
1515-- | This performs a ping benchmark on the TCP transport. This can be
1616-- compiled using:
@@ -77,16 +77,17 @@ pong targetEndPing sourceEndPong = do
7777-- | The effect of `ping sourceEndPing targetEndPong n` is to send the number
7878-- `n` using `sourceEndPing`, and to then receive the a number from
7979-- `targetEndPong`, which is then returned.
80−ping :: SourceEnd -> TargetEnd -> IO Int64
81−ping sourceEndPing targetEndPong = do
82− send sourceEndPing [BS.empty]
80+ping :: SourceEnd -> TargetEnd -> Int64 -> IO Int64
81+ping sourceEndPing targetEndPong n = do
82+ send sourceEndPing [encode n]
8383 [bs] <- receive targetEndPong
84− return $ decode bs
84+ let (Right n) = decode bs
85+ return $! n
8586
8687-- | The effect of `benchPing sourceEndPing targetEndPong n` is to send
8788-- `n` pings down `sourceEndPing` using the `ping` function. The time
8889-- taken is benchmarked.
8990benchPing :: SourceEnd -> TargetEnd -> Int64 -> Benchmark
9091benchPing sourceEndPing targetEndPong n = bench "PingTransport" $
91− nfIO (replicateM_ (fromIntegral n) (ping sourceEndPing targetEndPong))
92+ nfIO (replicateM_ (fromIntegral n) (ping sourceEndPing targetEndPong 42))
9293
network-transport/src/Network/Transport/TCP.hs+4−2
@@ -225,12 +225,14 @@ recvExact sock l = do
225225 res <- createAndTrim (fromIntegral l) (go 0)
226226 case BS.length res of
227227 n | n == (fromIntegral l) -> return $ Right res
228− _ -> return $ Left res
228+ n -> do
229+ printf "recvExact: expected %dB, got %dB\n" l n
230+ return $ Left res
229231 where
230232 go :: Int -> Ptr Word8 -> IO Int
231233 go n ptr | n == (fromIntegral l) = return n
232234 go n ptr = do
233− (p, off, len) <- toForeignPtr <$> NBS.recv sock n
235+ (p, off, len) <- toForeignPtr <$> NBS.recv sock (fromIntegral l)
234236 if len == 0
235237 then return n
236238 else withForeignPtr p $ \p -> do