sped up sim step by about 200%
Noticed that it was quite slow compared with things like action sendwanted. Guessed that the slowdown is largely due to every step doing a simulated git pull/push. So, rather than always doing a pull/push, only do those when no actions are found without doing a pull/push. This does mean that step will sometimes experience a split brain situation, but that seems like a good thing? Because step ought to explore as many possible scenarios as it reasonably can.
This commit is contained in:
parent
6df101f8b4
commit
969e6c2747
4 changed files with 33 additions and 30 deletions
46
Annex/Sim.hs
46
Annex/Sim.hs
|
@ -490,22 +490,39 @@ applySimCommand' (CommandNotPresent _ _) _ _ = error "applySimCommand' CommandNo
|
|||
handleStep :: Int -> Int -> SimState SimRepo -> Annex (SimState SimRepo)
|
||||
handleStep startn n st
|
||||
| n > 0 = do
|
||||
let (st', actions) = getcomponents [] st $
|
||||
getactions [] (M.toList (simRepos st))
|
||||
(st'', stable) <- runoneaction actions st'
|
||||
if stable
|
||||
then return st''
|
||||
let (st', actions) = getactions unsyncactions st
|
||||
(st'', nothingtodo) <- runoneaction actions st'
|
||||
if nothingtodo
|
||||
then do
|
||||
let (st''', actions') = getactions [ActionSync] st''
|
||||
(st'''', stable) <- runoneaction actions' st'''
|
||||
if stable
|
||||
then do
|
||||
showLongNote $ UnquotedString $
|
||||
"Simulation has stabilized after "
|
||||
++ show (startn - n)
|
||||
++ " steps."
|
||||
return st''''
|
||||
else handleStep startn (pred n) st''''
|
||||
else handleStep startn (pred n) st''
|
||||
| otherwise = return st
|
||||
where
|
||||
getactions c [] = c
|
||||
getactions c ((repo, u):repos) =
|
||||
unsyncactions =
|
||||
[ ActionGetWanted
|
||||
, ActionSendWanted
|
||||
, \repo remote -> ActionDropUnwanted repo (Just remote)
|
||||
]
|
||||
|
||||
getactions mks st' = getcomponents [] st' $
|
||||
getactions' mks [] (M.toList (simRepos st'))
|
||||
|
||||
getactions' _ c [] = concat c
|
||||
getactions' mks c ((repo, u):repos) =
|
||||
case M.lookup u (simConnections st) of
|
||||
Nothing -> getactions c repos
|
||||
Nothing -> getactions' mks c repos
|
||||
Just remotes ->
|
||||
let c' = map (ActionSync repo)
|
||||
(S.toList remotes)
|
||||
in getactions (c'++c) repos
|
||||
let l = [mk repo remote | remote <- S.toList remotes, mk <- mks]
|
||||
in getactions' mks (l:c) repos
|
||||
|
||||
getcomponents c st' [] = (st', concat c)
|
||||
getcomponents c st' (a:as) = case getSimActionComponents a st' of
|
||||
|
@ -513,12 +530,7 @@ handleStep startn n st
|
|||
Right (Right st'') -> getcomponents c st'' as
|
||||
Right (Left (st'', cs)) -> getcomponents (cs:c) st'' as
|
||||
|
||||
runoneaction [] st' = do
|
||||
showLongNote $ UnquotedString $
|
||||
"Simulation has stabilized after "
|
||||
++ show (startn - n)
|
||||
++ " steps."
|
||||
return (st', True)
|
||||
runoneaction [] st' = return (st', True)
|
||||
runoneaction actions st' = do
|
||||
let (idx, st'') = simRandom st'
|
||||
(randomR (0, length actions - 1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue