Skip to content

Instantly share code, notes, and snippets.

@prithvihv
Last active May 13, 2021 06:44
Show Gist options
  • Save prithvihv/cdfd4a8a45034ee08077dd959a6aa84e to your computer and use it in GitHub Desktop.
Save prithvihv/cdfd4a8a45034ee08077dd959a6aa84e to your computer and use it in GitHub Desktop.
state pipeline cost calculation
s3CostPerGB:: Double
s3CostPerGB = 0.025 -- per GB
s3SizeWrittenPerDay :: Double
s3SizeWrittenPerDay = 23 -- GB
s3PricePerSession:: Double -- this uses the assumption that of session per day
s3PricePerSession = pricePerDay/requestPerDay
where
pricePerDay = s3SizeWrittenPerDay * s3CostPerGB
hddPricePerSession:: Double
hddPricePerSession = costFor2TBMachine/coldDb2CountOfSessions
where
costFor2TBMachine = 294 :: Double
coldDb2CountOfSessions = 160631316 ::Double
-- Price per sessions
requestPerDay:: Double -- total session in a day
requestPerDay = 50000 * (24 * 60 / 15) -- sessions per day
sessionForXDays:: Double -> Double
sessionForXDays = (requestPerDay *)
stateDataStore :: Double -> Double
stateDataStore = (0.01 *) -- per session in mb (JSON)
costForXDaysS3 :: Double -> Double
costForXDaysS3 days = costToInsert + (costToStore * numberOfMonths)
where
countOfSessions = sessionForXDays days
costToInsert = countOfSessions * (0.005 /1000) -- aws charges 0.005 for 1000 req
numberOfMonths = (fromIntegral . ceiling) $ days / 30
costToStore = countOfSessions * s3PricePerSession
costForXDaysHDD:: Double -> Double
costForXDaysHDD days = costToInsert + (costToStore * numberOfMonths)
where
countOfSessions = sessionForXDays days
costToInsert = 0
costToStore = countOfSessions * hddPricePerSession
numberOfMonths = (fromIntegral . ceiling) $ days / 30
costGraph:: Double -> [(Double,Double,Double,Double)]
costGraph numOfMon =
[ (numOfMonths
, (stateDataStore (sessionForXDays $ numOfMonths * 30))/ 1000 -- in GB
, costForXDaysS3 (numOfMonths * 30)
, costForXDaysHDD (numOfMonths * 30)) | numOfMonths <- [1..numOfMon] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment