module Ecluse.Composition.MemoryPlan.Transient (
transientBudget,
renderTransientBudget,
brakeBounds,
liveTargetBytes,
liveCacheShareBytes,
idleLiveFloorBytes,
transientFloorBytes,
noCeilingTransientBytes,
liveCacheSharePercent,
meterStepBytes,
) where
import Ecluse.Composition.MemoryPlan.Types (TransientBudget (..))
import Ecluse.Core.Server.Admission.Types (BrakeBounds (..))
transientBudget :: Maybe Int -> Int -> Int -> Int -> TransientBudget
transientBudget :: Maybe Int -> Int -> Int -> Int -> TransientBudget
transientBudget Maybe Int
heapCeiling Int
capabilities Int
allocArea Int
tenants = case Maybe Int
heapCeiling of
Maybe Int
Nothing ->
TransientBudget
{ tbLiveTargetBytes :: Maybe Int
tbLiveTargetBytes = Maybe Int
forall a. Maybe a
Nothing
, tbExplainedBytes :: Int
tbExplainedBytes = Int
explained
, tbBootBytes :: Int
tbBootBytes = Int
noCeilingTransientBytes
, tbLiveCeilingBytes :: Maybe Int
tbLiveCeilingBytes = Maybe Int
forall a. Maybe a
Nothing
, tbFloorBytes :: Int
tbFloorBytes = Int
transientFloorBytes
, tbOverflowLiveBytes :: Maybe Int
tbOverflowLiveBytes = Maybe Int
forall a. Maybe a
Nothing
}
Just Int
ceiling' ->
let copyable :: Int
copyable = Int -> Int -> Int -> Int
copyableHeap Int
ceiling' Int
capabilities Int
allocArea
boot :: Int
boot = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
transientFloorBytes (Int
copyable Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
explained)
in TransientBudget
{ tbLiveTargetBytes :: Maybe Int
tbLiveTargetBytes = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
copyable Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4)
, tbExplainedBytes :: Int
tbExplainedBytes = Int
explained
, tbBootBytes :: Int
tbBootBytes = Int
boot
, tbLiveCeilingBytes :: Maybe Int
tbLiveCeilingBytes = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
copyable Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
3)
, tbFloorBytes :: Int
tbFloorBytes = Int
transientFloorBytes
, tbOverflowLiveBytes :: Maybe Int
tbOverflowLiveBytes = Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
copyable Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2)
}
where
explained :: Int
explained = Int
idleLiveFloorBytes Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
tenants
renderTransientBudget :: TransientBudget -> Text
renderTransientBudget :: TransientBudget -> Text
renderTransientBudget TransientBudget
budget = case TransientBudget -> Maybe Int
tbLiveTargetBytes TransientBudget
budget of
Maybe Int
Nothing ->
Text
"memory plan: transient budget " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TransientBudget -> Int
tbBootBytes TransientBudget
budget) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" (built-in default, no heap-ceiling datapoint)"
Just Int
target ->
Text
"memory plan: transient budget "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TransientBudget -> Int
tbBootBytes TransientBudget
budget)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" (live target "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
target
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" less "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TransientBudget -> Int
tbExplainedBytes TransientBudget
budget)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" for the idle process and the other tenants, floor "
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show (TransientBudget -> Int
tbFloorBytes TransientBudget
budget)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> (Int -> Text) -> Maybe Int -> Text
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" (\Int
ceiling' -> Text
", live ceiling " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text
forall b a. (Show a, IsString b) => a -> b
show Int
ceiling') (TransientBudget -> Maybe Int
tbLiveCeilingBytes TransientBudget
budget)
Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
")"
brakeBounds :: TransientBudget -> BrakeBounds
brakeBounds :: TransientBudget -> BrakeBounds
brakeBounds TransientBudget
budget =
BrakeBounds
{ bbBootBytes :: Int
bbBootBytes = TransientBudget -> Int
tbBootBytes TransientBudget
budget
, bbFloorBytes :: Int
bbFloorBytes = TransientBudget -> Int
tbFloorBytes TransientBudget
budget
, bbLiveCeilingBytes :: Maybe Int
bbLiveCeilingBytes = TransientBudget -> Maybe Int
tbLiveCeilingBytes TransientBudget
budget
, bbFixedLiveBytes :: Int
bbFixedLiveBytes = Int
idleLiveFloorBytes
, bbExplainedBytes :: Int
bbExplainedBytes = TransientBudget -> Int
tbExplainedBytes TransientBudget
budget
, bbOverflowLiveBytes :: Maybe Int
bbOverflowLiveBytes = TransientBudget -> Maybe Int
tbOverflowLiveBytes TransientBudget
budget
, bbGrowFloorBytes :: Int
bbGrowFloorBytes = Int
meterStepBytes
}
liveTargetBytes :: Int -> Int -> Int -> Int
liveTargetBytes :: Int -> Int -> Int -> Int
liveTargetBytes Int
ceiling' Int
capabilities Int
allocArea = Int -> Int -> Int -> Int
copyableHeap Int
ceiling' Int
capabilities Int
allocArea Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
4
liveCacheShareBytes :: Int -> Int -> Int -> Int
liveCacheShareBytes :: Int -> Int -> Int -> Int
liveCacheShareBytes Int
ceiling' Int
capabilities Int
allocArea =
Int -> Int -> Int -> Int
liveTargetBytes Int
ceiling' Int
capabilities Int
allocArea Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
liveCacheSharePercent Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
100
copyableHeap :: Int -> Int -> Int -> Int
copyableHeap :: Int -> Int -> Int -> Int
copyableHeap Int
ceiling' Int
capabilities Int
allocArea = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
ceiling' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1 Int
capabilities Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
allocArea)
idleLiveFloorBytes :: Int
idleLiveFloorBytes :: Int
idleLiveFloorBytes = Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024
transientFloorBytes :: Int
transientFloorBytes :: Int
transientFloorBytes = Int
16 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024
noCeilingTransientBytes :: Int
noCeilingTransientBytes :: Int
noCeilingTransientBytes = Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024
liveCacheSharePercent :: Int
liveCacheSharePercent :: Int
liveCacheSharePercent = Int
30
meterStepBytes :: Int
meterStepBytes :: Int
meterStepBytes = Int
1024 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1024