Skip to content

Commit

Permalink
fix(sut): more accurate throughput
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 11, 2022
1 parent 53e8810 commit a7f48cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/journal/src/Journal/Internal/Metrics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ percentile (Metrics _ hbuf) label p
where
go' :: Int -> Double -> IO (Maybe Double)
go' idx acc
| idx >= len = return Nothing
| idx < len = do
| idx >= len = return Nothing
| idx < len = do
v <- readIntOffArrayIx hbuf (idx * sizeOf (8 :: Int) + offsetBucket)
let sum' = realToFrac v + acc
if sum' >= target
Expand Down
51 changes: 32 additions & 19 deletions src/sut/dumblog/src/Dumblog/Metrics/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module Dumblog.Metrics.Main where

import Control.Concurrent (threadDelay)
import Control.Exception (IOException)
import Control.Monad (forever)
import Data.Maybe (fromMaybe)
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import Text.Printf (printf)
Expand All @@ -18,21 +17,32 @@ import Journal.Types

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

data ThroughputState = ThroughputState
{ tsLastTotalCount :: !Int
, tsLastTime :: !UTCTime
}

metricsMain :: IO ()
metricsMain = do
startTime <- getCurrentTime
forever $ do
setLocaleEncoding utf8 -- Otherwise we can't print µ...
metrics <- newMetrics dumblogSchema dUMBLOG_METRICS
eMeta <- journalMetadata dUMBLOG_JOURNAL dumblogOptions
putStrLn ansiClearScreen
displayServiceTime metrics
displayQueueDepth metrics
displayThroughput metrics startTime
displayJournalMetadata eMeta
displayConcurrentConnections metrics
displayErrors metrics
threadDelay 1_000_000
setLocaleEncoding utf8 -- Otherwise we can't print µ...
now <- getCurrentTime
go (ThroughputState 0 now)
where
go :: ThroughputState -> IO ()
go ts = do
metrics <- newMetrics dumblogSchema dUMBLOG_METRICS
eMeta <- journalMetadata dUMBLOG_JOURNAL dumblogOptions

putStrLn ansiClearScreen
displayServiceTime metrics
displayQueueDepth metrics
ts' <- displayThroughput metrics ts
displayJournalMetadata eMeta
displayConcurrentConnections metrics
displayErrors metrics

threadDelay 1_000_000
go ts'

ansiClearScreen :: String
ansiClearScreen = "\ESC[2J"
Expand Down Expand Up @@ -75,14 +85,17 @@ displayQueueDepth metrics = do
depth <- getCounter metrics QueueDepth
printf " %d\n" depth

displayThroughput :: DumblogMetrics -> UTCTime -> IO ()
displayThroughput metrics startTime = do
displayThroughput :: DumblogMetrics -> ThroughputState -> IO ThroughputState
displayThroughput metrics ts = do
now <- getCurrentTime
writeCnt <- count metrics ServiceTimeWrites
readCnt <- count metrics ServiceTimeReads
let totalCnt :: Double
totalCnt = realToFrac (writeCnt + readCnt)
printf "\nThroughput: %.2f ops/s\n" (totalCnt / realToFrac (diffUTCTime now startTime))
let totalCnt :: Int
totalCnt = writeCnt + readCnt
printf "\nThroughput: %.2f ops/s\n"
(realToFrac (totalCnt - tsLastTotalCount ts) /
realToFrac (diffUTCTime now (tsLastTime ts)) :: Double)
return (ThroughputState totalCnt now)

displayJournalMetadata :: Either IOException Metadata -> IO ()
displayJournalMetadata (Left _err) = do
Expand Down

0 comments on commit a7f48cf

Please sign in to comment.