Skip to content

Commit

Permalink
feat(sut): add benchmark for zero copy variant
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 3, 2022
1 parent 48e3431 commit 41851b1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/sut/dumblog/bench/zero-copy/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Main where

import Dumblog.ZeroCopy.Main (zeroCopyDumblog)

import Common

------------------------------------------------------------------------

main :: IO ()
main = commonMain "ZeroCopy" (zeroCopyDumblog bUFFER_CAPACITY pORT . Just)
6 changes: 6 additions & 0 deletions src/sut/dumblog/dumblog.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,9 @@ benchmark bench-sqlite
hs-source-dirs: bench/sqlite
main-is: Main.hs
type: exitcode-stdio-1.0

benchmark bench-zero-copy
import: bench-common
hs-source-dirs: bench/zero-copy
main-is: Main.hs
type: exitcode-stdio-1.0
5 changes: 3 additions & 2 deletions src/sut/dumblog/src/Dumblog/ZeroCopy/HttpServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import Dumblog.ZeroCopy.State

------------------------------------------------------------------------

httpServer :: Journal -> Int -> IO ()
httpServer jour port = withSocketsDo $ do
httpServer :: Journal -> Int -> Maybe (MVar ()) -> IO ()
httpServer jour port mReady = withSocketsDo $ do
numCapabilities <- getNumCapabilities
putStrLn ("Starting http server on port: " ++ show port)
putStrLn ("Capabilities: : " ++ show numCapabilities)
Expand All @@ -30,6 +30,7 @@ httpServer jour port = withSocketsDo $ do
mgr <- fromMaybe (error "Compile with -threaded") <$> getSystemEventManager
_key <- withFdSocket sock $ \fd ->
registerFd mgr (client jour state sock) (fromIntegral fd) evtRead MultiShot
maybe (return ()) (flip putMVar ()) mReady
loop
where
loop = do
Expand Down
17 changes: 9 additions & 8 deletions src/sut/dumblog/src/Dumblog/ZeroCopy/Main.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
module Dumblog.ZeroCopy.Main where

import Journal.Types (Journal)
import Control.Concurrent (MVar)
import Journal.Types (oTermBufferLength)
import Journal (defaultOptions, allocateJournal, startJournal)

import Dumblog.ZeroCopy.HttpServer

------------------------------------------------------------------------

zeroCopyDumblog :: Journal -> Int -> IO ()
zeroCopyDumblog jour port = httpServer jour port

main :: IO ()
main = do
zeroCopyDumblog :: Int -> Int -> Maybe (MVar ()) -> IO ()
zeroCopyDumblog capacity port mReady = do
let fp = "/tmp/dumblog-zero-copy.journal"
opts = defaultOptions
opts = defaultOptions { oTermBufferLength = capacity }
allocateJournal fp opts
jour <- startJournal fp opts
zeroCopyDumblog jour 8054
httpServer jour port mReady

main :: IO ()
main = zeroCopyDumblog (64 * 1024) 8054 Nothing

0 comments on commit 41851b1

Please sign in to comment.