Compare commits

..

2 commits

Author SHA1 Message Date
0cb4b6815c start implementing k-choices rebalancing, considering 1 VS each run
only loop implemented, rebalancing not implemented
2020-10-07 00:43:06 +02:00
b111515178 add config option for k-choices rebalance interval 2020-10-06 16:01:29 +02:00
3 changed files with 33 additions and 1 deletions

View file

@ -31,6 +31,7 @@ readConfig = do
-- waiting for timeout -- waiting for timeout
let let
speedup = read speedupString speedup = read speedupString
statsEvalD = 120 * 10^6 `div` speedup
confBootstrapNodes' = case remainingArgs of confBootstrapNodes' = case remainingArgs of
bootstrapHost : bootstrapPortString : _ -> bootstrapHost : bootstrapPortString : _ ->
[(bootstrapHost, read bootstrapPortString)] [(bootstrapHost, read bootstrapPortString)]
@ -52,6 +53,7 @@ readConfig = do
, confKChoicesOverload = 0.9 , confKChoicesOverload = 0.9
, confKChoicesUnderload = 0.1 , confKChoicesUnderload = 0.1
, confKChoicesMaxVS = 8 , confKChoicesMaxVS = 8
, confKChoicesRebalanceInterval = round (realToFrac statsEvalD * 1.1 :: Double)
} }
sConf = ServiceConf sConf = ServiceConf
{ confSubscriptionExpiryTime = 24*3600 / fromIntegral speedup { confSubscriptionExpiryTime = 24*3600 / fromIntegral speedup
@ -59,7 +61,7 @@ readConfig = do
, confServiceHost = confDomainString , confServiceHost = confDomainString
, confLogfilePath = "../simulationData/logs/" <> confDomainString <> ".log" , confLogfilePath = "../simulationData/logs/" <> confDomainString <> ".log"
, confSpeedupFactor = speedup , confSpeedupFactor = speedup
, confStatsEvalDelay = 120 * 10^6 `div` speedup , confStatsEvalDelay = statsEvalD
} }
pure (fConf, sConf) pure (fConf, sConf)

View file

@ -322,6 +322,34 @@ kChoicesDepartureCost remainingOwnLoad ownCap thisSegmentLoad segment =
+ abs (remainingOwnLoad + thisSegmentLoad) / ownCap + abs (remainingOwnLoad + thisSegmentLoad) / ownCap
- abs (segmentOwnerRemainingLoadTarget segment) / segmentOwnerCapacity segment - abs (segmentOwnerRemainingLoadTarget segment) / segmentOwnerCapacity segment
kChoicesRebalanceThread :: (Service s (RealNodeSTM s)) => RealNodeSTM s -> IO ()
kChoicesRebalanceThread nodeSTM = (confKChoicesRebalanceInterval . nodeConfig <$> readTVarIO nodeSTM) >>= rebalanceVS 0
where
rebalanceVS :: NodeID -> Int -> IO ()
rebalanceVS startAt interval = do
threadDelay interval
(vsToRebalance', serv) <- atomically $ do
node <- readTVar nodeSTM
pure (rMapLookupPred 0 (vservers node), nodeService node)
maybe
-- wait and retry if no active VS available
(rebalanceVS startAt interval)
(\(vsNid, vsSTM) -> do
vs <- readTVarIO vsSTM
-- query neighbour node(s) load
-- query own load
-- calculate departure cost
-- if deciding to re-balance, first leave and then join
-- loop
rebalanceVS vsNid interval
)
vsToRebalance'
-- placeholder
pure ()
-- | Join a new node into the DHT, using a provided bootstrap node as initial cache seed -- | Join a new node into the DHT, using a provided bootstrap node as initial cache seed
-- for resolving the new node's position. -- for resolving the new node's position.
fediChordBootstrapJoin :: Service s (RealNodeSTM s) fediChordBootstrapJoin :: Service s (RealNodeSTM s)

View file

@ -459,6 +459,8 @@ data FediChordConf = FediChordConf
-- ^ fraction of capacity below which a node considers itself underloaded -- ^ fraction of capacity below which a node considers itself underloaded
, confKChoicesMaxVS :: Word8 , confKChoicesMaxVS :: Word8
-- ^ upper limit of vserver index κ -- ^ upper limit of vserver index κ
, confKChoicesRebalanceInterval :: Int
-- ^ interval between vserver rebalance attempts
} }
deriving (Show, Eq) deriving (Show, Eq)