From 0a9ad7c1a65184725885fea3d6a09929dc9307de Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 13 Sep 2016 11:37:23 -0400 Subject: maximumStorageRate calculation --- HTTP/RateLimit.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'HTTP') diff --git a/HTTP/RateLimit.hs b/HTTP/RateLimit.hs index 81e3ed2..54eb8d2 100644 --- a/HTTP/RateLimit.hs +++ b/HTTP/RateLimit.hs @@ -8,6 +8,7 @@ module HTTP.RateLimit where import Types.Cost import HTTP import HTTP.ProofOfWork +import Tunables import Servant import Control.Concurrent.STM import Control.Concurrent.TokenBucket @@ -92,12 +93,21 @@ bloomMaxSize = 1000000 -- split into multiple chunks. However, setting this too high lets clients -- cheaply store lots of data, so keep the objectSize in mind. burstSize :: Word64 -burstSize = 4 -- allow 128 kb of data to be stored/retrieved w/o proof of work +burstSize = 4 -- allow 4 objects to be stored/retrieved w/o proof of work -- | Rate that the bucket is filled. fillRate :: Word64 fillRate = 60000000 -- 1 token per minute +-- | How much data could be stored, in bytes per second, assuming all +-- buckets in the rate limiter are kept drained, and all requests are +-- stores. +maximumStorageRate :: RateLimiter -> IO Int +maximumStorageRate ratelimiter = do + let storesize = maximum knownObjectSizes + bs <- liftIO $ atomically $ readTMVar (buckets ratelimiter) + return $ (length bs * storesize * 1000000) `div` fromIntegral fillRate + -- A request is tried in each bucket in turn which its proof of work allows -- access to. If all accessible token buckets are empty, generate a -- new ProofOfWorkRequirement for the client. -- cgit v1.2.3