git.iko.soy/distributed-process
on master help sign in
ignore mailbox size; remove printf noise; silence warnings
commit5ce2927e5389f112bdc11533c9632c77aef15db3 authorTim Watson <tim@rabbitmq.com> dateThu 20 Dec 2012, 15:45 (14 years ago) parent9e3786b
4 files changed+38−103
distributed-process/src/Control/Distributed/Process/Internal/CQueue.hs−10 distributed-process/src/Control/Distributed/Process/Internal/Primitives.hs−3 distributed-process/src/Control/Distributed/Process/Node.hs+17−56 distributed-process/tests/TestStats.hs+21−34
distributed-process/src/Control/Distributed/Process/Internal/CQueue.hs−10
@@ -5,7 +5,6 @@ module Control.Distributed.Process.Internal.CQueue
55 , BlockSpec(..)
66 , MatchOn(..)
77 , newCQueue
8− , length
98 , enqueue
109 , dequeue
1110 , mkWeakCQueue
@@ -36,9 +35,6 @@ import Control.Distributed.Process.Internal.StrictList
3635 ( StrictList(..)
3736 , append
3837 )
39−import qualified Control.Distributed.Process.Internal.StrictList as StrictList
40− ( foldr
41− )
4238import Data.Maybe (fromJust)
4339import GHC.MVar (MVar(MVar))
4440import GHC.IO (IO(IO))
@@ -52,12 +48,6 @@ data CQueue a = CQueue (StrictMVar (StrictList a)) -- Arrived
5248newCQueue :: IO (CQueue a)
5349newCQueue = CQueue <$> newMVar Nil <*> atomically newTChan
5450
55−length :: CQueue a -> IO Int
56−length (CQueue arrived _) = do
57− arr <- takeMVar arrived
58− let len = StrictList.foldr (\_ i -> i+1) 0 arr
59− return len
60−
6151-- | Enqueue an element
6252--
6353-- Enqueue is strict.
distributed-process/src/Control/Distributed/Process/Internal/Primitives.hs−3
@@ -412,10 +412,7 @@ getProcessInfo pid =
412412 let them = processNodeId pid in do
413413 us <- getSelfNode
414414 dest <- mkNode them us
415− liftIO . putStrLn $ "sending getInfo req to " ++ (show dest)
416−
417415 sendCtrlMsg dest $ GetInfo pid
418− liftIO . putStrLn $ "waiting for response"
419416 receiveWait [
420417 match (\(p :: ProcessInfo) -> return $ Just p)
421418 , match (\(n :: ProcessInfoNone) -> return Nothing)
distributed-process/src/Control/Distributed/Process/Node.hs+17−56
@@ -30,7 +30,6 @@ import qualified Data.Map as Map
3030 , elems
3131 , filterWithKey
3232 , foldlWithKey
33− , keys
3433 )
3534import Data.Set (Set)
3635import qualified Data.Set as Set
@@ -38,7 +37,6 @@ import qualified Data.Set as Set
3837 , insert
3938 , delete
4039 , member
41− , foldl'
4240 , toList
4341 )
4442import Data.Foldable (forM_)
@@ -71,9 +69,6 @@ import Control.Distributed.Process.Internal.CQueue
7169 , newCQueue
7270 , mkWeakCQueue
7371 )
74−import qualified Control.Distributed.Process.Internal.CQueue as Mailbox
75− ( length
76− )
7772import qualified Network.Transport as NT
7873 ( Transport
7974 , EndPoint
@@ -759,76 +754,43 @@ ncEffectGetInfo from pid =
759754 let lpid = processLocalId pid
760755 them = (ProcessIdentifier pid)
761756 in do
762− liftIO . putStrLn $ "processing get info"
763757 node <- ask
764− mProc <- liftIO $ withMVar (localState node) $ return . (^. localProcessWithId lpid)
758+ mProc <- liftIO $
759+ withMVar (localState node) $ return . (^. localProcessWithId lpid)
765760 case mProc of
766761 Nothing -> dispatch (isLocal node (ProcessIdentifier from))
767762 from node (ProcessInfoNone DiedUnknownId)
768− Just proc -> do
769− liftIO . putStrLn $ "getting links"
763+ Just _ -> do
770764 itsLinks <- gets (^. linksFor them)
771− liftIO . putStrLn $ "getting monitors"
772765 itsMons <- gets (^. monitorsFor them)
773− liftIO . putStrLn $ "getting registered names"
774766 registered <- gets (^. registeredHere)
775− sendInfo pid
776− (isLocal node (ProcessIdentifier from))
777− proc
778− node
779− (Set.toList itsLinks)
780− (Set.toList itsMons)
781− (registeredNames registered)
782−
783− where sendInfo :: ProcessId
784− -> Bool
785− -> LocalProcess
786− -> LocalNode
787− -> [ProcessId]
788− -> [(ProcessId, MonitorRef)]
789− -> [String]
790− -> NC ()
791− sendInfo d lc lp n l m r =
792− let n' = processNodeId pid
793− in do
794− qLen <- qLength lp
795− dispatch lc d n ProcessInfo {
796− infoNode = n'
797− , infoRegisteredNames = r
798− , infoMessageQueueLength = qLen
799− , infoMonitors = m
800− , infoLinks = l
801− }
802767
803− dispatch :: (Serializable a, Show a)
768+ let reg = registeredNames registered
769+ dispatch (isLocal node (ProcessIdentifier from))
770+ pid
771+ node
772+ ProcessInfo {
773+ infoNode = (processNodeId pid)
774+ , infoRegisteredNames = reg
775+ -- we cannot populate this field
776+ , infoMessageQueueLength = Nothing
777+ , infoMonitors = Set.toList itsMons
778+ , infoLinks = Set.toList itsLinks
779+ }
780+ where dispatch :: (Serializable a, Show a)
804781 => Bool
805782 -> ProcessId
806783 -> LocalNode
807784 -> a
808785 -> NC ()
809− dispatch True dest _ pInfo = do
810− -- liftIO $ putStrLn $ "posting " ++ (show pInfo) ++ " to " ++ (show dest)
811− postAsMessage dest $ pInfo
786+ dispatch True dest _ pInfo = postAsMessage dest $ pInfo
812787 dispatch False dest node pInfo = do
813− -- liftIO $ putStrLn $ "posting pinfo to node of " ++ (show dest)
814788 liftIO $ sendMessage node
815789 (NodeIdentifier (localNodeId node))
816790 (ProcessIdentifier dest)
817791 WithImplicitReconnect
818792 pInfo
819793
820− -- TODO: make this available to other functions?
821− qLength :: LocalProcess -> NC (Maybe Int)
822− qLength lp = do
823− liftIO $ putStrLn "getting qLen"
824− qRef <- liftIO $ deRefWeak (processWeakQ lp)
825− liftIO $ putStrLn "checking length..."
826− case qRef of
827− Nothing -> return $ Nothing
828− Just q -> do
829− len <- liftIO $ Mailbox.length q
830− return $ Just len
831−
832794 registeredNames = Map.foldlWithKey (\ks k v -> if v == pid
833795 then (k:ks)
834796 else ks) []
@@ -925,7 +887,6 @@ postAsMessage pid = postMessage pid . createMessage
925887
926888postMessage :: ProcessId -> Message -> NC ()
927889postMessage pid msg = do
928− liftIO $ putStrLn ("posting message to " ++ show pid)
929890 withLocalProc pid $ \p -> enqueue (processQueue p) msg
930891
931892throwException :: Exception e => ProcessId -> e -> NC ()
distributed-process/tests/TestStats.hs+21−34
@@ -3,7 +3,6 @@
33module Main where
44
55import Prelude hiding (catch)
6−import qualified Network.Transport as NT
76import Test.Framework
87 ( Test
98 , defaultMain
@@ -11,7 +10,6 @@ import Test.Framework
1110 )
1211import Network.Transport.TCP
1312import Control.Distributed.Process
14−import Control.Distributed.Process.Internal.Types ( MonitorRef(..) )
1513import Control.Distributed.Process.Node
1614 ( forkProcess
1715 , newLocalNode
@@ -24,8 +22,7 @@ import Control.Concurrent.MVar
2422 , putMVar
2523 , takeMVar
2624 )
27−import qualified Data.Set as Set
28−import Data.Binary
25+import Data.Binary()
2926import Data.Typeable()
3027import Test.HUnit (Assertion)
3128import Test.HUnit.Base (assertBool)
@@ -64,7 +61,6 @@ testLocalDeadProcessInfo result = do
6461 ref' == mref && pid' == pid && r == DiedNormal)
6562 (\p -> return p)
6663 ]
67− say "waiting for process info...."
6864 getProcessInfo pid >>= stash result
6965
7066testLocalLiveProcessInfo :: TestResult Bool -> Process ()
@@ -74,9 +70,9 @@ testLocalLiveProcessInfo result = do
7470 register "foobar" self
7571
7672 mon <- liftIO $ newEmptyMVar
77− mapM (send self) ["hello", "there", "mr", "process"]
73+ -- TODO: we can't get the mailbox's length
74+ -- mapM (send self) ["hello", "there", "mr", "process"]
7875 pid <- spawnLocal $ do
79− me <- getSelfPid
8076 link self
8177 mRef <- monitor self
8278 stash mon mRef
@@ -85,40 +81,31 @@ testLocalLiveProcessInfo result = do
8581
8682 monRef <- liftIO $ takeMVar mon
8783
88− xlog ("grabbing process-info for " ++ (show self))
8984 mpInfo <- getProcessInfo self
90−
91− xlog "checking pInfo"
92− case Just mpInfo of
85+ case mpInfo of
9386 Nothing -> stash result False
94− Just _ -> stash result True
95− -- where verifyPInfo :: ProcessInfo
96− -- -> ProcessId
97− -- -> MonitorRef
98− -- -> NodeId
99− -- -> Process ()
100− -- verifyPInfo pInfo pid mref node =
101− -- stash result $ infoNode pInfo == node &&
102− -- verifyLinks pInfo == [pid] &&
103− -- verifyMonitors pInfo == [(pid, mref)] &&
104− -- infoMessageQueueLength pInfo == Just 4 &&
105− -- infoRegisteredNames pInfo == ["foobar"]
106− -- verifyLinks = Set.toList . infoLinks
107− -- verifyMonitors = Set.toList . infoMonitors
108−
109−xlog :: String -> Process ()
110−xlog s = liftIO $ putStrLn s
87+ Just p -> verifyPInfo p pid monRef node
88+ where verifyPInfo :: ProcessInfo
89+ -> ProcessId
90+ -> MonitorRef
91+ -> NodeId
92+ -> Process ()
93+ verifyPInfo pInfo pid mref node =
94+ stash result $ infoNode pInfo == node &&
95+ infoLinks pInfo == [pid] &&
96+ infoMonitors pInfo == [(pid, mref)] &&
97+-- infoMessageQueueLength pInfo == Just 4 &&
98+ infoRegisteredNames pInfo == ["foobar"]
11199
112100tests :: LocalNode -> IO [Test]
113101tests node1 = do
114102 return [
115103 testGroup "Process Info" [
116− -- testCase "testLocalDeadProcessInfo"
117− -- (delayedAssertion
118− -- "expected dead process-info to be ProcessInfoNone"
119− -- node1 (Nothing) testLocalDeadProcessInfo)
120− -- ,
121− testCase "testLocalLiveProcessInfo"
104+ testCase "testLocalDeadProcessInfo"
105+ (delayedAssertion
106+ "expected dead process-info to be ProcessInfoNone"
107+ node1 (Nothing) testLocalDeadProcessInfo)
108+ , testCase "testLocalLiveProcessInfo"
122109 (delayedAssertion
123110 "expected process-info to be correctly populated"
124111 node1 True testLocalLiveProcessInfo)