module Ecluse.Composition.MemoryPlan (
MemoryPlan (..),
PublishTenant (..),
MirrorArtifactTenant (..),
QueueTenantDemand (..),
queueTenantDemand,
resolveMemoryPlan,
OverridePins,
overrideMinShedSum,
overrideSubstitutions,
attributeOverrideViolations,
planCacheConfig,
mirrorArtifactEnvelopeMultiplier,
mirrorArtifactBytesCap,
) where
import Data.Text qualified as T
import Ecluse.Composition.MirrorQueue (MirrorQueuePlan (MemoryBackend, SqsBackend), MirrorRuntimePlan (MirrorWith, NoMirroring))
import Ecluse.Composition.Sizing (mirrorEnqueueBufferDepth, resolveServeAdmission)
import Ecluse.Config (CacheSettings (..), LimitsSettings (..), QueueSettings (..))
import Ecluse.Core.Server.Cache (CacheConfig (..), StoreBudget (..))
import Ecluse.Core.Server.MemoryModel (contractResidentBytes, expandWireBytes, mirrorJobEstimatedBytes, packumentOriginFanout)
import Ecluse.Rts (EffectiveRuntimePlan (erpAllocAreaBytes), effectiveCapabilities, effectiveHeapCeiling, provenanceClause)
data QueueTenantDemand
=
NoQueueTenant
|
MirroringWithoutMemoryQueue
|
MemoryQueueTenant
deriving stock (QueueTenantDemand -> QueueTenantDemand -> Bool
(QueueTenantDemand -> QueueTenantDemand -> Bool)
-> (QueueTenantDemand -> QueueTenantDemand -> Bool)
-> Eq QueueTenantDemand
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QueueTenantDemand -> QueueTenantDemand -> Bool
== :: QueueTenantDemand -> QueueTenantDemand -> Bool
$c/= :: QueueTenantDemand -> QueueTenantDemand -> Bool
/= :: QueueTenantDemand -> QueueTenantDemand -> Bool
Eq, Int -> QueueTenantDemand -> ShowS
[QueueTenantDemand] -> ShowS
QueueTenantDemand -> String
(Int -> QueueTenantDemand -> ShowS)
-> (QueueTenantDemand -> String)
-> ([QueueTenantDemand] -> ShowS)
-> Show QueueTenantDemand
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QueueTenantDemand -> ShowS
showsPrec :: Int -> QueueTenantDemand -> ShowS
$cshow :: QueueTenantDemand -> String
show :: QueueTenantDemand -> String
$cshowList :: [QueueTenantDemand] -> ShowS
showList :: [QueueTenantDemand] -> ShowS
Show)
queueTenantDemand :: MirrorRuntimePlan -> QueueTenantDemand
queueTenantDemand :: MirrorRuntimePlan -> QueueTenantDemand
queueTenantDemand = \case
MirrorRuntimePlan
NoMirroring -> QueueTenantDemand
NoQueueTenant
MirrorWith (SqsBackend SqsConfig
_) -> QueueTenantDemand
MirroringWithoutMemoryQueue
MirrorWith MirrorQueuePlan
MemoryBackend -> QueueTenantDemand
MemoryQueueTenant
newtype PublishTenant = PublishTenant
{ PublishTenant -> Int
ptAggregateBytes :: Int
}
deriving stock (PublishTenant -> PublishTenant -> Bool
(PublishTenant -> PublishTenant -> Bool)
-> (PublishTenant -> PublishTenant -> Bool) -> Eq PublishTenant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PublishTenant -> PublishTenant -> Bool
== :: PublishTenant -> PublishTenant -> Bool
$c/= :: PublishTenant -> PublishTenant -> Bool
/= :: PublishTenant -> PublishTenant -> Bool
Eq, Int -> PublishTenant -> ShowS
[PublishTenant] -> ShowS
PublishTenant -> String
(Int -> PublishTenant -> ShowS)
-> (PublishTenant -> String)
-> ([PublishTenant] -> ShowS)
-> Show PublishTenant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PublishTenant -> ShowS
showsPrec :: Int -> PublishTenant -> ShowS
$cshow :: PublishTenant -> String
show :: PublishTenant -> String
$cshowList :: [PublishTenant] -> ShowS
showList :: [PublishTenant] -> ShowS
Show)
newtype MirrorArtifactTenant = MirrorArtifactTenant
{ MirrorArtifactTenant -> Int
matMaxBytes :: Int
}
deriving stock (MirrorArtifactTenant -> MirrorArtifactTenant -> Bool
(MirrorArtifactTenant -> MirrorArtifactTenant -> Bool)
-> (MirrorArtifactTenant -> MirrorArtifactTenant -> Bool)
-> Eq MirrorArtifactTenant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MirrorArtifactTenant -> MirrorArtifactTenant -> Bool
== :: MirrorArtifactTenant -> MirrorArtifactTenant -> Bool
$c/= :: MirrorArtifactTenant -> MirrorArtifactTenant -> Bool
/= :: MirrorArtifactTenant -> MirrorArtifactTenant -> Bool
Eq, Int -> MirrorArtifactTenant -> ShowS
[MirrorArtifactTenant] -> ShowS
MirrorArtifactTenant -> String
(Int -> MirrorArtifactTenant -> ShowS)
-> (MirrorArtifactTenant -> String)
-> ([MirrorArtifactTenant] -> ShowS)
-> Show MirrorArtifactTenant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MirrorArtifactTenant -> ShowS
showsPrec :: Int -> MirrorArtifactTenant -> ShowS
$cshow :: MirrorArtifactTenant -> String
show :: MirrorArtifactTenant -> String
$cshowList :: [MirrorArtifactTenant] -> ShowS
showList :: [MirrorArtifactTenant] -> ShowS
Show)
data MemoryPlan = MemoryPlan
{ MemoryPlan -> Int
mpRuntimeReserveBytes :: Int
, MemoryPlan -> Int
mpCacheAggregateBytes :: Int
, MemoryPlan -> Int
mpCacheMaxEntries :: Int
, MemoryPlan -> Int
mpMaterialAggregateBytes :: Int
, MemoryPlan -> Int
mpMaxResponseBytes :: Int
, MemoryPlan -> Int
mpMaxRequestBytes :: Int
, MemoryPlan -> Int
mpAdmissionCapacity :: Int
, MemoryPlan -> Maybe Int
mpShedCapabilities :: Maybe Int
, MemoryPlan -> Maybe PublishTenant
mpPublishTenant :: Maybe PublishTenant
, MemoryPlan -> Maybe MirrorArtifactTenant
mpMirrorArtifactTenant :: Maybe MirrorArtifactTenant
, MemoryPlan -> Int
mpQueueMemoryMaxDepth :: Int
, MemoryPlan -> Int
mpQueueTenantBytes :: Int
, MemoryPlan -> Int
mpFixedBufferBytes :: Int
, MemoryPlan -> [Text]
mpDegradations :: [Text]
, MemoryPlan -> [Text]
mpOverrideViolations :: [Text]
}
deriving stock (MemoryPlan -> MemoryPlan -> Bool
(MemoryPlan -> MemoryPlan -> Bool)
-> (MemoryPlan -> MemoryPlan -> Bool) -> Eq MemoryPlan
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MemoryPlan -> MemoryPlan -> Bool
== :: MemoryPlan -> MemoryPlan -> Bool
$c/= :: MemoryPlan -> MemoryPlan -> Bool
/= :: MemoryPlan -> MemoryPlan -> Bool
Eq, Int -> MemoryPlan -> ShowS
[MemoryPlan] -> ShowS
MemoryPlan -> String
(Int -> MemoryPlan -> ShowS)
-> (MemoryPlan -> String)
-> ([MemoryPlan] -> ShowS)
-> Show MemoryPlan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MemoryPlan -> ShowS
showsPrec :: Int -> MemoryPlan -> ShowS
$cshow :: MemoryPlan -> String
show :: MemoryPlan -> String
$cshowList :: [MemoryPlan] -> ShowS
showList :: [MemoryPlan] -> ShowS
Show)
resolveMemoryPlan ::
CacheSettings ->
LimitsSettings ->
QueueSettings ->
Maybe Int ->
EffectiveRuntimePlan ->
QueueTenantDemand ->
Bool ->
(MemoryPlan, [Text])
resolveMemoryPlan :: CacheSettings
-> LimitsSettings
-> QueueSettings
-> Maybe Int
-> EffectiveRuntimePlan
-> QueueTenantDemand
-> Bool
-> (MemoryPlan, [Text])
resolveMemoryPlan CacheSettings
cacheSettings LimitsSettings
limitsSettings QueueSettings
queueSettings Maybe Int
explicitAdmission EffectiveRuntimePlan
runtime QueueTenantDemand
queueDemand Bool
publishConfigured =
(MemoryPlan, [Text])
-> (Int -> (MemoryPlan, [Text]))
-> Maybe Int
-> (MemoryPlan, [Text])
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
(CacheSettings
-> LimitsSettings
-> QueueSettings
-> Int
-> Text
-> QueueTenantDemand
-> Bool
-> Int
-> (MemoryPlan, [Text])
fallbackPlan CacheSettings
cacheSettings LimitsSettings
limitsSettings QueueSettings
queueSettings Int
cpuAdmission Text
cpuAdmissionLine QueueTenantDemand
queueDemand Bool
publishConfigured Int
fixedBuffers)
Int -> (MemoryPlan, [Text])
solvedPlan
Maybe Int
heapCeiling
where
(Maybe Int
heapCeiling, Provenance
ceilingProvenance) = EffectiveRuntimePlan -> (Maybe Int, Provenance)
effectiveHeapCeiling EffectiveRuntimePlan
runtime
(Int
capabilities, Provenance
_) = EffectiveRuntimePlan -> (Int, Provenance)
effectiveCapabilities EffectiveRuntimePlan
runtime
(Int
cpuAdmission, Text
cpuAdmissionLine) = Maybe Int -> Int -> (Int, Text)
resolveServeAdmission Maybe Int
explicitAdmission Int
capabilities
fixedBuffers :: Int
fixedBuffers = case QueueTenantDemand
queueDemand of
QueueTenantDemand
NoQueueTenant -> Int
0
QueueTenantDemand
_ -> Int
mirrorEnqueueBufferDepth Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mirrorJobEstimatedBytes
memoryBacked :: Bool
memoryBacked = QueueTenantDemand
queueDemand QueueTenantDemand -> QueueTenantDemand -> Bool
forall a. Eq a => a -> a -> Bool
== QueueTenantDemand
MemoryQueueTenant
mirrors :: Bool
mirrors = QueueTenantDemand
queueDemand QueueTenantDemand -> QueueTenantDemand -> Bool
forall a. Eq a => a -> a -> Bool
/= QueueTenantDemand
NoQueueTenant
solvedPlan :: Int -> (MemoryPlan, [Text])
solvedPlan :: Int -> (MemoryPlan, [Text])
solvedPlan Int
h =
( MemoryPlan
{ mpRuntimeReserveBytes :: Int
mpRuntimeReserveBytes = Int
reserve
, mpCacheAggregateBytes :: Int
mpCacheAggregateBytes = ShedOutcomes -> Int
soCacheFinal ShedOutcomes
outcomes
, mpCacheMaxEntries :: Int
mpCacheMaxEntries = Int
cacheEntries
, mpMaterialAggregateBytes :: Int
mpMaterialAggregateBytes = ShedOutcomes -> Int
soMaterialFinal ShedOutcomes
outcomes
, mpMaxResponseBytes :: Int
mpMaxResponseBytes = ShedOutcomes -> Int
soResponseFinal ShedOutcomes
outcomes
, mpMaxRequestBytes :: Int
mpMaxRequestBytes = Int
requestFinal
, mpAdmissionCapacity :: Int
mpAdmissionCapacity = ShedOutcomes -> Int
soAdmissionFinal ShedOutcomes
outcomes
, mpShedCapabilities :: Maybe Int
mpShedCapabilities = Maybe Int
shedCaps
, mpPublishTenant :: Maybe PublishTenant
mpPublishTenant = Maybe PublishTenant
publishTenant
, mpMirrorArtifactTenant :: Maybe MirrorArtifactTenant
mpMirrorArtifactTenant = Maybe MirrorArtifactTenant
mirrorArtifactTenant
, mpQueueMemoryMaxDepth :: Int
mpQueueMemoryMaxDepth = ShedOutcomes -> Int
soDepthFinal ShedOutcomes
outcomes
, mpQueueTenantBytes :: Int
mpQueueTenantBytes = ShedOutcomes -> Int
soQueueTenantBytes ShedOutcomes
outcomes
, mpFixedBufferBytes :: Int
mpFixedBufferBytes = Int
fixedBuffers
, mpDegradations :: [Text]
mpDegradations = TenantDemands
-> ShedOutcomes -> Int -> Int -> Maybe Int -> Int -> [Text]
renderDegradations TenantDemands
demands ShedOutcomes
outcomes Int
capabilities Int
allocArea Maybe Int
shedCaps Int
overshootWithoutOverrides
, mpOverrideViolations :: [Text]
mpOverrideViolations = [Text]
overrideViolations
}
, TenantDemands
-> ShedOutcomes
-> Text
-> Text
-> Int
-> Bool
-> Maybe PublishTenant
-> Maybe MirrorArtifactTenant
-> [Text]
renderPlanLines TenantDemands
demands ShedOutcomes
outcomes Text
ceilingClause Text
cpuAdmissionLine Int
cacheEntries (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (CacheSettings -> Maybe Int
csMaxEntries CacheSettings
cacheSettings)) Maybe PublishTenant
publishTenant Maybe MirrorArtifactTenant
mirrorArtifactTenant
)
where
reserve :: Int
reserve = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
runtimeReserveFloorBytes (Int
h Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
runtimeReserveShareDiv)
appHeap :: Int
appHeap = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
h Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
reserve)
cacheExplicit :: Maybe Int
cacheExplicit = CacheSettings -> Maybe Int
csMaxBytes CacheSettings
cacheSettings
cacheDesired :: Int
cacheDesired = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe (Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
cacheBytesFloor Int
cacheBytesCap (Int
appHeap Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
cacheSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100)) Maybe Int
cacheExplicit
requestExplicit :: Maybe Int
requestExplicit = LimitsSettings -> Maybe Int
limMaxRequestBytes LimitsSettings
limitsSettings
computedRequestDefault :: Int
computedRequestDefault = Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
requestBytesFloor Int
requestBytesCap (Int
appHeap Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
publishSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100)
requestFinal :: Int
requestFinal = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
computedRequestDefault Maybe Int
requestExplicit
publishDesired :: Int
publishDesired = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
requestFinal (Int
appHeap Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
publishSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100)
responseExplicit :: Maybe Int
responseExplicit = LimitsSettings -> Maybe Int
limMaxResponseBytes LimitsSettings
limitsSettings
materialShareBytes :: Int
materialShareBytes = Int
appHeap Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
materialSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100
admissionMemBound :: Int
admissionMemBound = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int
materialShareBytes Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int -> Int
envelope Int
responseBytesFloor)
admissionDesired :: Int
admissionDesired = case Maybe Int
explicitAdmission of
Just Int
n -> Int
n
Maybe Int
Nothing -> Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
cpuAdmission Int
admissionMemBound)
responseDesired :: Int
responseDesired =
Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe
(Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
responseBytesFloor Int
responseBytesCap (Int -> Int
contractResidentBytes (Int
materialShareBytes Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int
admissionDesired Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
packumentOriginFanout))))
Maybe Int
responseExplicit
materialDesired :: Int
materialDesired = Int -> Int -> Int
materialOf Int
admissionDesired Int
responseDesired
materialMinimum :: Int
materialMinimum = Int -> Int -> Int
materialOf (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
1 Maybe Int
explicitAdmission) (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
responseBytesFloor Maybe Int
responseExplicit)
depthExplicit :: Maybe Int
depthExplicit = QueueSettings -> Maybe Int
qsMemoryMaxDepth QueueSettings
queueSettings
depthDesired :: Int
depthDesired = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe (Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
queueDepthFloor Int
queueDepthCap ((Int
appHeap Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
queueSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
mirrorJobEstimatedBytes)) Maybe Int
depthExplicit
artifactExplicit :: Maybe Int
artifactExplicit = LimitsSettings -> Maybe Int
limMaxArtifactBytes LimitsSettings
limitsSettings
artifactCapDesired :: Int
artifactCapDesired =
Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe
(Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
mirrorArtifactBytesCap ((Int
appHeap Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mirrorArtifactSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
mirrorArtifactEnvelopeMultiplier))
Maybe Int
artifactExplicit
mirrorChargeDesired :: Int
mirrorChargeDesired = if Bool
mirrors then Int
artifactCapDesired Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mirrorArtifactEnvelopeMultiplier else Int
0
demands :: TenantDemands
demands =
TenantDemands
{ tdCeiling :: Int
tdCeiling = Int
h
, tdReserve :: Int
tdReserve = Int
reserve
, tdFixedBuffers :: Int
tdFixedBuffers = Int
fixedBuffers
, tdCacheDesired :: Int
tdCacheDesired = Int
cacheDesired
, tdCacheExplicit :: Maybe Int
tdCacheExplicit = Maybe Int
cacheExplicit
, tdMaterialDesired :: Int
tdMaterialDesired = Int
materialDesired
, tdMaterialMinimum :: Int
tdMaterialMinimum = Int
materialMinimum
, tdAdmissionDesired :: Int
tdAdmissionDesired = Int
admissionDesired
, tdAdmissionExplicit :: Maybe Int
tdAdmissionExplicit = Maybe Int
explicitAdmission
, tdResponseExplicit :: Maybe Int
tdResponseExplicit = Maybe Int
responseExplicit
, tdPublishConfigured :: Bool
tdPublishConfigured = Bool
publishConfigured
, tdPublishDesired :: Int
tdPublishDesired = Int
publishDesired
, tdRequestFinal :: Int
tdRequestFinal = Int
requestFinal
, tdRequestExplicit :: Maybe Int
tdRequestExplicit = Maybe Int
requestExplicit
, tdDepthDesired :: Int
tdDepthDesired = Int
depthDesired
, tdDepthExplicit :: Maybe Int
tdDepthExplicit = Maybe Int
depthExplicit
, tdMemoryBacked :: Bool
tdMemoryBacked = Bool
memoryBacked
, tdMirrors :: Bool
tdMirrors = Bool
mirrors
, tdArtifactCapDesired :: Int
tdArtifactCapDesired = Int
artifactCapDesired
, tdMirrorChargeDesired :: Int
tdMirrorChargeDesired = Int
mirrorChargeDesired
, tdArtifactExplicit :: Maybe Int
tdArtifactExplicit = Maybe Int
artifactExplicit
}
outcomes :: ShedOutcomes
outcomes = TenantDemands -> ShedOutcomes
shedToFit TenantDemands
demands
allocArea :: Int
allocArea = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (EffectiveRuntimePlan -> Int
erpAllocAreaBytes EffectiveRuntimePlan
runtime)
shedCaps :: Maybe Int
shedCaps = Int -> Int -> Int -> Maybe Int
shedCapabilityCount Int
h Int
capabilities Int
allocArea
publishTenant :: Maybe PublishTenant
publishTenant = [PublishTenant] -> Maybe PublishTenant
forall a. [a] -> Maybe a
listToMaybe [PublishTenant{ptAggregateBytes :: Int
ptAggregateBytes = ShedOutcomes -> Int
soPublishFinal ShedOutcomes
outcomes} | Bool
publishConfigured]
mirrorArtifactTenant :: Maybe MirrorArtifactTenant
mirrorArtifactTenant =
[MirrorArtifactTenant] -> Maybe MirrorArtifactTenant
forall a. [a] -> Maybe a
listToMaybe [MirrorArtifactTenant{matMaxBytes :: Int
matMaxBytes = ShedOutcomes -> Int
soArtifactCapFinal ShedOutcomes
outcomes} | Bool
mirrors]
cacheEntries :: Int
cacheEntries = case CacheSettings -> Maybe Int
csMaxEntries CacheSettings
cacheSettings of
Just Int
n -> Int
n
Maybe Int
Nothing -> Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
cacheEntriesFloor Int
cacheEntriesCap (ShedOutcomes -> Int
soCacheFinal ShedOutcomes
outcomes Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
cacheEntryExpectedBytes)
ceilingClause :: Text
ceilingClause = Provenance -> Text
provenanceClause Provenance
ceilingProvenance
actualPins :: (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
actualPins = (Maybe Int
cacheExplicit, Maybe Int
explicitAdmission, Maybe Int
responseExplicit, Maybe Int
requestExplicit, Maybe Int
depthExplicit, Maybe Int
artifactExplicit)
overshootFor :: (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
-> Int
overshootFor (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
pins =
Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
-> Int
-> Bool
-> Bool
-> Bool
-> (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int,
Maybe Int)
-> Int
overrideMinShedSum (Int
reserve Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
fixedBuffers) Int
computedRequestDefault Bool
publishConfigured Bool
memoryBacked Bool
mirrors (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
pins Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
h)
overshootWithoutOverrides :: Int
overshootWithoutOverrides = (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
-> Int
overshootFor (Maybe Int
forall a. Maybe a
Nothing, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
forall a. Maybe a
Nothing)
overrideViolations :: [Text]
overrideViolations =
Int -> Int -> Int -> [(Text, Int)] -> [Text]
attributeOverrideViolations
Int
h
(ShedOutcomes -> Int
soResidualOvershoot ShedOutcomes
outcomes)
Int
overshootWithoutOverrides
[(Text
name, (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
-> Int
overshootFor (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
pins) | (Text
name, (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
pins) <- (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
-> [(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int,
Maybe Int))]
overrideSubstitutions (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
actualPins]
envelope :: Int -> Int
envelope :: Int -> Int
envelope Int
r = Int
packumentOriginFanout Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int -> Int
expandWireBytes Int
r
materialOf :: Int -> Int -> Int
materialOf :: Int -> Int -> Int
materialOf Int
a Int
r = Int
a Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int -> Int
envelope Int
r
queueCharge :: Bool -> Int -> Int
queueCharge :: Bool -> Int -> Int
queueCharge Bool
memoryBacked Int
d = if Bool
memoryBacked then Int
d Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mirrorJobEstimatedBytes else Int
0
clamp :: (Ord a) => a -> a -> a -> a
clamp :: forall a. Ord a => a -> a -> a -> a
clamp a
lo a
hi = a -> a -> a
forall a. Ord a => a -> a -> a
max a
lo (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> a
forall a. Ord a => a -> a -> a
min a
hi
fallbackPlan ::
CacheSettings ->
LimitsSettings ->
QueueSettings ->
Int ->
Text ->
QueueTenantDemand ->
Bool ->
Int ->
(MemoryPlan, [Text])
fallbackPlan :: CacheSettings
-> LimitsSettings
-> QueueSettings
-> Int
-> Text
-> QueueTenantDemand
-> Bool
-> Int
-> (MemoryPlan, [Text])
fallbackPlan CacheSettings
cacheSettings LimitsSettings
limitsSettings QueueSettings
queueSettings Int
cpuAdmission Text
cpuAdmissionLine QueueTenantDemand
queueDemand Bool
publishConfigured Int
fixedBuffers =
( MemoryPlan
{ mpRuntimeReserveBytes :: Int
mpRuntimeReserveBytes = Int
0
, mpCacheAggregateBytes :: Int
mpCacheAggregateBytes = Int
cacheBytes
, mpCacheMaxEntries :: Int
mpCacheMaxEntries = Int
cacheEntries
, mpMaterialAggregateBytes :: Int
mpMaterialAggregateBytes = Int
0
, mpMaxResponseBytes :: Int
mpMaxResponseBytes = Int
responseBytes
, mpMaxRequestBytes :: Int
mpMaxRequestBytes = Int
requestBytes
, mpAdmissionCapacity :: Int
mpAdmissionCapacity = Int
cpuAdmission
, mpShedCapabilities :: Maybe Int
mpShedCapabilities = Maybe Int
forall a. Maybe a
Nothing
, mpPublishTenant :: Maybe PublishTenant
mpPublishTenant = Maybe PublishTenant
publishTenant
, mpMirrorArtifactTenant :: Maybe MirrorArtifactTenant
mpMirrorArtifactTenant = Maybe MirrorArtifactTenant
mirrorArtifactTenant
, mpQueueMemoryMaxDepth :: Int
mpQueueMemoryMaxDepth = Int
queueDepth
, mpQueueTenantBytes :: Int
mpQueueTenantBytes = Bool -> Int -> Int
queueCharge (QueueTenantDemand
queueDemand QueueTenantDemand -> QueueTenantDemand -> Bool
forall a. Eq a => a -> a -> Bool
== QueueTenantDemand
MemoryQueueTenant) Int
queueDepth
, mpFixedBufferBytes :: Int
mpFixedBufferBytes = Int
fixedBuffers
, mpDegradations :: [Text]
mpDegradations = []
, mpOverrideViolations :: [Text]
mpOverrideViolations = []
}
, [Text
cpuAdmissionLine, Text
responseLine, Text
requestLine, Text
cacheBytesLine, Text
cacheEntriesLine, Text
queueDepthLine]
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text
artifactLine | Bool
mirrors]
)
where
mirrors :: Bool
mirrors = QueueTenantDemand
queueDemand QueueTenantDemand -> QueueTenantDemand -> Bool
forall a. Eq a => a -> a -> Bool
/= QueueTenantDemand
NoQueueTenant
(Int
responseBytes, Text
responseLine) = Text -> Maybe Int -> Int -> (Int, Text)
forall {b} {a}.
(Semigroup b, IsString b, Show a) =>
b -> Maybe a -> a -> (a, b)
fallbackOr Text
"response byte cap" (LimitsSettings -> Maybe Int
limMaxResponseBytes LimitsSettings
limitsSettings) Int
responseBytesFallback
(Int
requestBytes, Text
requestLine) = Text -> Maybe Int -> Int -> (Int, Text)
forall {b} {a}.
(Semigroup b, IsString b, Show a) =>
b -> Maybe a -> a -> (a, b)
fallbackOr Text
"request byte cap" (LimitsSettings -> Maybe Int
limMaxRequestBytes LimitsSettings
limitsSettings) Int
requestBytesFallback
(Int
cacheBytes, Text
cacheBytesLine) = Text -> Maybe Int -> Int -> (Int, Text)
forall {b} {a}.
(Semigroup b, IsString b, Show a) =>
b -> Maybe a -> a -> (a, b)
fallbackOr Text
"cache byte bound" (CacheSettings -> Maybe Int
csMaxBytes CacheSettings
cacheSettings) Int
cacheBytesFallback
(Int
cacheEntries, Text
cacheEntriesLine) = Text -> Maybe Int -> Int -> (Int, Text)
forall {b} {a}.
(Semigroup b, IsString b, Show a) =>
b -> Maybe a -> a -> (a, b)
fallbackOr Text
"cache entry bound" (CacheSettings -> Maybe Int
csMaxEntries CacheSettings
cacheSettings) (Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
cacheEntriesFloor Int
cacheEntriesCap (Int
cacheBytes Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
cacheEntryExpectedBytes))
(Int
queueDepth, Text
queueDepthLine) = Text -> Maybe Int -> Int -> (Int, Text)
forall {b} {a}.
(Semigroup b, IsString b, Show a) =>
b -> Maybe a -> a -> (a, b)
fallbackOr Text
"memory-queue depth" (QueueSettings -> Maybe Int
qsMemoryMaxDepth QueueSettings
queueSettings) Int
queueDepthFallback
(Int
artifactBytes, Text
artifactLine) = Text -> Maybe Int -> Int -> (Int, Text)
forall {b} {a}.
(Semigroup b, IsString b, Show a) =>
b -> Maybe a -> a -> (a, b)
fallbackOr Text
"mirror artifact byte cap" (LimitsSettings -> Maybe Int
limMaxArtifactBytes LimitsSettings
limitsSettings) Int
mirrorArtifactBytesCap
publishTenant :: Maybe PublishTenant
publishTenant = [PublishTenant] -> Maybe PublishTenant
forall a. [a] -> Maybe a
listToMaybe [PublishTenant{ptAggregateBytes :: Int
ptAggregateBytes = Int
publishAggregateFallbackRequests Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
requestBytes} | Bool
publishConfigured]
mirrorArtifactTenant :: Maybe MirrorArtifactTenant
mirrorArtifactTenant =
[MirrorArtifactTenant] -> Maybe MirrorArtifactTenant
forall a. [a] -> Maybe a
listToMaybe [MirrorArtifactTenant{matMaxBytes :: Int
matMaxBytes = Int
artifactBytes} | Bool
mirrors]
fallbackOr :: b -> Maybe a -> a -> (a, b)
fallbackOr b
name Maybe a
explicit a
fallback = case Maybe a
explicit of
Just a
n -> (a
n, b
"memory plan: " b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
name b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
" " b -> b -> b
forall a. Semigroup a => a -> a -> a
<> a -> b
forall b a. (Show a, IsString b) => a -> b
show a
n b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
" (from config)")
Maybe a
Nothing -> (a
fallback, b
"memory plan: " b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
name b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
" " b -> b -> b
forall a. Semigroup a => a -> a -> a
<> a -> b
forall b a. (Show a, IsString b) => a -> b
show a
fallback b -> b -> b
forall a. Semigroup a => a -> a -> a
<> b
" (built-in default; no heap-ceiling datapoint)")
data TenantDemands = TenantDemands
{ TenantDemands -> Int
tdCeiling :: Int
, TenantDemands -> Int
tdReserve :: Int
, TenantDemands -> Int
tdFixedBuffers :: Int
, TenantDemands -> Int
tdCacheDesired :: Int
, TenantDemands -> Maybe Int
tdCacheExplicit :: Maybe Int
, TenantDemands -> Int
tdMaterialDesired :: Int
, TenantDemands -> Int
tdMaterialMinimum :: Int
, TenantDemands -> Int
tdAdmissionDesired :: Int
, TenantDemands -> Maybe Int
tdAdmissionExplicit :: Maybe Int
, TenantDemands -> Maybe Int
tdResponseExplicit :: Maybe Int
, TenantDemands -> Bool
tdPublishConfigured :: Bool
, TenantDemands -> Int
tdPublishDesired :: Int
, TenantDemands -> Int
tdRequestFinal :: Int
, TenantDemands -> Maybe Int
tdRequestExplicit :: Maybe Int
, TenantDemands -> Int
tdDepthDesired :: Int
, TenantDemands -> Maybe Int
tdDepthExplicit :: Maybe Int
, TenantDemands -> Bool
tdMemoryBacked :: Bool
, TenantDemands -> Bool
tdMirrors :: Bool
, TenantDemands -> Int
tdArtifactCapDesired :: Int
, TenantDemands -> Int
tdMirrorChargeDesired :: Int
, TenantDemands -> Maybe Int
tdArtifactExplicit :: Maybe Int
}
data ShedOutcomes = ShedOutcomes
{ ShedOutcomes -> Int
soMirrorShed :: Int
, ShedOutcomes -> Int
soArtifactCapFinal :: Int
, ShedOutcomes -> Int
soCacheShed :: Int
, ShedOutcomes -> Int
soCacheFinal :: Int
, ShedOutcomes -> Int
soMaterialShed :: Int
, ShedOutcomes -> Int
soMaterialFinal :: Int
, ShedOutcomes -> Int
soAdmissionFinal :: Int
, ShedOutcomes -> Int
soResponseFinal :: Int
, ShedOutcomes -> Int
soPublishShed :: Int
, ShedOutcomes -> Int
soPublishFinal :: Int
, ShedOutcomes -> Int
soQueueShedBytes :: Int
, ShedOutcomes -> Int
soDepthFinal :: Int
, ShedOutcomes -> Int
soQueueTenantBytes :: Int
, ShedOutcomes -> Int
soResidualOvershoot :: Int
}
data ShedStep = ShedStep
{ ShedStep -> Int
stepShed :: Int
, ShedStep -> Int
stepFinal :: Int
, ShedStep -> Int
stepResidual :: Int
}
shedStep :: Int -> Int -> Int -> ShedStep
shedStep :: Int -> Int -> Int -> ShedStep
shedStep Int
overshoot Int
desired Int
reclaimable =
ShedStep{stepShed :: Int
stepShed = Int
shed, stepFinal :: Int
stepFinal = Int
desired Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
shed, stepResidual :: Int
stepResidual = Int
overshoot Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
shed}
where
shed :: Int
shed = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
overshoot Int
reclaimable
shedMirrorStep :: Int -> Int -> Maybe Int -> ShedStep
shedMirrorStep :: Int -> Int -> Maybe Int -> ShedStep
shedMirrorStep Int
overshoot Int
mirrorDesired Maybe Int
artifactExplicit =
Int -> Int -> Int -> ShedStep
shedStep Int
overshoot Int
mirrorDesired (if Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust Maybe Int
artifactExplicit then Int
0 else Int
mirrorDesired)
shedCacheStep :: Int -> Int -> Maybe Int -> ShedStep
shedCacheStep :: Int -> Int -> Maybe Int -> ShedStep
shedCacheStep Int
overshoot Int
cacheDesired Maybe Int
cacheExplicit =
Int -> Int -> Int -> ShedStep
shedStep Int
overshoot Int
cacheDesired (if Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust Maybe Int
cacheExplicit then Int
0 else Int
cacheDesired)
data MaterialOutcome = MaterialOutcome
{ MaterialOutcome -> ShedStep
moStep :: ShedStep
, MaterialOutcome -> Int
moAdmission :: Int
, MaterialOutcome -> Int
moResponse :: Int
}
shedMaterialStep :: Int -> Int -> Int -> Int -> Maybe Int -> Maybe Int -> MaterialOutcome
shedMaterialStep :: Int
-> Int -> Int -> Int -> Maybe Int -> Maybe Int -> MaterialOutcome
shedMaterialStep Int
overshoot Int
materialDesired Int
materialMinimum Int
admissionDesired Maybe Int
explicitAdmission Maybe Int
responseExplicit =
MaterialOutcome{moStep :: ShedStep
moStep = ShedStep
step, moAdmission :: Int
moAdmission = Int
admissionFinal, moResponse :: Int
moResponse = Int
responseFinal}
where
step :: ShedStep
step = Int -> Int -> Int -> ShedStep
shedStep Int
overshoot Int
materialDesired (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
materialDesired Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
materialMinimum))
materialFinal :: Int
materialFinal = ShedStep -> Int
stepFinal ShedStep
step
admissionFinal :: Int
admissionFinal = case Maybe Int
explicitAdmission of
Just Int
n -> Int
n
Maybe Int
Nothing -> Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
admissionDesired (Int
materialFinal Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int -> Int
envelope (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
responseBytesFloor Maybe Int
responseExplicit)))
responseFinal :: Int
responseFinal = case Maybe Int
responseExplicit of
Just Int
r -> Int
r
Maybe Int
Nothing -> Int -> Int -> Int -> Int
forall a. Ord a => a -> a -> a -> a
clamp Int
responseBytesFloor Int
responseBytesCap (Int -> Int
contractResidentBytes (Int
materialFinal Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 (Int
admissionFinal Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
packumentOriginFanout)))
shedPublishStep :: Int -> Bool -> Int -> Int -> ShedStep
shedPublishStep :: Int -> Bool -> Int -> Int -> ShedStep
shedPublishStep Int
overshoot Bool
publishConfigured Int
publishDesired Int
requestFloor =
Int -> Int -> Int -> ShedStep
shedStep Int
overshoot Int
publishDesired (if Bool
publishConfigured then Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
publishDesired Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
requestFloor) else Int
0)
data QueueOutcome = QueueOutcome
{ QueueOutcome -> Int
qoShed :: Int
, QueueOutcome -> Int
qoDepthFinal :: Int
, QueueOutcome -> Int
qoTenantBytes :: Int
, QueueOutcome -> Int
qoResidual :: Int
}
shedQueueStep :: Int -> Bool -> Int -> Maybe Int -> QueueOutcome
shedQueueStep :: Int -> Bool -> Int -> Maybe Int -> QueueOutcome
shedQueueStep Int
overshoot Bool
memoryBacked Int
depthDesired Maybe Int
depthExplicit =
QueueOutcome
{ qoShed :: Int
qoShed = Int
queueShedBytes
, qoDepthFinal :: Int
qoDepthFinal = Int
depthFinal
, qoTenantBytes :: Int
qoTenantBytes = Int -> Int
charge Int
depthFinal
, qoResidual :: Int
qoResidual = Int
overshoot Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
queueShedBytes
}
where
charge :: Int -> Int
charge = Bool -> Int -> Int
queueCharge Bool
memoryBacked
depthReclaimableBytes :: Int
depthReclaimableBytes = case Maybe Int
depthExplicit of
Just Int
_ -> Int
0
Maybe Int
Nothing -> Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int
charge Int
depthDesired Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int
charge Int
queueDepthFloor)
queueShedBytes :: Int
queueShedBytes = Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
overshoot Int
depthReclaimableBytes
depthFinal :: Int
depthFinal = case Maybe Int
depthExplicit of
Just Int
n -> Int
n
Maybe Int
Nothing
| Int
queueShedBytes Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 -> Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
queueDepthFloor ((Int -> Int
charge Int
depthDesired Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
queueShedBytes) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
mirrorJobEstimatedBytes)
| Bool
otherwise -> Int
depthDesired
shedToFit :: TenantDemands -> ShedOutcomes
shedToFit :: TenantDemands -> ShedOutcomes
shedToFit TenantDemands
d =
ShedOutcomes
{ soMirrorShed :: Int
soMirrorShed = ShedStep -> Int
stepShed ShedStep
mirrorStep
, soArtifactCapFinal :: Int
soArtifactCapFinal = Int
artifactCapFinal
, soCacheShed :: Int
soCacheShed = ShedStep -> Int
stepShed ShedStep
cacheStep
, soCacheFinal :: Int
soCacheFinal = ShedStep -> Int
stepFinal ShedStep
cacheStep
, soMaterialShed :: Int
soMaterialShed = ShedStep -> Int
stepShed ShedStep
materialStep
, soMaterialFinal :: Int
soMaterialFinal = ShedStep -> Int
stepFinal ShedStep
materialStep
, soAdmissionFinal :: Int
soAdmissionFinal = MaterialOutcome -> Int
moAdmission MaterialOutcome
material
, soResponseFinal :: Int
soResponseFinal = MaterialOutcome -> Int
moResponse MaterialOutcome
material
, soPublishShed :: Int
soPublishShed = ShedStep -> Int
stepShed ShedStep
publishStep
, soPublishFinal :: Int
soPublishFinal = ShedStep -> Int
stepFinal ShedStep
publishStep
, soQueueShedBytes :: Int
soQueueShedBytes = QueueOutcome -> Int
qoShed QueueOutcome
queue
, soDepthFinal :: Int
soDepthFinal = QueueOutcome -> Int
qoDepthFinal QueueOutcome
queue
, soQueueTenantBytes :: Int
soQueueTenantBytes = QueueOutcome -> Int
qoTenantBytes QueueOutcome
queue
, soResidualOvershoot :: Int
soResidualOvershoot = QueueOutcome -> Int
qoResidual QueueOutcome
queue
}
where
publishCharge :: Int
publishCharge = if TenantDemands -> Bool
tdPublishConfigured TenantDemands
d then TenantDemands -> Int
tdPublishDesired TenantDemands
d else Int
0
desiredSum :: Int
desiredSum =
TenantDemands -> Int
tdReserve TenantDemands
d
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TenantDemands -> Int
tdFixedBuffers TenantDemands
d
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TenantDemands -> Int
tdMirrorChargeDesired TenantDemands
d
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TenantDemands -> Int
tdCacheDesired TenantDemands
d
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TenantDemands -> Int
tdMaterialDesired TenantDemands
d
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
publishCharge
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Bool -> Int -> Int
queueCharge (TenantDemands -> Bool
tdMemoryBacked TenantDemands
d) (TenantDemands -> Int
tdDepthDesired TenantDemands
d)
overshoot0 :: Int
overshoot0 = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
desiredSum Int -> Int -> Int
forall a. Num a => a -> a -> a
- TenantDemands -> Int
tdCeiling TenantDemands
d)
mirrorStep :: ShedStep
mirrorStep = Int -> Int -> Maybe Int -> ShedStep
shedMirrorStep Int
overshoot0 (TenantDemands -> Int
tdMirrorChargeDesired TenantDemands
d) (TenantDemands -> Maybe Int
tdArtifactExplicit TenantDemands
d)
artifactCapFinal :: Int
artifactCapFinal = case TenantDemands -> Maybe Int
tdArtifactExplicit TenantDemands
d of
Just Int
n -> Int
n
Maybe Int
Nothing -> ShedStep -> Int
stepFinal ShedStep
mirrorStep Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
mirrorArtifactEnvelopeMultiplier
cacheStep :: ShedStep
cacheStep = Int -> Int -> Maybe Int -> ShedStep
shedCacheStep (ShedStep -> Int
stepResidual ShedStep
mirrorStep) (TenantDemands -> Int
tdCacheDesired TenantDemands
d) (TenantDemands -> Maybe Int
tdCacheExplicit TenantDemands
d)
material :: MaterialOutcome
material =
Int
-> Int -> Int -> Int -> Maybe Int -> Maybe Int -> MaterialOutcome
shedMaterialStep
(ShedStep -> Int
stepResidual ShedStep
cacheStep)
(TenantDemands -> Int
tdMaterialDesired TenantDemands
d)
(TenantDemands -> Int
tdMaterialMinimum TenantDemands
d)
(TenantDemands -> Int
tdAdmissionDesired TenantDemands
d)
(TenantDemands -> Maybe Int
tdAdmissionExplicit TenantDemands
d)
(TenantDemands -> Maybe Int
tdResponseExplicit TenantDemands
d)
materialStep :: ShedStep
materialStep = MaterialOutcome -> ShedStep
moStep MaterialOutcome
material
publishStep :: ShedStep
publishStep = Int -> Bool -> Int -> Int -> ShedStep
shedPublishStep (ShedStep -> Int
stepResidual ShedStep
materialStep) (TenantDemands -> Bool
tdPublishConfigured TenantDemands
d) (TenantDemands -> Int
tdPublishDesired TenantDemands
d) (TenantDemands -> Int
tdRequestFinal TenantDemands
d)
queue :: QueueOutcome
queue = Int -> Bool -> Int -> Maybe Int -> QueueOutcome
shedQueueStep (ShedStep -> Int
stepResidual ShedStep
publishStep) (TenantDemands -> Bool
tdMemoryBacked TenantDemands
d) (TenantDemands -> Int
tdDepthDesired TenantDemands
d) (TenantDemands -> Maybe Int
tdDepthExplicit TenantDemands
d)
shedCapabilityCount :: Int -> Int -> Int -> Maybe Int
shedCapabilityCount :: Int -> Int -> Int -> Maybe Int
shedCapabilityCount Int
h Int
capabilities Int
allocArea
| Int
capabilities Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
allocArea Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
h Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
nurseryCeilingShareDiv =
let fitted :: Int
fitted = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 ((Int
h Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
nurseryCeilingShareDiv) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
allocArea)
in if Int
fitted Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
capabilities then Int -> Maybe Int
forall a. a -> Maybe a
Just Int
fitted else Maybe Int
forall a. Maybe a
Nothing
| Bool
otherwise = Maybe Int
forall a. Maybe a
Nothing
renderDegradations :: TenantDemands -> ShedOutcomes -> Int -> Int -> Maybe Int -> Int -> [Text]
renderDegradations :: TenantDemands
-> ShedOutcomes -> Int -> Int -> Maybe Int -> Int -> [Text]
renderDegradations TenantDemands
d ShedOutcomes
o Int
capabilities Int
allocArea Maybe Int
shedCaps Int
overshootWithoutOverrides =
[Maybe Text] -> [Text]
forall a. [Maybe a] -> [a]
catMaybes
[ [Text] -> Maybe Text
forall a. [a] -> Maybe a
listToMaybe
[ Text
"memory plan: mirror artifact byte cap shed from "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TenantDemands -> Int
tdArtifactCapDesired TenantDemands
d)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" to "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (ShedOutcomes -> Int
soArtifactCapFinal ShedOutcomes
o)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" bytes to fit the heap ceiling"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (if ShedOutcomes -> Int
soArtifactCapFinal ShedOutcomes
o Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Text
" (this pod mirrors no artifact it cannot buffer safely)" else Text
"")
| ShedOutcomes -> Int
soMirrorShed ShedOutcomes
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
]
, [Text] -> Maybe Text
forall a. [a] -> Maybe a
listToMaybe
[ Text
"memory plan: cache aggregate shed from "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TenantDemands -> Int
tdCacheDesired TenantDemands
d)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" to "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (ShedOutcomes -> Int
soCacheFinal ShedOutcomes
o)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" bytes to fit the heap ceiling"
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> (if ShedOutcomes -> Int
soCacheFinal ShedOutcomes
o Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then Text
" (the proxy serves uncached)" else Text
"")
| ShedOutcomes -> Int
soCacheShed ShedOutcomes
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
]
, [Text] -> Maybe Text
forall a. [a] -> Maybe a
listToMaybe
[ Text
"memory plan: admission shed to "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (ShedOutcomes -> Int
soAdmissionFinal ShedOutcomes
o)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" in-flight operation(s) (the material share cannot hold more at the floor response cap)"
| ShedOutcomes -> Int
soMaterialShed ShedOutcomes
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
]
, ( \Int
c ->
Text
"memory plan: capability count shed to "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
c
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" (the nursery of "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
capabilities
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" capabilities x "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
allocArea
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" bytes allocation area is the memory pressure; fewer, or a smaller GHCRTS -A, fits this pod)"
)
(Int -> Text) -> Maybe Int -> Maybe Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Int
shedCaps
, [Text] -> Maybe Text
forall a. [a] -> Maybe a
listToMaybe
[ Text
"memory plan: publish aggregate shed to one maximum request (" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (ShedOutcomes -> Int
soPublishFinal ShedOutcomes
o) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" bytes)"
| ShedOutcomes -> Int
soPublishShed ShedOutcomes
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
]
, [Text] -> Maybe Text
forall a. [a] -> Maybe a
listToMaybe
[Text
"memory plan: memory-queue depth shed to " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (ShedOutcomes -> Int
soDepthFinal ShedOutcomes
o) | ShedOutcomes -> Int
soQueueShedBytes ShedOutcomes
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0]
, [Text] -> Maybe Text
forall a. [a] -> Maybe a
listToMaybe
[ Text
"memory plan: the irreducible minimum (one operation on one capability, no cache) still exceeds the heap ceiling by "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
overshootWithoutOverrides
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" bytes; booting anyway with the container limit as the only backstop -- give this pod more memory"
| ShedOutcomes -> Int
soResidualOvershoot ShedOutcomes
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
overshootWithoutOverrides Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
]
]
renderPlanLines :: TenantDemands -> ShedOutcomes -> Text -> Text -> Int -> Bool -> Maybe PublishTenant -> Maybe MirrorArtifactTenant -> [Text]
renderPlanLines :: TenantDemands
-> ShedOutcomes
-> Text
-> Text
-> Int
-> Bool
-> Maybe PublishTenant
-> Maybe MirrorArtifactTenant
-> [Text]
renderPlanLines TenantDemands
d ShedOutcomes
o Text
ceilingClause Text
cpuAdmissionLine Int
cacheEntries Bool
entriesExplicit Maybe PublishTenant
publishTenant Maybe MirrorArtifactTenant
mirrorArtifactTenant =
[ Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"runtime reserve" (TenantDemands -> Int
tdReserve TenantDemands
d) Bool
False
, Text
cpuAdmissionLine
, Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"admission capacity" (ShedOutcomes -> Int
soAdmissionFinal ShedOutcomes
o) (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (TenantDemands -> Maybe Int
tdAdmissionExplicit TenantDemands
d))
, Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"material aggregate" (ShedOutcomes -> Int
soMaterialFinal ShedOutcomes
o) Bool
False
, Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"response byte cap" (ShedOutcomes -> Int
soResponseFinal ShedOutcomes
o) (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (TenantDemands -> Maybe Int
tdResponseExplicit TenantDemands
d))
, Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"request byte cap" (TenantDemands -> Int
tdRequestFinal TenantDemands
d) (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (TenantDemands -> Maybe Int
tdRequestExplicit TenantDemands
d))
, Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"cache byte bound" (ShedOutcomes -> Int
soCacheFinal ShedOutcomes
o) (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (TenantDemands -> Maybe Int
tdCacheExplicit TenantDemands
d))
, Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"cache entry bound" Int
cacheEntries Bool
entriesExplicit
]
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"publish aggregate" (Int -> (PublishTenant -> Int) -> Maybe PublishTenant -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 PublishTenant -> Int
ptAggregateBytes Maybe PublishTenant
publishTenant) Bool
False | TenantDemands -> Bool
tdPublishConfigured TenantDemands
d]
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"memory-queue depth" (ShedOutcomes -> Int
soDepthFinal ShedOutcomes
o) (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (TenantDemands -> Maybe Int
tdDepthExplicit TenantDemands
d)) | TenantDemands -> Bool
tdMemoryBacked TenantDemands
d]
[Text] -> [Text] -> [Text]
forall a. Semigroup a => a -> a -> a
<> [Text -> Int -> Bool -> Text
forall {a}. Show a => Text -> a -> Bool -> Text
withCeiling Text
"mirror artifact byte cap" (Int
-> (MirrorArtifactTenant -> Int)
-> Maybe MirrorArtifactTenant
-> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 MirrorArtifactTenant -> Int
matMaxBytes Maybe MirrorArtifactTenant
mirrorArtifactTenant) (Maybe Int -> Bool
forall a. Maybe a -> Bool
isJust (TenantDemands -> Maybe Int
tdArtifactExplicit TenantDemands
d)) | TenantDemands -> Bool
tdMirrors TenantDemands
d]
where
withCeiling :: Text -> a -> Bool -> Text
withCeiling Text
name a
value Bool
explicit =
Text
"memory plan: "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> a -> Text
forall b a. (Show a, IsString b) => a -> b
show a
value
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> ( if Bool
explicit
then Text
" (from config)"
else Text
" (computed from heap ceiling " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TenantDemands -> Int
tdCeiling TenantDemands
d) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
", " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
ceilingClause Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
)
type OverridePins = (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
overrideMinShedSum :: Int -> Int -> Bool -> Bool -> Bool -> OverridePins -> Int
overrideMinShedSum :: Int
-> Int
-> Bool
-> Bool
-> Bool
-> (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int,
Maybe Int)
-> Int
overrideMinShedSum Int
base Int
computedRequestFloor Bool
publishPresent Bool
memoryBacked Bool
mirrors (Maybe Int
pinCache, Maybe Int
pinAdmission, Maybe Int
pinResponse, Maybe Int
pinRequest, Maybe Int
pinDepth, Maybe Int
pinArtifact) =
Int
base
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
0 Maybe Int
pinCache
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
materialFloor
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (if Bool
publishPresent then Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
computedRequestFloor Maybe Int
pinRequest else Int
0)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (if Bool
memoryBacked then Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
queueDepthFloor Maybe Int
pinDepth Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mirrorJobEstimatedBytes else Int
0)
Int -> Int -> Int
forall a. Num a => a -> a -> a
+ (if Bool
mirrors then Int -> (Int -> Int) -> Maybe Int -> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
mirrorArtifactEnvelopeMultiplier) Maybe Int
pinArtifact else Int
0)
where
materialFloor :: Int
materialFloor = Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
1 Maybe Int
pinAdmission Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
packumentOriginFanout Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int -> Int
expandWireBytes (Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe Int
responseBytesFloor Maybe Int
pinResponse)
overrideSubstitutions :: OverridePins -> [(Text, OverridePins)]
overrideSubstitutions :: (Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int)
-> [(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int,
Maybe Int))]
overrideSubstitutions (Maybe Int
pinCache, Maybe Int
pinAdmission, Maybe Int
pinResponse, Maybe Int
pinRequest, Maybe Int
pinDepth, Maybe Int
pinArtifact) =
[Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int,
Maybe Int))]
-> [(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int,
Maybe Int))]
forall a. [Maybe a] -> [a]
catMaybes
[ (Text
"cache.maxBytes", (Maybe Int
forall a. Maybe a
Nothing, Maybe Int
pinAdmission, Maybe Int
pinResponse, Maybe Int
pinRequest, Maybe Int
pinDepth, Maybe Int
pinArtifact)) (Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
-> Maybe Int
-> Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Int
pinCache
, (Text
"runtime.serveMaxInFlight", (Maybe Int
pinCache, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
pinResponse, Maybe Int
pinRequest, Maybe Int
pinDepth, Maybe Int
pinArtifact)) (Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
-> Maybe Int
-> Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Int
pinAdmission
, (Text
"limits.maxResponseBytes", (Maybe Int
pinCache, Maybe Int
pinAdmission, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
pinRequest, Maybe Int
pinDepth, Maybe Int
pinArtifact)) (Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
-> Maybe Int
-> Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Int
pinResponse
, (Text
"limits.maxRequestBytes", (Maybe Int
pinCache, Maybe Int
pinAdmission, Maybe Int
pinResponse, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
pinDepth, Maybe Int
pinArtifact)) (Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
-> Maybe Int
-> Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Int
pinRequest
, (Text
"queue.memoryMaxDepth", (Maybe Int
pinCache, Maybe Int
pinAdmission, Maybe Int
pinResponse, Maybe Int
pinRequest, Maybe Int
forall a. Maybe a
Nothing, Maybe Int
pinArtifact)) (Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
-> Maybe Int
-> Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Int
pinDepth
, (Text
"limits.maxArtifactBytes", (Maybe Int
pinCache, Maybe Int
pinAdmission, Maybe Int
pinResponse, Maybe Int
pinRequest, Maybe Int
pinDepth, Maybe Int
forall a. Maybe a
Nothing)) (Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
-> Maybe Int
-> Maybe
(Text,
(Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int, Maybe Int))
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Int
pinArtifact
]
attributeOverrideViolations :: Int -> Int -> Int -> [(Text, Int)] -> [Text]
attributeOverrideViolations :: Int -> Int -> Int -> [(Text, Int)] -> [Text]
attributeOverrideViolations Int
heapCeiling Int
overriddenOvershoot Int
freeOvershoot [(Text, Int)]
perOverrideOvershoot
| Int
overriddenOvershoot Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
freeOvershoot Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0 =
[ Text
"explicit override(s) "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", " [Text]
culprits
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" push the combined memory plan "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
overriddenOvershoot
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" bytes past the effective heap ceiling "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
heapCeiling
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"; the override-free minimum fits within it, so lower them or raise the ceiling"
]
| Bool
otherwise = []
where
culprits :: [Text]
culprits = case [Text
name | (Text
name, Int
o) <- [(Text, Int)]
perOverrideOvershoot, Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
0] of
[] -> ((Text, Int) -> Text) -> [(Text, Int)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, Int) -> Text
forall a b. (a, b) -> a
fst [(Text, Int)]
perOverrideOvershoot
[Text]
flips -> [Text]
flips
planCacheConfig :: CacheSettings -> MemoryPlan -> CacheConfig
planCacheConfig :: CacheSettings -> MemoryPlan -> CacheConfig
planCacheConfig CacheSettings
cacheSettings MemoryPlan
plan =
CacheConfig
{ cacheTtl :: NominalDiffTime
cacheTtl = CacheSettings -> NominalDiffTime
csTtl CacheSettings
cacheSettings
, cacheFullBudget :: StoreBudget
cacheFullBudget = StoreBudget{sbMaxEntries :: Int
sbMaxEntries = Int
entries, sbMaxBytes :: Int
sbMaxBytes = Int
fullBytes}
, cacheVersionBudget :: StoreBudget
cacheVersionBudget = StoreBudget{sbMaxEntries :: Int
sbMaxEntries = Int
cacheVersionEntriesFactor Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
entries, sbMaxBytes :: Int
sbMaxBytes = Int
versionBytes}
, cacheAssembledBudget :: StoreBudget
cacheAssembledBudget = StoreBudget{sbMaxEntries :: Int
sbMaxEntries = Int
entries, sbMaxBytes :: Int
sbMaxBytes = Int
aggregate Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fullBytes Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
versionBytes}
}
where
aggregate :: Int
aggregate = MemoryPlan -> Int
mpCacheAggregateBytes MemoryPlan
plan
entries :: Int
entries = MemoryPlan -> Int
mpCacheMaxEntries MemoryPlan
plan
fullBytes :: Int
fullBytes = Int
aggregate Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
cacheFullSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100
versionBytes :: Int
versionBytes = Int
aggregate Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
cacheVersionSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100
cacheFullSharePercent :: Int
cacheFullSharePercent :: Int
cacheFullSharePercent = Int
60
cacheVersionSharePercent :: Int
cacheVersionSharePercent :: Int
cacheVersionSharePercent = Int
15
cacheVersionEntriesFactor :: Int
cacheVersionEntriesFactor :: Int
cacheVersionEntriesFactor = Int
4
cacheSharePercent :: Int
cacheSharePercent :: Int
cacheSharePercent = Int
30
materialSharePercent :: Int
materialSharePercent :: Int
materialSharePercent = Int
45
publishSharePercent :: Int
publishSharePercent :: Int
publishSharePercent = Int
15
queueSharePercent :: Int
queueSharePercent :: Int
queueSharePercent = Int
5
mirrorArtifactSharePercent :: Int
mirrorArtifactSharePercent :: Int
mirrorArtifactSharePercent = Int
4
mirrorArtifactEnvelopeMultiplier :: Int
mirrorArtifactEnvelopeMultiplier :: Int
mirrorArtifactEnvelopeMultiplier = Int
4
mirrorArtifactBytesCap :: Int
mirrorArtifactBytesCap :: Int
mirrorArtifactBytesCap = Int
512 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024
runtimeReserveShareDiv :: Int
runtimeReserveShareDiv :: Int
runtimeReserveShareDiv = Int
5
runtimeReserveFloorBytes :: Int
runtimeReserveFloorBytes :: Int
runtimeReserveFloorBytes = Int
33554432
nurseryCeilingShareDiv :: Int
nurseryCeilingShareDiv :: Int
nurseryCeilingShareDiv = Int
4
responseBytesFloor :: Int
responseBytesFloor :: Int
responseBytesFloor = Int
12582912
responseBytesCap :: Int
responseBytesCap :: Int
responseBytesCap = Int
67108864
responseBytesFallback :: Int
responseBytesFallback :: Int
responseBytesFallback = Int
12582912
requestBytesFloor :: Int
requestBytesFloor :: Int
requestBytesFloor = Int
26214400
requestBytesCap :: Int
requestBytesCap :: Int
requestBytesCap = Int
104857600
requestBytesFallback :: Int
requestBytesFallback :: Int
requestBytesFallback = Int
26214400
publishAggregateFallbackRequests :: Int
publishAggregateFallbackRequests :: Int
publishAggregateFallbackRequests = Int
4
cacheBytesFloor :: Int
cacheBytesFloor :: Int
cacheBytesFloor = Int
67108864
cacheBytesCap :: Int
cacheBytesCap :: Int
cacheBytesCap = Int
1073741824
cacheBytesFallback :: Int
cacheBytesFallback :: Int
cacheBytesFallback = Int
268435456
cacheEntryExpectedBytes :: Int
cacheEntryExpectedBytes :: Int
cacheEntryExpectedBytes = Int
262144
cacheEntriesFloor :: Int
cacheEntriesFloor :: Int
cacheEntriesFloor = Int
256
cacheEntriesCap :: Int
cacheEntriesCap :: Int
cacheEntriesCap = Int
65536
queueDepthFloor :: Int
queueDepthFloor :: Int
queueDepthFloor = Int
5000
queueDepthCap :: Int
queueDepthCap :: Int
queueDepthCap = Int
100000
queueDepthFallback :: Int
queueDepthFallback :: Int
queueDepthFallback = Int
50000