add runtime flag for enabling k-choices or not

any value except "off" means on

contributes to #2
This commit is contained in:
Trolli Schmittlauch 2020-09-22 23:12:07 +02:00
parent 13c5b385b1
commit 62da66aade
3 changed files with 29 additions and 21 deletions

View file

@ -26,7 +26,7 @@ main = do
readConfig :: IO (FediChordConf, ServiceConf)
readConfig = do
confDomainString : ipString : portString : servicePortString : speedupString : remainingArgs <- getArgs
confDomainString : ipString : portString : servicePortString : speedupString : loadBalancingEnabled : remainingArgs <- getArgs
-- allow starting the initial node without bootstrapping info to avoid
-- waiting for timeout
let
@ -48,6 +48,7 @@ readConfig = do
, confResponsePurgeAge = 60 / fromIntegral speedup
, confRequestTimeout = 5 * 10^6 `div` speedup
, confRequestRetries = 3
, confEnableKChoices = loadBalancingEnabled /= "off"
}
sConf = ServiceConf
{ confSubscriptionExpiryTime = 24*3600 / fromIntegral speedup

View file

@ -120,16 +120,21 @@ fediChordInit initConf serviceRunner = do
-- prepare for joining: start node cache writer thread
-- currently no masking is necessary, as there is nothing to clean up
nodeCacheWriterThread <- forkIO $ nodeCacheWriter realNodeSTM
-- TODO: k-choices way of joining, so far just initialise a single vserver
fediThreadsAsync <- if confEnableKChoices initConf
then
-- TODO: k-choices way of joining
async (fediMainThreads serverSock realNodeSTM)
else do
-- without k-choices, just initialise a single vserver
firstVS <- nodeStateInit realNodeSTM 0
firstVSSTM <- newTVarIO firstVS
-- add vserver to list at RealNode
atomically . modifyTVar' realNodeSTM $ \rn -> rn { vservers = HMap.insert (getNid firstVS) firstVSSTM (vservers rn) }
-- try joining the DHT using one of the provided bootstrapping nodes
joinedState <- tryBootstrapJoining firstVSSTM
fediThreadsAsync <- either (\err -> do
-- handle unsuccessful join
either (\err -> do
-- handle unsuccessful join
putStrLn $ err <> " Error joining, start listening for incoming requests anyways"
-- launch thread attempting to join on new cache entries
_ <- forkIO $ joinOnNewEntriesThread firstVSSTM

View file

@ -436,6 +436,8 @@ data FediChordConf = FediChordConf
-- ^ how long to wait until response has arrived, in milliseconds
, confRequestRetries :: Int
-- ^ how often re-sending a timed-out request can be retried
, confEnableKChoices :: Bool
-- ^ whether to enable k-choices load balancing
}
deriving (Show, Eq)