Permalink
Browse files

Add throughput tests.

  • Loading branch information...
1 parent 3c41094 commit 0ab544a16a4d4b08efd3685eef4189da81618f42 Toralf Wittner committed Jan 23, 2010
Showing with 141 additions and 2 deletions.
  1. +60 −1 README
  2. +51 −0 test/perf/local_thr.hs
  3. +29 −0 test/perf/remote_thr.hs
  4. +1 −1 test/poll.hs
View
61 README
@@ -1 +1,60 @@
-Haskell bindings to zeromq (http://zeromq.org).
+This library provides Haskell bindings to zeromq (http://zeromq.org).
+
+
+· Current status
+
+Version 0.1 - This software currently has *alpha* status, i.e. it had
+only seen very limited testing and changes to its API might happen.
+
+This software was developed and tested on Linux 2.6.31 with GHC-6.12.1
+using the current git HEAD of zeromq2 (http://github.com/sustrik/zeromq2).
+
+
+· Installation
+
+As usual for Haskell packages this software is installed best via Cabal
+(http://www.haskell.org/cabal). In addition to GHC it depends on 0MQ of course.
+
+
+· Usage
+
+The API mostly follows 0MQ's. Public functions are:
+
+- init
+- term
+- socket
+- close
+- setOption
+- subscribe
+- unsubscribe
+- bind
+- connect
+- send
+- flush
+- receive
+- poll
+
+One difference to 0MQ's API is that sockets are parameterized types, i.e. there
+is not one socket type but when creating a socket the desired socket type has
+to be specified, e.g. 'P2P' and the resulting socket is of type 'Socket P2P'.
+This additional type information is used to ensure that only options applicable
+to the socket type can be set, hence ZMQ_SUBSCRIBE and ZMQ_UNSUBSCRIBE which
+only apply to ZMQ_SUB sockets have their own functions ('subscribe' and
+'unsubscribe') which can only be used with sockets of type 'Socket Sub'.
+
+Other differences are mostly for convenience. Also one does not deal directly
+with 0MQ messages, instead these are created internally as needed.
+
+
+· Examples
+
+The test folder contains some simple tests mostly mimicking the ones that come
+with 0MQ.
+
+
+· Bugs
+
+If you find any bugs or other shortcomings I would greatly appreciate a bug
+report, preferably via http://github.com/twittner/zeromq-haskell/issues or e-mail
+to toralf.wittner@gmail.com
+
View
@@ -0,0 +1,51 @@
+import Control.Monad
+import System.IO
+import System.Exit
+import System.Environment
+import Data.Time.Clock
+import qualified System.ZMQ as ZMQ
+import qualified Data.ByteString as SB
+import Text.Printf
+
+main :: IO ()
+main = do
+ args <- getArgs
+ when (length args /= 3) $ do
+ hPutStrLn stderr usage
+ exitFailure
+ let bindTo = args !! 0
+ size = read $ args !! 1 :: Int
+ count = read $ args !! 2 :: Int
+ c <- ZMQ.init 1 1 False
+ s <- ZMQ.socket c ZMQ.Sub
+ ZMQ.subscribe s ""
+ ZMQ.bind s bindTo
+ receive s size
+ start <- getCurrentTime
+ loop s (count - 1) size
+ end <- getCurrentTime
+ printStat start end size count
+ ZMQ.close s
+ ZMQ.term c
+ where
+ receive s sz = do
+ msg <- ZMQ.receive s []
+ when (SB.length msg /= sz) $
+ error "message of incorrect size received"
+
+ loop s c sz = unless (c <= 0) $ do
+ receive s sz
+ loop s (c - 1) sz
+
+ printStat start end size count = do
+ let elapsed = fromRational . toRational $ diffUTCTime end start :: Double
+ through = fromIntegral count / elapsed
+ mbits = (through * fromIntegral size * 8) / 1000000
+ printf "message size: %d [B]\n" size
+ printf "message count: %d\n" count
+ printf "mean throughput: %.3f [msg/s]\n" through
+ printf "mean throughput: %.3f [Mb/s]\n" mbits
+
+usage :: String
+usage = "usage: local_thr <bind-to> <message-size> <message-count>"
+
View
@@ -0,0 +1,29 @@
+import Control.Monad
+import Control.Concurrent
+import System.IO
+import System.Exit
+import System.Environment
+import qualified System.ZMQ as ZMQ
+import qualified Data.ByteString as SB
+
+main :: IO ()
+main = do
+ args <- getArgs
+ when (length args /= 3) $ do
+ hPutStrLn stderr usage
+ exitFailure
+ let connTo = args !! 0
+ size = read $ args !! 1
+ count = read $ args !! 2
+ message = SB.replicate size 0x65
+ c <- ZMQ.init 1 1 False
+ s <- ZMQ.socket c ZMQ.Pub
+ ZMQ.connect s connTo
+ replicateM_ count $ ZMQ.send s message []
+ threadDelay 10000000
+ ZMQ.close s
+ ZMQ.term c
+
+usage :: String
+usage = "usage: remote_thr <connect-to> <message-size> <message-count>"
+
View
@@ -27,5 +27,5 @@ main = do
receive ss
usage :: String
-usage = "usage: local_lat <bind-to>"
+usage = "usage: poll <bind-to>"

0 comments on commit 0ab544a

Please sign in to comment.