Skip to content

Commit

Permalink
prototype: supply 1.25 credits for tiering merges
Browse files Browse the repository at this point in the history
This is necessary to accomodate 5-way merges due to holding back runs
that are too small.
  • Loading branch information
mheinzel committed Jul 25, 2024
1 parent 4773733 commit 199466d
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions prototypes/ScheduledMerges.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,24 @@ bufferToRun = id
supplyCredits :: Credit -> Levels s -> ST s ()
supplyCredits n ls =
sequence_
[ supplyMergeCredits (n * creditsForMerge mr) mr | Level mr _rs <- ls ]
[ supplyMergeCredits (ceiling (fromIntegral n * creditsForMerge mr)) mr
| Level mr _rs <- ls
]

-- | The general case (and thus worst case) of how many merge credits we need
-- for a level. This is based on the merging policy at the level.
--
creditsForMerge :: MergingRun s -> Credit
creditsForMerge :: MergingRun s -> Float
creditsForMerge SingleRun{} = 0

-- A levelling merge is 5x the cost of a tiering merge.
-- That's because for levelling one of the runs as an input to the merge
-- is the one levelling run which is (up to) 4x bigger than the others put
-- together, so it's 1 + 4.
creditsForMerge (MergingRun MergePolicyLevelling _ _) = 5
creditsForMerge (MergingRun MergePolicyTiering _ _) = 1
-- A levelling merge has 1 input run and one resident run, which is (up to) 4x
-- bigger than the others.
-- It needs to be completed before another run comes in.
creditsForMerge (MergingRun MergePolicyLevelling _ _) = (1 + 4) / 1

-- A tiering merge has 5 runs at most (once could be held back to merged again)
-- and must be completed before the level is full (once 4 more runs come in).
creditsForMerge (MergingRun MergePolicyTiering _ _) = 5 / 4

type Event = EventAt EventDetail
data EventAt e = EventAt {
Expand Down

0 comments on commit 199466d

Please sign in to comment.