© 2016 IBM Corporation© 2016 IBM Corporation
Introduction to
serverless and
OpenWhisk
© 2016 IBM Corporation© 2016 IBM Corporation
THE CASE FOR
SERVERLESS
© 2016 IBM Corporation© 2016 IBM Corporation
Welcome to Industrial internet!
© 2016 IBM Corporation© 2016 IBM Corporation
Devices can be...
© 2016 IBM Corporation© 2016 IBM Corporation
How would you implement it?
© 2016 IBM Corporation© 2016 IBM Corporation
OK, let’s move step by step
© 2016 IBM Corporation© 2016 IBM Corporation
And if you want it to be HA?
© 2016 IBM Corporation© 2016 IBM Corporation
What about another device?
© 2016 IBM Corporation© 2016 IBM Corporation
Let’s be smart!
© 2016 IBM Corporation© 2016 IBM Corporation
An unexpected spike!
© 2016 IBM Corporation© 2016 IBM Corporation
Scaling out!
© 2016 IBM Corporation© 2016 IBM Corporation
And traffic goes down...
© 2016 IBM Corporation© 2016 IBM Corporation
An excessive compute?
© 2016 IBM Corporation© 2016 IBM Corporation
Or maybe those ones?
© 2016 IBM Corporation© 2016 IBM Corporation
And in the meantime...
© 2016 IBM Corporation© 2016 IBM Corporation
And further down...
© 2016 IBM Corporation© 2016 IBM Corporation
And...
© 2016 IBM Corporation© 2016 IBM Corporation
Ideal case
© 2016 IBM Corporation© 2016 IBM Corporation
Compute follows traffic
© 2016 IBM Corporation© 2016 IBM Corporation
Compute follows traffic
© 2016 IBM Corporation© 2016 IBM Corporation
So what are the requirements?
● Invoke and scale as fast as possible
● Terminate after completion
© 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
© 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
© 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
© 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
© 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
© 2016 IBM Corporation© 2016 IBM Corporation
Twelve Factor App was created as a methodology for building SaaS…
I. Codebase
One codebase tracked in revision control,
many deploys
II. Dependencies
Explicitly declare and isolate dependencies
III. Config
Store config in the environment
IV. Backing services
Treat backing services as attached resources
V. Build, release, run
Strictly separate build and run stages
VI. Processes
Execute the app as one or more stateless
processes
https://12factor.net/
VII. Port binding
Export services via port binding
VIII. Concurrency
Scale out via the process model
IX. Disposability
Maximize robustness with fast startup and graceful
shutdown
X. Dev/prod parity
Keep development, staging, and production as
similar as possible
XI. Logs
Treat logs as event streams
XII. Admin processes
Run admin/management tasks as one-off processes
Serverless and the 12 Factor App?
© 2016 IBM Corporation© 2016 IBM Corporation
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)
© 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)
© 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
© 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
2
Pool of actions
Swift DockerJS
Running
action
Running
action
Deploy action within millisecs,
run it,
free up resources
OpenWhisk
Engine
OpenWhisk model
© 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
© 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)
© 2016 IBM Corporation© 2016 IBM Corporation
JavaPythonJavaScriptSwiftContainer
Polyglot action implementation
Trigger
Event
Action
© 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
© 2016 IBM Corporation© 2016 IBM Corporation
Trigger: „A class of events that can happen“T
Trigger
© 2016 IBM Corporation© 2016 IBM Corporation
A Actions: „An event-handler, i.e. code that runs in response to an event“
Action
© 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
© 2016 IBM Corporation© 2016 IBM Corporation
R
R := T A
Rules: „An association of a trigger and an action“
Rule
© 2016 IBM Corporation© 2016 IBM Corporation
myAction
myFeedT
A
Packages: „A shared collection of triggers and actions“P
A forecast
Open
Source
Yours
Third
Party
translate
languageId
textToSpeechA
A
A
databaseCreate
documentRead
...
changesT
A
A
A
Push
Notifications
sendMessage
webhookT
A
webhookT
postA
Websocket
sendA
Package
© 2016 IBM Corporation© 2016 IBM Corporation
Some usage Scenarios
Microservices-based apps / APIs
Mobile Backends
Data (Stream) Processing
IoT
Cognitive
Bots
© 2016 IBM Corporation© 2016 IBM Corporation
What is serverless good for?
© 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?
© 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
© 2016 IBM Corporation© 2016 IBM Corporation
GETTING
STARTED
© 2016 IBM Corporation© 2016 IBM Corporation
https://github.com/openwhisk
OpenWhisk Command Line
wsk trigger create <trigger-name>
1. Creating a trigger
wsk package create <package-name>
2. Creating a package
wsk action create <package>/<action> <Jar File>.jar
3. 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
Deploying to Bluemix
Deploying Locally
git 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.
© 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
© 2016 IBM Corporation© 2016 IBM Corporation
One last demo… did you like my talk?
https://github.com/l2fprod/openwhisk-emoting
Simplicity can be unsettling…
© 2016 IBM Corporation© 2016 IBM Corporation
DISCUSSION

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

  • 1.
    © 2016 IBMCorporation© 2016 IBM Corporation Introduction to serverless and OpenWhisk
  • 2.
    © 2016 IBMCorporation© 2016 IBM Corporation THE CASE FOR SERVERLESS
  • 3.
    © 2016 IBMCorporation© 2016 IBM Corporation Welcome to Industrial internet!
  • 4.
    © 2016 IBMCorporation© 2016 IBM Corporation Devices can be...
  • 5.
    © 2016 IBMCorporation© 2016 IBM Corporation How would you implement it?
  • 6.
    © 2016 IBMCorporation© 2016 IBM Corporation OK, let’s move step by step
  • 7.
    © 2016 IBMCorporation© 2016 IBM Corporation And if you want it to be HA?
  • 8.
    © 2016 IBMCorporation© 2016 IBM Corporation What about another device?
  • 9.
    © 2016 IBMCorporation© 2016 IBM Corporation Let’s be smart!
  • 10.
    © 2016 IBMCorporation© 2016 IBM Corporation An unexpected spike!
  • 11.
    © 2016 IBMCorporation© 2016 IBM Corporation Scaling out!
  • 12.
    © 2016 IBMCorporation© 2016 IBM Corporation And traffic goes down...
  • 13.
    © 2016 IBMCorporation© 2016 IBM Corporation An excessive compute?
  • 14.
    © 2016 IBMCorporation© 2016 IBM Corporation Or maybe those ones?
  • 15.
    © 2016 IBMCorporation© 2016 IBM Corporation And in the meantime...
  • 16.
    © 2016 IBMCorporation© 2016 IBM Corporation And further down...
  • 17.
    © 2016 IBMCorporation© 2016 IBM Corporation And...
  • 18.
    © 2016 IBMCorporation© 2016 IBM Corporation Ideal case
  • 19.
    © 2016 IBMCorporation© 2016 IBM Corporation Compute follows traffic
  • 20.
    © 2016 IBMCorporation© 2016 IBM Corporation Compute follows traffic
  • 21.
    © 2016 IBMCorporation© 2016 IBM Corporation So what are the requirements? ● Invoke and scale as fast as possible ● Terminate after completion
  • 22.
    © 2016 IBMCorporation© 2016 IBM Corporation So what are the requirements? ● Invoke and scale as fast as possible ● Terminate after completion ● Charge per compute used
  • 23.
    © 2016 IBMCorporation© 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
  • 24.
    © 2016 IBMCorporation© 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
  • 25.
    © 2016 IBMCorporation© 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
  • 26.
    © 2016 IBMCorporation© 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
  • 27.
    © 2016 IBMCorporation© 2016 IBM Corporation Twelve Factor App was created as a methodology for building SaaS… I. Codebase One codebase tracked in revision control, many deploys II. Dependencies Explicitly declare and isolate dependencies III. Config Store config in the environment IV. Backing services Treat backing services as attached resources V. Build, release, run Strictly separate build and run stages VI. Processes Execute the app as one or more stateless processes https://12factor.net/ VII. Port binding Export services via port binding VIII. Concurrency Scale out via the process model IX. Disposability Maximize robustness with fast startup and graceful shutdown X. Dev/prod parity Keep development, staging, and production as similar as possible XI. Logs Treat logs as event streams XII. Admin processes Run admin/management tasks as one-off processes Serverless and the 12 Factor App?
  • 28.
    © 2016 IBMCorporation© 2016 IBM Corporation SERVERLESS & OPENWHISK
  • 29.
    © 2016 IBMCorporation© 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)
  • 30.
    © 2016 IBMCorporation© 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)
  • 31.
    © 2016 IBMCorporation© 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
  • 32.
    © 2016 IBMCorporation© 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 2 Pool of actions Swift DockerJS Running action Running action Deploy action within millisecs, run it, free up resources OpenWhisk Engine OpenWhisk model
  • 33.
    © 2016 IBMCorporation© 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
  • 34.
    © 2016 IBMCorporation© 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)
  • 35.
    © 2016 IBMCorporation© 2016 IBM Corporation JavaPythonJavaScriptSwiftContainer Polyglot action implementation Trigger Event Action
  • 36.
    © 2016 IBMCorporation© 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
  • 37.
    © 2016 IBMCorporation© 2016 IBM Corporation Trigger: „A class of events that can happen“T Trigger
  • 38.
    © 2016 IBMCorporation© 2016 IBM Corporation A Actions: „An event-handler, i.e. code that runs in response to an event“ Action
  • 39.
    © 2016 IBMCorporation© 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
  • 40.
    © 2016 IBMCorporation© 2016 IBM Corporation R R := T A Rules: „An association of a trigger and an action“ Rule
  • 41.
    © 2016 IBMCorporation© 2016 IBM Corporation myAction myFeedT A Packages: „A shared collection of triggers and actions“P A forecast Open Source Yours Third Party translate languageId textToSpeechA A A databaseCreate documentRead ... changesT A A A Push Notifications sendMessage webhookT A webhookT postA Websocket sendA Package
  • 42.
    © 2016 IBMCorporation© 2016 IBM Corporation Some usage Scenarios Microservices-based apps / APIs Mobile Backends Data (Stream) Processing IoT Cognitive Bots
  • 43.
    © 2016 IBMCorporation© 2016 IBM Corporation What is serverless good for?
  • 44.
    © 2016 IBMCorporation© 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?
  • 45.
    © 2016 IBMCorporation© 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
  • 46.
    © 2016 IBMCorporation© 2016 IBM Corporation GETTING STARTED
  • 47.
    © 2016 IBMCorporation© 2016 IBM Corporation https://github.com/openwhisk
  • 48.
    OpenWhisk Command Line wsktrigger create <trigger-name> 1. Creating a trigger wsk package create <package-name> 2. Creating a package wsk action create <package>/<action> <Jar File>.jar 3. 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
  • 49.
  • 50.
    Deploying Locally git 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.
  • 51.
    © 2016 IBMCorporation© 2016 IBM Corporation Dark Vision https://github.com/IBM-Bluemix/openwhisk-darkvisionapp Discover dark data in videos with IBM Watson and IBM Bluemix OpenWhisk
  • 52.
    © 2016 IBMCorporation© 2016 IBM Corporation One last demo… did you like my talk? https://github.com/l2fprod/openwhisk-emoting Simplicity can be unsettling…
  • 53.
    © 2016 IBMCorporation© 2016 IBM Corporation DISCUSSION