Where should I run my code?

A presentation at DevFest Dublin 2019 in November 2019 in Dublin, Ireland by Katie McLaughlin

Slide 1

Slide 1

Where should I run my code? Katie McLaughlin Developer Advocate, Google Cloud

Slide 2

Slide 2

So, “where should I run my code?” I hear you ask. Well,

Slide 3

Slide 3

It depends.

Slide 4

Slide 4

Thank you for coming to my talk! :D

Slide 5

Slide 5

Okay, fine.

Slide 6

Slide 6

Saying “it depends” here is a bit of a cop out, and I still have 28 minutes of speaking time So Instead, I offer the following.

Slide 7

Slide 7

I am a sysadmin, but I”m not your sysadmin.

I can’t tell you what will work for your system. If I did tell you a solution, you may not like it, you may not understand it which means you won’t be able to maintain it. Which is far worse.

So instead I’m going to give you information to help you make an informed decision.

Slide 8

Slide 8

By the end of this talk, you should have an understanding of a few of the major options out there, and hopefully have an idea about which one is right choice.

Slide 9

Slide 9

But what is the right choice

Slide 10

Slide 10

The right choice is what is right for you

As I said, I’m not your sysadmin, beyond this presentation I’m not going to be able to help you. I won’t be there oncall to help fix your systems, I can only give advice now.

The choice has to be right for you.

Slide 11

Slide 11

Today we’re going to cover four areas of Google Cloud: Cloud Functions, App engine, Cloud Run, and Compute engine.

Slide 12

Slide 12

Cloud Functions Managed code execution

Slide 13

Slide 13

A serverless environment to build and connect cloud services

Event driven - connect Cloud services via Cloud Pub/Sub, Cloud Storage, HTTP requests & more

Serverless Fully managed execution environment Pay only for what you use Autoscales with usage

Slide 14

Slide 14

What do you have to worry about? Events Function Definitions

What is managed for you? Everything else.

Slide 15

Slide 15

Good fit? Constraints?

Good fit Serverless Using Cloud Pub/Sub, Cloud Storage Don’t want to think about runtime environment Data transformations (ETL) HTTP glue Constraints Function level granularity Must interact via events Specific language runtimes: Node.js, Python, Go.

Slide 16

Slide 16

Don’t have to even think about servers Pay only for what you use Simple developer experience (deploy functions not apps)

Slide 17

Slide 17

App Engine Managed Runtimes

Slide 18

Slide 18

App Engine goal: let developers focus on app code No servers to manage, scale up fast, scale down to zero No patches/updates Versioning Traffic splitting

Slide 19

Slide 19

Open-source, idiomatic experience Use any extension, binary, or framework Supported Runtimes Python, Java, Node.js, PHP, Ruby, Go Use Google Cloud APIs directly

Slide 20

Slide 20

What do you have to worry about?

Code HTTP Requests Versions

What is managed for you? Everything else.

Slide 21

Slide 21

Good fit? Constraints?

Good fit HTTP/S request-response Stateless serving applications Scaling to high traffic

Constraints Standard Runtimes for Python, Java, Node, PHP, Ruby, Go HTTP/S only

Flexible runtimes Inherit Docker constraints Not best for very low traffic sites

Slide 22

Slide 22

Developers focus on code Optimized for web serving workloads Especially great for variable load

App Engine currently serves more than 100B requests per day

Slide 23

Slide 23

@glasnt Cloud Run Managed containers 03

Slide 24

Slide 24

Now generally available!

Input: container image with code listening on $PORT for HTTP

SSL termination HTTP requests to running containers 1-80 concurrent requests, configurable Scale to zero Pay only for actual CPU & memory used

Slide 25

Slide 25

Code in a container image Building the image Listening on a $PORT * container contract: it lists the details of ports, the envvars you get, the container instance sandbox, etc. If you need to be doing more low level things, you may hit limitations here.

What is managed for you? Everything else.

Slide 26

Slide 26

Good fit? Constraints?

Good fit Stateless HTTP request-response workloads Scale: way up, down to zero, bursty Specific runtime requirements

Constraints Must use containers Decide on build process (Cloud Build, etc)

Slide 27

Slide 27

Why Cloud Run?

Serverless developer experience Decide on operations model at deployment time Change with a re-deploy Runs anything that can run in a container and listens to HTTP. Open: run same containers on your machines

Slide 28

Slide 28

Compute Engine Virtual Machines

Slide 29

Slide 29

@glasnt What is Compute Engine? Virtual machines and networking Per Virtual Machine: ● up to 160 vCPUs ● up to 3,844 GB RAM ● up to 64 TB of disk ● optional GPUs, TPUs Each specification independently configurable

Slide 30

Slide 30

What do you have to worry about? Virtual machines and networking

Start quickly, ~20 seconds to user code running Pre-built images, or create your own Debian, CentOS, CoreOS, Ubuntu, RHEL, SUSE also Windows Server Datacenter!

Slide 31

Slide 31

What do you have to worry about? Your software Operating system / disk images CPU, RAM, Disk Networking - Firewall, Load balancers, VPNs

What is managed for you? Everything else.

Slide 32

Slide 32

Good fit Existing systems (lift and shift) 1:1 container:VM mapping Specific OS / kernel required License requirements Running databases

Constraints Scaling speed floor ~20s per VM, 1000s in ~60s Decide how to handle software updates

Slide 33

Slide 33

Consistency - ask for 10 VMs, you get 10 good VMs Custom VMs - choose RAM and CPU, GPUs Live disk resize - also any size disk on any machine Billing - Sustained use discounts, preemptible VMs, per minute billing Live migrations - your VMs stay up longer Architecture - good fit for most existing systems

Slide 34

Slide 34

Google Cloud services run on it, too: Cloud SQL GKE Cloud Dataflow Cloud Dataproc Cloud Build and more…

Slide 35

Slide 35

Oh but wait a moment there, Katie. All this talk of different workload platforms, and you work at google…

Slide 36

Slide 36

Why oh why haven’t you mentioned kubernetes yet?!

Slide 37

Slide 37

Oh, but I have.

Slide 38

Slide 38

KNative is an open source project for creating building blocks on top of serverless

Slide 39

Slide 39

and knative directly powers cloud run.

and since Cloud run is managed, you can use all the power of kubernetes without having to directly administer it.

Slide 40

Slide 40

We’ve already talked about what’s a particularly good fit for each of the services. So you may be set. Your current needs might be a great fit for a specific one. Great!

It’s possible though, that you’re still not sure which of these fit for you

Slide 41

Slide 41

You could think of it in terms of two vectors of complexity.

If you aren’t sure and what a solid template to work from, and you just want to run a function, Cloud Functions If you need a bit more wiggle room, but you still want that sort of framework, App Engine

If you’re already used to containers, Cloud Run If you want more than just containers, Compute Engine.

But of course it’s more complex than that

Slide 42

Slide 42

But what is the right choice is going to depend on what choices you are able to make.

Slide 43

Slide 43

At the most complex end of the spectrum, you have the choice of ANYTHING in Compute engine. From the packages you have to the hardware you run on. As you go back, you have choices made for you. You don’t get to choose your hardware on any other service, but you still have the choice of language on Cloud Run Functions and App Engine, you have a limited choice, because it’s managed for you.

Slide 44

Slide 44

We can, however, think of this a different way.

Instead of “what am I limited by”, think about it this way:

Slide 45

Slide 45

What do I have to worry about.

If the choice is made for you, you can focus on other parts of the stack

Slide 46

Slide 46

Some of the “Choices” from earlier are just that. Choices. In a few cases once you make the choice, it’s managed for you.

You chose a certain type of hardware, we got you. You don’t have to do any physical server maintenance.

The language you chose for your Cloud Function? We’ll handle updates there. But you have little choice on which language.

The more choices, the more worry.

Slide 47

Slide 47

And again, the right choice is what is right for you.

And what you want to do.

Slide 48

Slide 48

Do one thing. Do many things. Do anything, do everything.

But, of course it’s not just that easy.

Slide 49

Slide 49

You could have more than one choice.

Slide 50

Slide 50

You could use them together!

Slide 51

Slide 51

You could have app engine which sends out longer running tasks to cloud functions

Or you could have some functionality on compute engine, complemented with other workloads

Slide 52

Slide 52

You could have, say: An Cloud Run website that takes uploaded images, sends them off into a queue with Cloud Pub/Sub, which then processes them in the vision API, and stores the results in Cloud SQL, which your app then shows the results of

Or you could have a function that uses the translation API based on BigQuery data

The possibilities are endless.

Slide 53

Slide 53

…or move up or down abstraction levels

Slide 54

Slide 54

You might find your container just needs to be triggered on a schedule, and so you move your functionality into Cloud functions

You might want more flexibility than what App Engine provides, so you migrate to a container You may find that you need more “ooph” in your function, and move to compute engine with custom hardware selections.

Slide 55

Slide 55

The right choice is what is right for you.

Hopefully you’ve gained some more clarity on what that just might be but if not, come have a chat, I might just be able to help.

Slide 56

Slide 56

Thank you!