From 917f25ded3c2504ef677b3ed4dec943947b591ed Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Tue, 28 Feb 2023 05:54:53 +0300 Subject: [PATCH] cache sweeping --- hbs2-peer/app/BlockDownload.hs | 11 ++++++++++- hbs2-peer/app/PeerTypes.hs | 8 -------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hbs2-peer/app/BlockDownload.hs b/hbs2-peer/app/BlockDownload.hs index 47d0f1f2..2d8f6308 100644 --- a/hbs2-peer/app/BlockDownload.hs +++ b/hbs2-peer/app/BlockDownload.hs @@ -586,12 +586,17 @@ postponedLoop env0 = do void $ liftIO $ async $ withPeerM e $ withDownload env0 do po <- asks (view peerPostponed) + ban <- asks (view blockBanned) + stored <- asks (view blockStored) forever do -- FIXME: del-posponed-time-hardcode pause @'Seconds 60 debug "postponedLoop" + liftIO $ Cache.purgeExpired ban + liftIO $ Cache.purgeExpired stored + back <- liftIO $ atomically $ stateTVar po $ \hm -> let els = HashMap.toList hm in -- FIXME: back-from-postponed-size-var @@ -671,12 +676,16 @@ peerDownloadLoop peer = do forever do + liftIO do + Cache.purgeExpired sizeCache + Cache.purgeExpired noBlock + auth' <- lift $ find (KnownPeerKey peer) id pinfo' <- lift $ find (PeerInfoKey peer) id -- (view peerDownloadFail) let mbauth = (,) <$> auth' <*> pinfo' - let noAuth = warn ( "lost peer auth" <+> pretty peer) >> pause @'Seconds 5 + let noAuth = warn ( "lost peer auth" <+> pretty peer) >> pause @'Seconds 1 maybe1 mbauth noAuth $ \(_,pinfo) -> do diff --git a/hbs2-peer/app/PeerTypes.hs b/hbs2-peer/app/PeerTypes.hs index 4681a9f9..adcc8d59 100644 --- a/hbs2-peer/app/PeerTypes.hs +++ b/hbs2-peer/app/PeerTypes.hs @@ -235,14 +235,6 @@ incBlockSizeReqCount h = do writeTVar (view bsLastSeen blk) now modifyTVar (view bsReqSizeTimes blk) succ --- FIXME: что-то более обоснованно -calcWaitTime :: MonadIO m => BlockDownloadM e m Double -calcWaitTime = do - wip <- asks (view blockWip) >>= liftIO . Cache.size - let wipn = realToFrac wip * 3 - let waiting = 5 + ( (realToFrac (toNanoSeconds defBlockWaitMax) * wipn) / 1e9 ) - pure waiting - isBlockHereCached :: forall e m . ( MyPeer e , MonadIO m , HasStorage m