Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Price Aware Scheduling

Price Aware Scheduling

A look at an algorithm in haskell that I am working on for doing fair
and less-fair-but-actually-kind-of efficient scheduling of tasks
across across multiple machines. The goal is to take existing work
scheduling approaches that tend to be ok at optimising for resource
utilisation across multiple dimensions (IO, Memory, CPU) for a fixed
set of resources, and introduce variably available / variable price
resources. Using budgets (min/max concurrent resources, cost of
execution, timelines of completion) I hope to arbitrate between
allocation of existing and new resources without sacrificing
utilisation.

Mark Hibberd

May 25, 2016
Tweet

More Decks by Mark Hibberd

Other Decks in Programming

Transcript

  1. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours
  2. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  3. resource $0.40 / hr 4 x cpu 240 gb disk

    1Gb network 4m boot-time 8gb memory
  4. “We are in the business of turning technical debt into

    monetary debt” - Old Ambiata Proverb
  5. 1

  6. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  7. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  8. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  9. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  10. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  11. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  12. resource $0.40 / hr 4 x cpu 240 gb disk

    1Gb network 4m boot-time 8gb memory
  13. resource $0.40 / hr 4 x cpu 240 gb disk

    1Gb network 4m boot-time 8gb memory
  14. resource $0.04 / hr 4 x cpu 240 gb disk

    1Gb network 4m boot-time 8gb memory
  15. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  16. 1 newtype TaskId = 2 TaskId Text 3 4 data

    Timeliness = 5 Interactive 6 | Lazy 7 | FinishBy UTCTime 8 9 data Requirement = 10 Requirement { 11 memory :: Memory 12 , disk :: Disk 13 , network :: Network 14 , timeliness :: Timeliness 15 } deriving (Eq, Show) 16 17 data Task = 18 Task { 19 taskId :: !TaskId 20 , taskRequirement :: !Requirement 21 } deriving (Eq, Show)
  17. 1 newtype ResourceId = 2 ResourceId Text 3 4 data

    Resource = 5 Resource { 6 memory :: Memory 7 , disk :: Disk 8 , network :: Network 9 , cost :: Price 10 } 11 12 data Allocation = 13 Allocated ResourceId Task 14 | Unallocated ResourceId 15 16 data Capability = 17 Capability { 18 capabilityResource :: Resource 19 , capabilityAllocated :: [Allocation] 20 }
  18. 1 submit :: UTCTime -> [Capability] -> [Task] -> [Decision]

    2 submit now capabiities tasks = 3 schedule now capabiities <$> 4 sortBy (compare `on` urgency now) tasks
  19. 1 urgency :: UTCTime -> Task -> Double 2 urgency

    now t = 3 case timelinessOf t of 4 Interactive -> 5 1.0 6 Lazy -> 7 0.0 8 FinishBy when -> 9 distributionOver (statisticsOf t) when
  20. 1 submit :: UTCTime -> [Capability] -> [Task] -> [Decision]

    2 submit now capabiities tasks = 3 schedule now capabiities <$> 4 sortBy (compare `on` urgency now) tasks
  21. 1 submit :: UTCTime -> [Capability] -> [Task] -> [Decision]

    2 submit now capabiities tasks = 3 schedule now capabiities <$> 4 sortBy (compare `on` urgency now) tasks 5 6 schedule :: UTCTime -> [Capability] -> Task -> Decision 7 schedule now capabilities task = 8 decide $ 9 evaluate now task <$> capabilities
  22. 1 data Score = 2 Free Resource [Double] 3 |

    Scale Capability [Double] 4 | Delay Capability [Double] 5 6 data Scores = 7 Scores Task [Score] 8 9 evaluate :: UTCTime -> Task -> Capability -> Scores 10 evaluate now task capability = 11 merge [ 12 evaluateFree now task capability 13 , evaluateRunning now task capability 14 , evaluateScaled now task capability 15 ] 16 17 evaluateFree :: UTCTime -> Task -> Capability -> Scores 18 19 evaluateRunning :: UTCTime -> Task -> Capability -> Scores 20 21 evaluateScaled :: UTCTime -> Task -> Capability -> Scores
  23. 1 memory resource allocated required = 2 max 0 $

    required / resource - allocated 3 4 cpu resource allocated required = 5 max 0 $ required / resource - allocated 6 7 network resource allocated required = 8 max 0 $ required / resource - allocated 9 10 timeliness remaining average variance = 11 (average + variance) / remaining
  24. 1 submit :: UTCTime -> [Capability] -> [Task] -> [Decision]

    2 submit now capabiities tasks = 3 schedule now capabiities <$> 4 sortBy (compare `on` urgency now) tasks 5 6 schedule :: UTCTime -> [Capability] -> Task -> Decision 7 schedule now capabilities task = 8 decide $ 9 evaluate now task <$> capabilities
  25. 1 data Decision = 2 Decision Task Outcome 3 4

    data Outcome = 5 Assign Resource 6 | Delay Resource 7 | Scale Capability 8 | Preempt Capability 9 | Reject 10 11 decide :: [Scores] -> Decision 12 decide scores = 13 let Scores t ss = merge score in Decision t $ 14 case last . sortBy (compare `on` weight) $ ss of 15 Nothing -> 16 Reject 17 Just (Free resource _) -> 18 Assign resource 19 Just (Scale capability _) -> 20 Scale capability 21 Just (Delay capability _) -> 22 Preempt capability
  26. $ $

  27. $

  28. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  29. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours preemptible y/n?
  30. 2 x cpu task 4gb memory 12 hours 128 gb

    disk σ 1.1 hours, μ 4hours x second batch time