View
4
Download
0
Category
Preview:
Citation preview
Cloud Computing – Lecture 4
Function as a Service – Serverless
Computing2 March 2021
Chinmaya Dehury
chinmaya.dehury@ut.ee
1
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
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 this concept onto
IaaS cloud model ?
3
Serverless Computing
*img src: https://www.serverlesscomputing.org/wosc3/presentations/intro.pdf
4
Serverless Computing - Features
Abstraction of
servers
Event-driven
instant scale
Sub-second
billing
5
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
6
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
7
Why serverless computing is so attractive ?
• Making app development
& ops dramatically faster,
cheaper, easier
• Drives infrastructure cost
savings
8
Source: Jason McGee, IBM; Serverless Conference 2017.
Vendors providing serverless computing
9
IBM- Cloud Functions
…and the most popular one is…
10/37Src: https://trends.google.com/trends/explore?date=today%205-
y&q=AWS%20Lambda,Cloudflare%20workers,Azure%20function,Google%20Cloud%20function,IBM%20Cloud%20Function
…and the most popular one is…
11/37Src: https://trends.google.com/trends/explore?date=today%205-y&q=%2Fg%2F11c0q_754d,%2Fg%2F11bw4c_dgq
FaaS in Public Clouds (1/4)
● 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
○ Some limit:
■ Function and layer storage (.zip file archives): 75GB,
■ Memory: upto 10GB
■ Concurrency: 1000 (can be increased)
■ Timeout: 900sec
12/37https://aws.amazon.com/about-aws/whats-new/2020/12/aws-lambda-supports-10gb-memory-6-vcpu-cores-lambda-functions/
FaaS in Public Clouds (2/4)
● IBM BlueMix Cloud Function○ IBM Bluemix, rebranded IBM Cloud in 2017
○ 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
○ Some limits:
■ Code size: 48MB
■ Memory: 128 MB -2GB
■ Concurrency: 1000
■ Timeout: 100ms – 600sec
13/37Src: https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-limits
FaaS in Public Clouds (3/4)
● 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.
○ Some limits:
■ Code size: 100MB (compressed) for sources. 500MB (uncompressed) for sources plus
modules.
■ Memory: 4GB
■ Concurrency: 1000
■ Timeout: 540sec
■ HTTP request size per invocation: 10MB
14/37
FaaS in Public Clouds (4/4)
● 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-Sec
○ Some limits:
■ Code size: no limit
■ Memory: 1.5 – 14 GBGB
■ Timeout: can be unbounded
■ Request size : 100MB
15/37Src: https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/azure-subscription-service-limits#azure-functions-limits
Triggers, actions, rules (and packages)
16/37
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)
17/37
Triggers, actions, rules (and packages)
18/37
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
● 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
19/37
Triggers, actions, rules (and packages)
● Asynchronous actions/invocation:
○ Here the invoker—caller request—does not expect a response
● Synchronously action/invocation:
○ Here the invoker expects a response as a result of the action execution.
20/37
Src:
https://docs.aws.amazon.com/lambda/latest/dg/images/invo
cation-sync.png
Src:
https://docs.aws.amazon.com/lambda/latest/dg/images/features-
async.png
Triggers, actions, rules (and packages)
21/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
Triggers, actions, rules (and packages)
22/37
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
23/37
Triggers, actions, rules (and packages)
24/37
Event source Serverless Function
(Lambda Function)Services
• DB changed
• Request to endpoint
• Resource state changed
• Java
• Go
• Node.js
• C#
• Python
• etc
Some available frameworks…
● Apache OpenWhisk
● OpenFaaS
● Fn Project
25/37
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
26https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md
Apache OpenWhisk - System overview
https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md
27/37
Apache OpenWhisk - The internal flow of processing
https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md
28/37
Apache OpenWhisk - The internal flow of processing
https://github.com/apache/incubator-openwhisk/blob/master/docs/about.md29/37
Nginx:
• exposes the public-facing HTTP(S) endpoint to the clients.
• Every request (even from wsk CLI) must go through this layer.
Controller
• Performs the authentication and authorization of every request.
• Responsible for the actual implementation of the OpenWhisk API.
• Decides the path that the request will eventually take
CouchDB
• To maintain the state of the system.
• The credentials, metadata, namespaces, and the definitions of
actions, triggers, and rules, are stored in CouchDB.
Consul
• Provides service discovery capabilities
• Allows controller to discover Invokers to invoke an Action.
Kafka
• Kafka buffers the messages sent by the Controller
Some available frameworks…
● Apache OpenWhisk
● OpenFaaS
● Fn Project
30/37
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
31/37
OpenFaaS Serverless framework
32/37Recommended
OpenFaaS workflow
33/37
• faas-netes : Kubernetes controller for OpenFaaS
• NATS provides asynchronous execution and queuing
• Prometheus provides metrics and enables auto-scaling through AlertManager
OpenFaaS – Templates
34/37
OpenFaaS vs OpenWhisk
35/37
OpenFaaS OpenWhisk
Popularity (Github Stars) 19K 5.2K
Contributors 156 184
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
Some available frameworks…
● Apache OpenWhisk
● OpenFaaS
● Fn Project
38/37
Fn Project
● Oracle announced the Fn project.
● Can be hosted on any cloud (private cloud, AWS, Oracle Cloud, Google
Cloud, and so on)
● Only requirement to run Fn is a Docker engine.
● Supported languages: Go, Java, Node.js, Python, Ruby
39/37
Fn Project
● Fn Project 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
40/37
Fn Project – Architecture
41/37
Fn Project – Deployment details
42/37
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.
Something different project…. Serverless Framework
● It is not a serverless platform, just a packaging mechanism.
● A software development kit for serverless.
● The package can be deployed on Lambda, Google Functions, Azure
Functions, Apache OpenWhisk, Cloudflare Workers, OpenFaas, Kubeless or
Fn
44
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
45/37
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
46/37
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
47/37
● Chatbots
○ Powering chatbot logic
● Amazon Alexa○ Powering voice-enabled apps
○ Alexa Skills Kit
● IT automation○ Policy engines
○ Extending AWS services
○ Infrastructure management
Use Cases
48
Thomson Reuters
● Provides companies with the intelligence, technology, and human expertise
for quick decisions making.
● AWS Lambda allows Thomson Reuters to
○ load and process the streaming data
○ collects data from the Kinesis pipeline
○ loads data into the master dataset in Amazon S3
○ Lambda is triggered by Amazon S3 upon new data arrival
49
iRobot
● A global consumer robot company.
● Focusing on home-cleaning robot category
● iRobot is using about 25 AWS services.
● AWS Lambda and AWS IoT platform at the core
● AWS IoT platform : Provides the connectivity layer between the robots and
the iRobot cloud platform
● AWS Lambda runs code in response to events to provide function-based
compute services50
GreenQ
● Smart residential waste collection.
● Optimize every aspect of waste collection from scheduling and routing to
major fleet vehicle decisions and contract optimization.
● OpenWhisk serverless platform:
○ Collects information regarding every waste bin pickup
○ Every file and every MQTT message being uploaded to Bluemix triggers OpenWhisk actions
51
Serverless is Good and Not Good for…
● Short-running
● Stateless
● Event-driven
- Microservices
- Mobile Backends
- Bots
- IoT
- Service Integration
- Stream processing
53/37
● Long-running
● Stateful
● Number crunching
- Databases
- DL training
- Heavy-duty stream analytics
- Numeric simulation
- Video streaming
What next ???
54
Let’s move to lab session…
55
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://netflix.github.io/titus/
● https://www.youtube.com/watch?v=66PxX3oGVCA
● https://aws.amazon.com/solutions/case-studies/thomson-reuters/
● https://aws.amazon.com/solutions/case-studies/irobot/
● https://thenewstack.io/behind-scenes-apache-openwhisk-serverless-platform/
● Dehury, Chinmaya, et al. "Data Pipeline Architecture for Serverless Platform." European Conference
on Software Architecture. Springer, Cham, 2020. 56
57
Thank you
Recommended