add runtime flag for enabling k-choices or not
any value except "off" means on contributes to #2
This commit is contained in:
parent
13c5b385b1
commit
62da66aade
|
@ -26,7 +26,7 @@ main = do
|
||||||
|
|
||||||
readConfig :: IO (FediChordConf, ServiceConf)
|
readConfig :: IO (FediChordConf, ServiceConf)
|
||||||
readConfig = do
|
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
|
-- allow starting the initial node without bootstrapping info to avoid
|
||||||
-- waiting for timeout
|
-- waiting for timeout
|
||||||
let
|
let
|
||||||
|
@ -48,6 +48,7 @@ readConfig = do
|
||||||
, confResponsePurgeAge = 60 / fromIntegral speedup
|
, confResponsePurgeAge = 60 / fromIntegral speedup
|
||||||
, confRequestTimeout = 5 * 10^6 `div` speedup
|
, confRequestTimeout = 5 * 10^6 `div` speedup
|
||||||
, confRequestRetries = 3
|
, confRequestRetries = 3
|
||||||
|
, confEnableKChoices = loadBalancingEnabled /= "off"
|
||||||
}
|
}
|
||||||
sConf = ServiceConf
|
sConf = ServiceConf
|
||||||
{ confSubscriptionExpiryTime = 24*3600 / fromIntegral speedup
|
{ confSubscriptionExpiryTime = 24*3600 / fromIntegral speedup
|
||||||
|
|
|
@ -120,27 +120,32 @@ fediChordInit initConf serviceRunner = do
|
||||||
-- prepare for joining: start node cache writer thread
|
-- prepare for joining: start node cache writer thread
|
||||||
-- currently no masking is necessary, as there is nothing to clean up
|
-- currently no masking is necessary, as there is nothing to clean up
|
||||||
nodeCacheWriterThread <- forkIO $ nodeCacheWriter realNodeSTM
|
nodeCacheWriterThread <- forkIO $ nodeCacheWriter realNodeSTM
|
||||||
-- TODO: k-choices way of joining, so far just initialise a single vserver
|
fediThreadsAsync <- if confEnableKChoices initConf
|
||||||
firstVS <- nodeStateInit realNodeSTM 0
|
then
|
||||||
firstVSSTM <- newTVarIO firstVS
|
-- TODO: k-choices way of joining
|
||||||
-- add vserver to list at RealNode
|
async (fediMainThreads serverSock realNodeSTM)
|
||||||
atomically . modifyTVar' realNodeSTM $ \rn -> rn { vservers = HMap.insert (getNid firstVS) firstVSSTM (vservers rn) }
|
else do
|
||||||
-- try joining the DHT using one of the provided bootstrapping nodes
|
-- without k-choices, just initialise a single vserver
|
||||||
joinedState <- tryBootstrapJoining firstVSSTM
|
firstVS <- nodeStateInit realNodeSTM 0
|
||||||
fediThreadsAsync <- either (\err -> do
|
firstVSSTM <- newTVarIO firstVS
|
||||||
-- handle unsuccessful join
|
-- 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
|
||||||
|
|
||||||
putStrLn $ err <> " Error joining, start listening for incoming requests anyways"
|
either (\err -> do
|
||||||
-- launch thread attempting to join on new cache entries
|
-- handle unsuccessful join
|
||||||
_ <- forkIO $ joinOnNewEntriesThread firstVSSTM
|
putStrLn $ err <> " Error joining, start listening for incoming requests anyways"
|
||||||
async (fediMainThreads serverSock realNodeSTM)
|
-- launch thread attempting to join on new cache entries
|
||||||
)
|
_ <- forkIO $ joinOnNewEntriesThread firstVSSTM
|
||||||
(\joinedNS -> do
|
async (fediMainThreads serverSock realNodeSTM)
|
||||||
-- launch main eventloop with successfully joined state
|
)
|
||||||
putStrLn "successful join"
|
(\joinedNS -> do
|
||||||
async (fediMainThreads serverSock realNodeSTM)
|
-- launch main eventloop with successfully joined state
|
||||||
)
|
putStrLn "successful join"
|
||||||
joinedState
|
async (fediMainThreads serverSock realNodeSTM)
|
||||||
|
)
|
||||||
|
joinedState
|
||||||
pure (fediThreadsAsync, realNodeSTM)
|
pure (fediThreadsAsync, realNodeSTM)
|
||||||
|
|
||||||
-- | initialises the 'NodeState' for this local node.
|
-- | initialises the 'NodeState' for this local node.
|
||||||
|
|
|
@ -436,6 +436,8 @@ data FediChordConf = FediChordConf
|
||||||
-- ^ how long to wait until response has arrived, in milliseconds
|
-- ^ how long to wait until response has arrived, in milliseconds
|
||||||
, confRequestRetries :: Int
|
, confRequestRetries :: Int
|
||||||
-- ^ how often re-sending a timed-out request can be retried
|
-- ^ how often re-sending a timed-out request can be retried
|
||||||
|
, confEnableKChoices :: Bool
|
||||||
|
-- ^ whether to enable k-choices load balancing
|
||||||
}
|
}
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue