make stats measurement delay configurable, take speedup into account

This commit is contained in:
Trolli Schmittlauch 2020-09-10 21:23:21 +02:00
parent 8f917130c4
commit 34ecdd66e1
3 changed files with 9 additions and 6 deletions

View file

@ -73,6 +73,8 @@ readConfig = do
, confServicePort = read servicePortString
, confServiceHost = confDomainString
, confLogfilePath = "../simulationData/logs/" <> confDomainString <> ".log"
, confSpeedupFactor = speedup
, confStatsEvalDelay = 35 * 10^6 `div` speedup
}
pure (fConf, sConf)

View file

@ -459,6 +459,10 @@ data ServiceConf = ServiceConf
-- ^ hostname of service
, confLogfilePath :: String
-- ^ where to store the (measurement) log file
, confStatsEvalDelay :: Int
-- ^ delay between statistic rate measurement samplings, in microseconds
, confSpeedupFactor :: Int
-- While the speedup factor needs to be already included in all
}
class DHT d where

View file

@ -743,9 +743,6 @@ data RelayStats = RelayStats
}
-- TODO: make delay configurable
statsEvalDelay = 300000
launchStatsThreads :: PostService d -> IO ()
launchStatsThreads serv = do
@ -795,7 +792,7 @@ evaluateStatsThread :: PostService d -> TVar RelayStats -> IO ()
evaluateStatsThread serv statsAcc = getPOSIXTime >>= loop
where
loop previousTs = do
threadDelay statsEvalDelay
threadDelay $ confStatsEvalDelay (serviceConf serv)
-- get and reset the stats accumulator
summedStats <- atomically $ do
stats <- readTVar statsAcc
@ -806,7 +803,8 @@ evaluateStatsThread serv statsAcc = getPOSIXTime >>= loop
now <- getPOSIXTime
-- evaluate stats rate and replace server stats
-- persistently store in a TVar so it can be retrieved later by the DHT
atomically . writeTVar (loadStats serv) . evaluateStats (now - previousTs) $ summedStats
let timePassed = (now - previousTs) * fromIntegral (confSpeedupFactor $ serviceConf serv)
atomically . writeTVar (loadStats serv) . evaluateStats timePassed $ summedStats
-- and now what? write a log to file
-- format: total relayReceiveRates;total relayDeliveryRates;postFetchRate;postPublishRate
-- later: current (reported) load, target load
@ -833,7 +831,6 @@ evaluateStats timeInterval summedStats =
, postFetchRate = postFetchRate summedStats / intervalSeconds
}
where
-- TODO: take speedup into account
intervalSeconds = fromIntegral (fromEnum timeInterval) / 10^12