basics of cloud computing – lecture 4 serverless ......apache-licensed serverless computing...

44
Basics of Cloud Computing Lecture 4 Serverless Computing 3 March 2020 Chinmaya Dehury Satish Srirama 1

Upload: others

Post on 01-Jan-2021

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Basics of Cloud Computing – Lecture 4

Serverless Computing3 March 2020

Chinmaya Dehury

Satish Srirama

1

Page 2: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Revisiting IaaS

In telecom, instead of paying for the

whole minute, you started paying for

seconds.

Instead of paying for the whole flat,

you started paying for one room and

other common shared area.

2

Page 3: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Revisiting IaaS

In telecom, instead of paying for the

whole minute, you started paying for

seconds.

Instead of paying for the whole flat,

you started paying for one room and

other common shared area.

Decreasing control over stack

implementation

Incre

asin

g fo

cu

s o

n b

usin

ess lo

gic

Physical Server

Virtual servers

Container

3

Page 4: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Revisiting IaaS

In telecom, instead of paying for the

whole minute, you started paying for

seconds.

Instead of paying for the whole flat,

you started paying for one room and

other common shared area.

Decreasing control over stack

implementation

Incre

asin

g fo

cu

s o

n b

usin

ess lo

gic

Physical Server

Virtual servers

Container

Can we apply the concept onto

IaaS cloud model ?

4

Page 5: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Serverless Computing

*img src: https://www.serverlesscomputing.org/wosc3/presentations/intro.pdf

5

Page 6: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Serverless Computing

Abstraction of

servers

Event-driven

instant scale

Sub-second

billing

6

Page 7: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Serverless Computing• Newer workloads are a better fit for event driven programming

– Execute application logic in response to database triggers

– Execute app logic in response to sensor data

– Execute app logic in response to scheduled tasks etc.

• Applications are charged by compute time (millisecond) rather than by

reserved resources

• Greater linkage between cloud resources used and business operations

executed

• Serverless in a nutshell

– Event-action platforms to execute code in response to events

7

Page 8: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Serverless Computing

Develop, deploy and run your applications without taking care of the

underlined servers.

- Stateless computation

- Short running

- Event driven applications

- Auto-scaling (auto scale up & down)

- Charges for actual usage

8

Page 9: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Why serverless computing is so attractive ?

• Making app development

& ops dramatically faster,

cheaper, easier

• Drives infrastructure cost

savings

9

Source: Jason McGee, IBM; Serverless Conference 2017.

Page 10: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Current platforms for serverless

10/37

Basics of Cloud Computing - Serverless Computing

Page 11: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

FaaS in Public Clouds (1/2)

● AWS Lambda

○ Run code in AWS without managing infrastructure or software

○ Java, Go, PowerShell, Node.js, C#, Python, and Ruby code

○ Pricing is based on number of requests and GB-Sec "Memory-Duration"

○ Free: 1M requests a month. After: $0.20 per 1M

○ Free: 400,000 GB-Sec. After: $0.000017 per 1 GB-Sec

● IBM BlueMix Cloud Function

○ Based on OpenWhisk - Open Source Serverless cloud platform

○ Event, trigger & rule based execution

○ Supports any language*

○ Free: 400,000 GB-Sec. After: $0.000017 per 1 GB-Sec

11/37

Basics of Cloud Computing - Serverless Computing

Page 12: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

FaaS in Public Clouds (1/2)

● Google Cloud Function

○ Started with Google App Engine in 2008

○ JavaScript, Node.js, Python, Go

○ Pricing is based on number of requests GB-Sec, and GHz-sec

○ Free: 2M invocations, 400K GB-Sec, 200K GHz-Sec of compute time a month.

● Azure Functions

○ The Functions runtime is open-source.

○ C#, JavaScript, F#, Java, PowerShell, Python

○ Free: 1M invocations per month.

After: $0.20 per million executions

○ Free: 400K GB-Sec pre month.

After: $0.000016 per GB-Sec12/37

Basics of Cloud Computing - Serverless Computing

Page 13: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

13/37

Basics of Cloud Computing - Serverless Computing

Page 14: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

● Services or data sources define the events they emit as triggers

● Event-programming model:

○ Runs code in response to events

○ Events (Trigger examples):

■ changes to database records

■ IoT sensor readings that exceed a certain temperature

■ new code commits to a GitHub repository

■ simple HTTP requests from web or mobile apps

○ Event can also trigger

■ multiple functions (parallel invocations)

14/37

Basics of Cloud Computing - Serverless Computing

Page 15: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

15/37

Basics of Cloud Computing - Serverless Computing

Page 16: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

● Action ○ a stateless function that executes arbitrary code.

○ small snippets of JavaScript or Swift code

○ custom binary code embedded in a Docker container

● Instantly deployed and executed whenever a trigger fires

● Asynchronous actions:

○ Here the invoker—caller request—does not expect a response

● Synchronously action

○ Here the invoker expects a response as a result of the action execution.

● Actions can be invoked

○ directly via REST API,

○ executed based on a trigger.

● The result of an action could also be a trigger of another function (sequential invocations).

● A set of actions can be chained

16/37

Basics of Cloud Computing - Serverless Computing

Page 17: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

17/37

# Hello world as an OpenWhisk action.

def myFunction(args):

name = args['name']

greeting = "Hello " + name + '!'

return {"greeting": greeting}

● Create an action:

wsk action create myfunction Hello-Python.py

● Invoke an action:

wsk action invoke myfunction --result --param name

World

● Update an action:

wsk action update myfunction Hello-Python.py

Basics of Cloud Computing - Serverless Computing

Page 18: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

18/37

Basics of Cloud Computing - Serverless Computing

Page 19: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

● Developers associate the actions to handle the events via rules● Rule is an association of a trigger to an action

○ Many to many mapping

● Packages are a shared

collection of Triggers

and Actions

19/37

Basics of Cloud Computing - Serverless Computing

Page 20: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Triggers, actions, rules (and packages)

20/37

Event source Serverless Function

(Lambda Function)Services

• DB changed

• Request to endpoint

• Resource state changed

• Java

• Go

• Node.js

• C#

• Python

• etc

Basics of Cloud Computing - Serverless Computing

Page 21: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Some available frameworks…

● Apache OpenWhisk

● OpenFaaS

● Open-Lambda

● Fn Project

21/37

Basics of Cloud Computing - Serverless Computing

Page 22: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Apache OpenWhisk

OpenWhisk is an event-driven compute platform also

referred to as Serverless computing or as a FaaS that runs

code in response to events or direct invocations.

● Initiated by IBM but now an Apache project

● Open source cloud platform

● Serverless deployment and operations model

● Optimal utilization and granular pricing

● Scales on a per-request basis

● Supports JS, Swift, Python, Java, Docker

22https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md

Page 23: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Apache OpenWhisk - System overview

https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md

23/37

Basics of Cloud Computing - Serverless Computing

Page 24: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Apache OpenWhisk - The internal flow of processing

https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md

24/37

Basics of Cloud Computing - Serverless Computing

Page 25: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Some available frameworks…

● Apache OpenWhisk

● OpenFaaS

● Open-Lambda

● Fn Project

25/37

Basics of Cloud Computing - Serverless Computing

Page 26: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

OpenFaaS Serverless framework

A framework for building serverless functions with Docker and Kubernetes that

offers first-class support for metrics.

● Ease of use through UI portal and one-click install

● Write services and functions in any language with Template Store or a

Dockerfile

● Build and ship your code in the Docker/OCI image format

● Portable: runs on existing hardware or public/private cloud by leveraging

Kubernetes

● CLI available with YAML format for templating and defining functions

● Auto-scales as demand increases including to zero

26/37

Basics of Cloud Computing - Serverless Computing

Page 27: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

OpenFaaS Serverless framework

27/37

Basics of Cloud Computing - Serverless Computing

Page 28: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

OpenFaaS – Templates

28/37

Basics of Cloud Computing - Serverless Computing

Page 29: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

OpenFaaS vs OpenWhisk

29/37

Basics of Cloud Computing - Serverless Computing

OpenFaaS OpenWhisk

Popularity (Github Stars) 17K 4.6K

Contributors 137 173

Stability (Corporate Backer) VMWare IBM (Apache Foundation)

Development Language Go Scala

Packaging mechanism Docker container Docker container

Underlying technology Alertmanager / Prometheus,

Nats

CouchDB, Kafka, Nginx,

Redis, Zookeeper

Page 30: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Some available frameworks…

● Apache OpenWhisk

● OpenFaaS

● Open-Lambda

● Fn Project

30/37

Basics of Cloud Computing - Serverless Computing

Page 31: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Open-Lambda

● Apache-licensed serverless computing project

● Written in Go Language

● Based on Linux containers

● Heavily relies on root privilege

● Tested on Ubuntu 16.04 LTS

31/37

Basics of Cloud Computing - Serverless Computing

Page 32: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Some available frameworks…

● Apache OpenWhisk

● OpenFaaS

● Open-Lambda

● Fn Project

32/37

Basics of Cloud Computing - Serverless Computing

Page 33: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Fn Project

● Fn Project today consists of 4 major components:○ Fn Server

■ Executes sync functions, returning responses to clients immediately

■ Executes async functions when capacity is available

○ The Fn Load Balancer

■ routes functions to certain nodes consistently for hot function efficiency

■ Scales each function independently

■ Can be used to scale Fn servers

○ Fn FDK’s:

■ Function Development Kits for popular languages - Java, Node.js, Python, Go, and Ruby

○ Fn Flow

● Supported languages: Go, Java, Node.js, Python, Ruby

33/37

Basics of Cloud Computing - Serverless Computing

Page 34: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Fn Project – Architecture

34/37

Basics of Cloud Computing - Serverless Computing

Page 35: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Fn Project – Deployment details

35/37

Basics of Cloud Computing - Serverless Computing

1. Builds container (multi-stage) + bumps version

2. Pushes container to registry

3. Creates/updates function & triggers

When you call the function via the call command or curl, the

container is executed and the results are returned to you.

Page 36: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Fn Project – Request flow

36/37

Basics of Cloud Computing - Serverless Computing

Page 37: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Advantages of Serverless/FaaS

● Very simple and "cheap" to scale

● Rapid prototyping

● Easy to modify serverless functions

● Pay only for the execution time, not for idle computation time

● Can create applications by composing functions written in different languages

37/37

Basics of Cloud Computing - Serverless Computing

Page 38: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Disadvantages of Serverless

● Harder to avoid vendor lock-in

○ Depend heavily on built in triggers and rules

● Lack of monitoring and debugging tools

● Composition and architecture complexity

● Slow cold-start

● What about stateful computations?

● Harder to predict costs

38/37

Basics of Cloud Computing - Serverless Computing

Page 39: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Common Serverless Application Use Cases

● Web applications

○ Static websites

○ Complex web apps

○ Packages for Flask and Express

● Backends○ Apps and services

○ Mobile

○ IoT

● Data processing○ Real time

○ MapReduce

○ Batch

○ Machine learning inference

39/37

● Chatbots

○ Powering chatbot logic

● Amazon Alexa○ Powering voice-enabled apps

○ Alexa Skills Kit

● IT automation○ Policy engines

○ Extending AWS services

○ Infrastructure management

Basics of Cloud Computing - Serverless Computing

Page 40: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Serverless is Good and Not Good for…

● Short-running

● Stateless

● Event-driven

- Microservices

- Mobile Backends

- Bots

- IoT

- Service Integration

- Stream processing

40/37

● Long-running

● Stateful

● Number crunching

- Databases

- DL training

- Heavy-duty stream analytics

- Numeric simulation

- Video streaming

Basics of Cloud Computing - Serverless Computing

Page 41: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

What next ???

41

Page 42: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

Let’s move to lab session…

42

Page 43: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

References

● https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md

● https://cloud.google.com/functions/docs/writing

● https://cloud.google.com/functions/pricing#compute_time

● https://docs.microsoft.com/en-us/azure/azure-functions/supported-languages

● https://azure.microsoft.com/en-us/pricing/details/functions/

● https://github.com/Azure/azure-functions-host

● https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview

● https://www.serverlesscomputing.org/wosc3/presentations/intro.pdf

● http://deck.fnproject.io/

● https://docs.google.com/presentation/d/1zdgzSgCfhmF_zK-ziMB_-

oqG2C2xVlCE90M1aO70SqU/edit#slide=id.g3063cc7e5a_0_100

43

Page 44: Basics of Cloud Computing – Lecture 4 Serverless ......Apache-licensed serverless computing project Written in Go Language Based on Linux containers Heavily relies on root privilege

44

Thank you