serverless computing formal foundations of€¦ · serverless programming is hard - challenges -...

56
Formal Foundations of Serverless Computing Abhinav Jangda, Donald Pickney, Samuel Baxter, Joseph Spitzer, Breanna Devore-McDonald, Yuriy Brun, Arjun Guha 1

Upload: others

Post on 27-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Formal Foundations of Serverless Computing

Abhinav Jangda, Donald Pickney, Samuel Baxter, Joseph Spitzer, Breanna Devore-McDonald, Yuriy Brun, Arjun Guha

1

Page 2: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

2

Page 3: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

:)3

Page 4: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

4

Page 5: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

5

Page 6: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

CAT

6

Page 7: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Platforms

7

Page 8: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Supported Languages

8

Page 9: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

model = CatOrDogModel ();function catOrDog (req, res) {

if (req.type === train) {model.train (req.data);

} else {res.write (model.predict (req.data));}}

Store trained model

Takes a HTTP Req

Train Model

Predict Cat or Dog

9

Page 10: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

10

Page 11: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

DOG

11

Page 12: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

model = CatOrDogModel ();function catOrDog (req, res) {

if (req.type === ‘train’) {model.train (req.data);

} else {res.write (model.predict (req.data));}}

Ephemeral State

12

Page 13: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

DOG

13

Page 14: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

DOG

14

Page 15: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

model = CatOrDogModel ();function catOrDog (req, res) {

if (req == ‘train’) {model.train (req.data);

} else {res.write (model.predict (req.data));}}

Single event processed to completion multiple times

15

Page 16: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

DOG

16

Page 17: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

17

Page 18: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

model = CatOrDogModel ();function catOrDog (req, res) {

if (req.type === ‘train’) {model.train (req.data);

} else {res.write (model.predict (req.data));}}

More than one instances of function can be running in parallel.

18

Page 19: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

CAT

19

Page 20: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

let Datastore = require('@google-cloud/datastore');Function catOrDog(req, res) { let ds = new Datastore({ projectId: 'cat-app' }); let dst = ds.transaction(); dst.run(function() { let tId = ds.key(['Transaction', req.body.transId]); dst.get(tId, function(err, trans) { if (err || trans) { dst.rollback(function() { res.send(false); }); } else if (req.body.type === ‘train') { let data = ds.key(['model', req.body.data]); dst.get(data, function(err, model) { model.train (data) dst.save({ key: data, data: model }); dst.save({ key: tId, data: {} }); dst.commit(function() { res.send(true); });}); } else if (req == ‘test’) { let data = ds.key(['prediction’, req.body.data]); dst.get(data, function(err, model) { prediction = model.predict (data) dst.save({ key: data, data: prediction }); dst.save({ key: tId, data: {} }); dst.commit(function() { res.send(prediction); });}); } else { dst.rollback(function(){res.send(false);});}});}}});});};

model = CatOrDogModel ();function catOrDog (req, res) {

if (req.type == ‘train’) {model.train (req.data);

} else {res.write (model.predict (req.data));}}

= x 4

20

Page 21: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming is Hard

- Challenges- Ephemeral State

- Need for transactions

- Concurrency

- Need a deep understanding of serverless platforms to provide robust tools to

programmers for writing correct code.

“Serverless functions are not functions in an ordinary sense”

21

Page 22: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Our Contributions- Operational semantics to model essential details of serverless platforms.

- Three case studies to show that the semantics is useful:- Idealized Semantics

- Key Value Store

- Serverless Programming Language for composing functions

22

Page 23: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

23

Page 24: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

REQUEST

+

24

Page 25: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

COLD-START

++

New NodeJS

+

WARM-START

++

Idle NodeJS

Idle NodeJS processing request

25

Page 26: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Summary

Operational semantics models all details of serverless platforms:1. New instance creation

2. Instance reuse

3. Ephemeral and persistent state

Ideally: Provide programmers higher-level abstractions

26

Page 27: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

1st Case Study: Idealized Serverless Semantics

Models an idealized serverless platform with:

Failures

27

Page 28: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

1st Case Study: Idealized Serverless Semantics

28

Page 29: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

1st Case Study: Idealized Serverless Semantics

N-Start N-Step

REQUEST COLD-START HIDDEN RESPOND DIE

N-Step N-Stop

≈ ≈ ≈ ≈

Theorem: If certain conditions are met, then Idealized Semantics is weakly bisimilar to Operational Semantics.

29

≈ ≈

Page 30: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

2nd Case Study: Semantics with Key Value Store

+

+

30

Page 31: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

3rd Case Study: Serverless Programming Language

1. Extend Operational Semantics with a serverless composition language

2. Inspired by OpenWhisk Conductor and IBM Composer

31

Page 32: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Compositions

BlackOrWhite

Black

32

Page 33: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Compositions

BlackOrWhiteCatOrDog

Black Cat

33

Page 34: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

3rd Case Study: Serverless Programming Language

a <- invoke catOrDog (in);return invoke blackOrWhite (a.animal);

catOrDog(in) blackOrWhite(a.animal)

in a a.animal

34

Page 35: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming Language (SPL)

1. OpenWhisk Conductor is executed in a

docker container.

2. SPL’s JSON Transformation can be

executed directly in OpenWhisk

Controller.

35

Page 36: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Contributions

1. Writing correct code for serverless platform is hard

2. We present Operational Semantics of serverless platform

3. We present 3 case studies to show these semantics are usefula. Naive Semantics are abstractions of operational semantics

b. Operational Semantics are extended with a Key Value store

c. Serverless Programming Language can be used to compose existing serverless functions efficiently.

36

Page 37: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

1st Case Study: Naive Serverless Semantics

N-Start N-Step

REQUEST COLD-START HIDDEN RESPOND DIE

N-Stop

≈ ≈ ≈ ≈

Theorem: If certain conditions are met, then Naive Semantics is weakly bisimilar to Operational Semantics.

37

Page 38: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

3rd Case Study: Serverless Compositions

Sufficient to describe control flow

f

invoke

f

f

>>>

f

g

g

f

first

f

38

Page 39: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Issues

let accounts = new Map();

exports.bank = function(req, res) {

accounts.set(req.body.name, req.body.value);

res.send(true);

};

➢ Ephemeral State

➢ More than one instances of function can be running in parallel.

➢ Re-invoke functions when a failure is detected.A single event may be processed to completion multiple times.

39

Page 40: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System➢ Based on experiences with major serverless computing platforms.

40

Page 41: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

+ R(f, id, v)+ R(f, id, v) + F(f, busy(id), σ)

COLD-START A new Function instance of f with initial state σ for id has started

+ R(f, id, v)+ F(f, idle, σ)

+ R(f, id, v) + F(f, busy(id), σ)

WARM-START Start executing f on an idle function instance

41

Page 42: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

+ F(f, m, σ)

DIE

42

Page 43: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Introduction to Serverless Computing

Deploys JavaScript function, foo on the cloud server

Receives data after executing function foo

Calls function foo on the server

43

Page 44: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

➢ Focus on application code only ➢ Compiles code➢ Configures OS➢ Manages resource allocation.

44

Page 45: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Function Example

let accounts = new Map();

exports.bank = function(req, res) {

accounts.set(req.body.name, req.body.value);

res.send(true);

};

Store account data

Takes a HTTP Req

Deposit the amount

45

Page 46: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming Language

a <- invoke f (in);return invoke g (a.x);

[in, {input: in}] >>> first (invoke f) >>> [a.x, {a: in, input: in}] >>> first (invoke g) >>> in[0]

in is the input to the composition

First element of array as the input to the composition

Perform JSON Transformations to store the state of composition

46

Page 47: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming Language

a <- invoke f (in);return invoke g (a.x);

f(x)[in, {}]

g(y)in

{}

a [a, {}] [a.x, {a}] a.x

47

Page 48: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

+ F(f, idle, σ)

RESPOND

+ R(f, id, v) + F(f, busy(id), σ)

Function instance has turned idle.

48

Page 49: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

+ F(f, idle, σ) S(result)

RESPOND

49

Page 50: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Operational Semantics of Serverless System

+ R(f, id, v)+ F(f, idle, σ)

+ R(f, id, v) + F(f, busy(id), σ)

WARM-START

Start executing f on an idle function instance

50

Page 51: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Need for Serverless Compositions

Scheduler

f(x) g(y)

Scheduler spends most of the time idle. Leading to double billing

x

xy

z

y

z

f(x) g(y)x y z

51

Page 52: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Need for Serverless CompositionsMerge f and g into one function

f(x) g(y)

1. Hinders code-reuse2. Does not work when

a. source code is unavailable or b. the serverless functions are written in different languages

x y z

fg (x)

52

Page 53: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Need for Serverless CompositionsThe solution should

● not lead to double billing● does not hinders code-reuse● be language agnostic

53

Page 54: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming LanguageComposition primitives for serverless platforms based on Haskell Arrows

f

invoke

f

f

>>>

f

g

g

f

first

f

Sufficient to describe control flow

54

Page 55: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming LanguageImplementations:

1. Integrated in a fork of OpenWhisk2. Portable implementation to communicate with other public cloud providers

55

Page 56: Serverless Computing Formal Foundations of€¦ · Serverless Programming is Hard - Challenges - Ephemeral State - Need for transactions - Concurrency - Need a deep understanding

Serverless Programming Language

1. Comparison to OpenWhisk Conductor2. Increasing Request Sizes3. 6-core Intel Xeon E5-1650 with 64 GB

RAM with Hyper-Threading enabled.

56