ibm bluemix paris meetup #22-20170315 meetup @villagebyca - serverless & openwhisk

53
© 2016 IBM Corporation © 2016 IBM Corporation Introduction to serverless and OpenWhisk

Upload: ibm-france-lab

Post on 21-Mar-2017

62 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Introduction to serverless and OpenWhisk

Page 2: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

THE CASE FOR SERVERLESS

Page 3: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Welcome to Industrial internet!

Page 4: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Devices can be...

Page 5: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

How would you implement it?

Page 6: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

OK, let’s move step by step

Page 7: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

And if you want it to be HA?

Page 8: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

What about another device?

Page 9: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Let’s be smart!

Page 10: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

An unexpected spike!

Page 11: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Scaling out!

Page 12: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

And traffic goes down...

Page 13: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

An excessive compute?

Page 14: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Or maybe those ones?

Page 15: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

And in the meantime...

Page 16: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

And further down...

Page 17: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

And...

Page 18: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Ideal case

Page 19: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Compute follows traffic

Page 20: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Compute follows traffic

Page 21: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

So what are the requirements?

● Invoke and scale as fast as possible● Terminate after completion

Page 22: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

So what are the requirements?

● Invoke and scale as fast as possible● Terminate after completion● Charge per compute used

Page 23: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

So what are the requirements?

● Invoke and scale as fast as possible● Terminate after completion● Charge per compute used● Guaranteed message delivery● Load balancing

Page 24: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

So what are the requirements?

● Invoke and scale as fast as possible● Terminate after completion● Charge per compute used● Guaranteed message delivery● Load balancing● High availability● Self-healing

Page 25: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

So what are the requirements?

● Invoke and scale as fast as possible● Terminate after completion● Charge per compute used● Guaranteed message delivery● Load balancing● High availability● Self-healing

● Support of multiple technologies

● Have possibility to launch other microservices

● Write and read data from multiple data sources

Page 26: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

So what are the requirements?

● Invoke and scale as fast as possible● Terminate after completion● Charge per compute used● Guaranteed message delivery● Load balancing● High availability● Self-healing

● Support of multiple technologies

● Have possibility to launch other microservices

● Write and read data from multiple data sources

● Abstract developers from the infrastructure

Page 27: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Twelve Factor App was created as a methodology for building SaaS…

I. CodebaseOne codebase tracked in revision control, many deploys

II. DependenciesExplicitly declare and isolate dependencies

III. ConfigStore config in the environment

IV. Backing servicesTreat backing services as attached resources

V. Build, release, runStrictly separate build and run stages

VI. ProcessesExecute the app as one or more stateless processes

https://12factor.net/VII. Port bindingExport services via port binding

VIII. ConcurrencyScale out via the process model

IX. DisposabilityMaximize robustness with fast startup and graceful shutdown

X. Dev/prod parityKeep development, staging, and production as similar as possible

XI. LogsTreat logs as event streams

XII. Admin processesRun admin/management tasks as one-off processes

Serverless and the 12 Factor App?

Page 28: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

SERVERLESS

&

OPENWHISK

Page 29: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

OpenWhisk in a nutshell

„Event-action platform to execute code in response to events“

* whisk (v): to move nimbly and quickly (source: merriam-webster.com)

Page 30: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

OpenWhisk in a nutshell

„Event-action platform to execute code in response to events“

Delivered as open source & managed service on IBM Bluemix

* whisk (v): to move nimbly and quickly (source: merriam-webster.com)

Page 31: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Swift

Application

Container VMCF

2

Polling

1b

Request

1a

• Continuous polling

• Charges even when idling due to poor utilization

• Worry about scaling- When to scale? (mem-, cpu-, response time-driven)- How fast to scale?

• Worry about resiliency- At least 2 processes for HA (driving cost)- Deployment in multiple regions (driving cost)- Keep them running & healthy Process & idle

Traditional model

Page 32: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

• Introduces event programming model

• Charges only for what is used due to optimal utilization

• Scales inherently- One process per request

• No cost overhead for resiliency- No long running process for HA

3

Running action

1

Trigger

2Pool of actions

Swift DockerJS

Running action

Running action

Deploy action within millisecs,run it, free up resources

OpenWhisk Engine

OpenWhisk model

Page 33: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

} 1

Event Providers

OpenWhisk

Cloudant

Push Notifcations

IoT message

File Storage

Data event occurs, e.g.-Commit on a Git Repository-CRUD operation on Cloudant-….

Trigger execution of associated OpenWhisk action

2

…JS Swift Docker …

Action triggered by an external event

Page 34: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

OpenWhisk

JS Swift Docker …

Incoming HTTP request, e.g.HTTP GET mynewcoolapp.com/customers

1 2 Invoke associated OpenWhisk action „getCustomers“

Browser

Mobile App

Web App

Variety of languages

Action triggered directly by an application (Action as API)

Page 35: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Actions are only alive for the duration of the execution!

Trigger+Action = Rule

Java Python JavaScript Swift Container

Polyglot action implementation

Trigger

Event

Action

Page 36: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

• Services define the events they emit as triggers, and developers associate the actions to handle the events via rules

• The developer only needs to care about implementing the desired application logic - the system handles the rest

T R A

Triggers > Rules > Actions

Page 37: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Trigger: „A class of events that can happen“T

Trigger

Page 38: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

A Actions: „An event-handler, i.e. code that runs in response to an event“

Action

Page 39: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

A

AA:= A1

+ A2+ A3

AB:= A2

+ A1+ A3

AC:= A3

+ A1+ A2

Actions: Can be chained to create sequences to increase flexibility and foster reuse

Action Sequence

Page 40: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

R

R := T A

Rules: „An association of a trigger and an action“

Rule

Page 41: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

myActionmyFeedT

A

Packages: „A shared collection of triggers and actions“P

A forecast

OpenSource YoursThird

Party

translatelanguageIdtextToSpeechA

AA

databaseCreatedocumentRead...changesT

AAA

Push Notifications

sendMessagewebhookT

A

webhookT

postA

WebsocketsendA

Package

Page 42: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Some usage Scenarios

Microservices-based apps / APIs

Mobile Backends

Data (Stream) Processing

IoT

Cognitive

Bots

Page 43: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

What is serverless good for?

Page 44: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Less is more… Avoid heavy-weight functions• Harder to debug• Harder to reuse

Triggers do not guarantee order of processing…• Message affinity is bad… avoid it at all costs

Plan how your input and output are designed to maximize reuse• Ability to re-use an action depends on the assumption it is making about its input• Assert aggressively!

What should you keep in mind while working with serverless?

Page 45: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

You want to try OpenWhisk on your own?

• Want to try out our IBM Bluemix OpenWhisk offering?Sign-up today at: https://console.ng.bluemix.net/openwhisk/

• Want to try out our open-source OpenWhisk offering?Visit: https://developer.ibm.com/openwhisk/

Try it today

Page 46: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

GETTING STARTED

Page 47: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

https://github.com/openwhisk

Page 48: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

OpenWhisk Command Linewsk trigger create <trigger-name>1. Creating a trigger

wsk package create <package-name>2. Creating a package

wsk action create <package>/<action> <Jar File>.jar3. Creating an action

wsk package bind /whisk.system/websocket <bind-name> -p uri ws://<url>4. Create a binding for an action

wsk rule create <rule-name> <trigger> <action>5. Create a rule for triggering an action

Installing OpenWhisk CLI can be found here: https://new-console.ng.bluemix.net/openwhisk/cli

Page 49: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

Deploying to Bluemix

Page 50: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

Deploying Locallygit clone --depth=1 https://github.com/openwhisk/openwhisk.git

cd openwhisk/tools/vagrant

./hello

1. Deploying OpenWhisk in a VM:

Pre-requistes:• VirtualBox• Vagrant

wsk -i property set --apihost 192.168.33.13 --auth `vagrant ssh -- cat openwhisk/ansible/files/auth.guest`

2. Setting up wsk CLI environment

Note: There are a more complete deployment of OpenWhisk described in github but this approach provides a good way to test your actions locally.

Page 51: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

Dark Vision

https://github.com/IBM-Bluemix/openwhisk-darkvisionapp

Discover dark data in videos with IBM Watson and IBM Bluemix OpenWhisk

Page 52: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

One last demo… did you like my talk?

https://github.com/l2fprod/openwhisk-emoting

Simplicity can be unsettling…

Page 53: IBM Bluemix Paris Meetup #22-20170315 Meetup @VillagebyCA - Serverless & OpenWhisk

© 2016 IBM Corporation© 2016 IBM Corporation

DISCUSSION