Slide 1

Slide 1 text

Google Cloud Platform logo Everything You Ever Wanted A Few Things To Know About Resource Scheduling eBay Meetup December 14, 2016 Tim Hockin Senior Staff Software Engineer, Google @thockin

Slide 2

Slide 2 text

Google Cloud Platform WARNING: Some of this presentation is aspirational !

Slide 3

Slide 3 text

Google Cloud Platform I posit: Kubernetes is fundamentally ABOUT resource management

Slide 4

Slide 4 text

Google Cloud Platform ● CPU ● Memory

Slide 5

Slide 5 text

Google Cloud Platform ● CPU ● Memory ● Disk space ● Disk time ● Disk “spindles”

Slide 6

Slide 6 text

Google Cloud Platform ● CPU ● Memory ● Disk space ● Disk time ● Disk “spindles” ● Network bandwidth ● Host ports

Slide 7

Slide 7 text

Google Cloud Platform ● CPU ● Memory ● Disk space ● Disk time ● Disk “spindles” ● Network bandwidth ● Host ports ● Cache lines ● Memory bandwidth ● IP addresses ● Attached storage ● PIDs ● GPUs ● Power

Slide 8

Slide 8 text

Google Cloud Platform ● CPU ● Memory ● Disk space ● Disk time ● Disk “spindles” ● Network bandwidth ● Host ports ● Arbitrary, opaque third-party resources we can’t possibly predict ● Cache lines ● Memory bandwidth ● IP addresses ● Attached storage ● PIDs ● GPUs ● Power

Slide 9

Slide 9 text

Google Cloud Platform Many people are still asking the wrong questions.

Slide 10

Slide 10 text

Google Cloud Platform “How do I make sure my compute-intensive jobs don’t get scheduled on my database machine?” Images by Connie Zhou

Slide 11

Slide 11 text

Google Cloud Platform “Why would I want multiple replicas on a node? I want to use ALL of the memory.” Images by Connie Zhou

Slide 12

Slide 12 text

Google Cloud Platform “How do I save some machines for important work, and use the rest for batch?” Images by Connie Zhou

Slide 13

Slide 13 text

Google Cloud Platform So... what should they be asking?

Slide 14

Slide 14 text

Google Cloud Platform “How do I make sure my compute jobs can’t hurt my database job?”

Slide 15

Slide 15 text

Google Cloud Platform Isolation

Slide 16

Slide 16 text

Google Cloud Platform “How do I know how much memory and CPU my job needs?”

Slide 17

Slide 17 text

Google Cloud Platform Sizing

Slide 18

Slide 18 text

Google Cloud Platform “How do I safely pack more work onto less machines?”

Slide 19

Slide 19 text

Google Cloud Platform Utilization

Slide 20

Slide 20 text

Google Cloud Platform Isolation

Slide 21

Slide 21 text

Google Cloud Platform Isolation Prevent apps from hurting each other Make sure you actually get what you paid for Kubernetes (and Docker) isolate CPU and memory Don’t handle things like memory bandwidth, disk time, cache, network bandwidth, ... (yet) Predictability at the extremes is paramount

Slide 22

Slide 22 text

Google Cloud Platform When does isolation matter? Infinite loops Memory leaks Disk hogs Fork bombs Cache thrashing

Slide 23

Slide 23 text

Google Cloud Platform Counter-measures Infinite loops: CPU shares and quota Memory leaks: OOM yourself Disk hogs: Quota Fork bombs: Process limits Cache thrashing: LLC jails, cache segments

Slide 24

Slide 24 text

Google Cloud Platform Counter-measures: work to do Infinite loops: CPU shares and quota Memory leaks: OOM yourself Disk hogs: Quota Fork bombs: Process limits Cache thrashing: LLC jails, cache segments

Slide 25

Slide 25 text

Google Cloud Platform Resource taxonomy Compressible resources ● Hold no state ● Can be taken away very quickly ● “Merely” cause slowness when revoked ● e.g. CPU, disk time Non-compressible resources ● Hold state ● Are slower to be taken away ● Can fail to be revoked ● e.g. Memory, disk space

Slide 26

Slide 26 text

Google Cloud Platform Requests and limits Request: amount of a resource allowed to be used, with a strong guarantee of availability ● CPU (seconds/second), RAM (bytes) ● Scheduler will not over-commit requests Limit: max amount of a resource that can be used, regardless of guarantees ● scheduler ignores limits Repercussions: ● request < usage <= limit: resources might be available ● usage > limit: throttled or killed CPU 1. 5 Limit

Slide 27

Slide 27 text

Google Cloud Platform Quality of service Guaranteed: highest protection ● limit == request Burstable: medium protection ● request > 0 && limit > request Best Effort: lowest protection ● request == 0 How is “protection” implemented? ● CPU: cgroup shares & quota ● Memory: OOM score + user-space evictions CPU 1. 5 Limit

Slide 28

Slide 28 text

Google Cloud Platform Requests and limits Behavior at (or near) the limit depends on the particular resource Compressible resources: throttle usage ● e.g. No more CPU time for you! Non-compressible resources: reclaim ● e.g. Write-back and reallocate dirty pages ● Failure means process death (OOM) Being correct is more important than optimal CPU 1. 5 Limit

Slide 29

Slide 29 text

Google Cloud Platform What if I don’t specify? You get best-effort isolation You might get defaulted values You might get OOM killed randomly You might get CPU starved You might get no isolation at all

Slide 30

Slide 30 text

Google Cloud Platform Sizing

Slide 31

Slide 31 text

Google Cloud Platform Sizing How many replicas does my job need? How much CPU/RAM does my job need? Do I provision for worst-case? ● Expensive, wasteful Do I provision for average case? ● High failure rate (e.g. OOM) Benchmark it!

Slide 32

Slide 32 text

Google Cloud Platform Benchmarks are hard.

Slide 33

Slide 33 text

Google Cloud Platform Benchmarks are hard. Accurate benchmarks are VERY hard.

Slide 34

Slide 34 text

Google Cloud Platform Horizontal scaling Add more replicas Easy to reason about Works well when combined with resource isolation ● Having >1 replica per node makes sense Not always applicable ● e.g. Memory use scales with cluster size HorizontalPodAutoscaler ...

Slide 35

Slide 35 text

Google Cloud Platform What can we do? Horizontal scaling is not enough Resource needs change over time If only we had an “autopilot” mode... ● Collect stats & build a model ● Predict and react ● Manage Pods, Deployments, Jobs ● Try to stay ahead of the spikes

Slide 36

Slide 36 text

Google Cloud Platform Autopilot in Borg Most Borg users use autopilot See earlier statement regarding benchmarks - even at Google Kubernetes API is purpose-built for this sort of use-case We need a VerticalPodAutoscaler

Slide 37

Slide 37 text

Google Cloud Platform Utilization

Slide 38

Slide 38 text

Google Cloud Platform Utilization Resources cost money Wasted resources == wasted money You want NEED to use as much of your capacity as possible Selling it is not the same as using it

Slide 39

Slide 39 text

Google Cloud Platform How can we do better? Utilization demands isolation ● If you want to push the limits, it has to be safe at the extremes People are inherently cautious ● Provision for 90%-99% case VPA & strong isolation should give enough confidence to provision more tightly We need to do some kernel work, here

Slide 40

Slide 40 text

Google Cloud Platform Siren’s song: over-packing Clusters need some room to operate ● Nodes fail or get upgraded As you approach 100% bookings (requests), consider what happens when things go bad ● Nowhere to squeeze the toothpaste! Plan for some idle capacity - it will save your bacon one day ● Priorities & rescheduling can make this less expensive

Slide 41

Slide 41 text

Google Cloud Platform Wrapping up

Slide 42

Slide 42 text

Google Cloud Platform WARNING: Some of this presentation was aspirational !

Slide 43

Slide 43 text

Google Cloud Platform We still have a LONG WAY to go. Fortunately, this is a path we’ve been down before.

Slide 44

Slide 44 text

Google Cloud Platform Kubernetes is Open https://kubernetes.io Code: github.com/kubernetes/kubernetes Chat: slack.k8s.io Twitter: @kubernetesio open community open design open source open to ideas