KEMBAR78
High Performance Serverless Functions in Scala | PPTX
High Performance Serverless
Functions in Scala
Scale BTB • November 14, 2019
Hello
Scale By
The Bay!
Hello
Scale By
The Bay!
High Performance Serverless
Functions in Scala
Scale BTB • November 14, 2019
High Performance Serverless
Functions in Scala
with AWS Lambda
Scale BTB • November 14, 2019
Vanilla Sally
And The Tale Of The
Growling Lambs!
Vanilla Sally & Growling Lambs
Vanilla Scala & Graal Lambda
Vanilla Scala
Compiled With
Graal For Lambda!
Let
Me Try To
Explain This
1. Write your Lambda Functions in Vanilla Scala
2. Package to a big ol’ fat Jar
3. Compile to native Linux code with GraalVM
4. Setup a Serverless config w/ lots o mem
5. Deploy away!
Fast Scala Serverless Functions
Solution
Vanilla Scala
Compiled With
Graal For Lambda!
Okay, That’s The
Entire Talk
Let’s Run To The Snack Bar Before The Other Talks Finish
Problem
I Want To Write a Slack App...
Choosing Scala on AWS Lambda
Choosing Scala on AWS Lambda
What’s
The Challenge?
Slack App
Response Times
< 3 Seconds
api.slack.com
User Flow
Response Times
< 1 Second
Jakob Nielsen, Usability Engineering (1995)
Instantaneous Reaction
Response Times
< 0.1 Seconds
Jakob Nielsen, Usability Engineering (1995)
Well? We’re Waiting….
JVM on AWS Lambda is
Pretty Slow
Especially when
Booting the JVM
Slack
User Flow
“Native images compiled with
GraalVM ahead-of-time improve
the startup time and reduce the
memory footprint of JVM
applications.”
JVM vs GraalVM
So How Does
AWS Lambda
handle Native Code?
AWS Lambda Custom Runtime
1. [Your Linux Executable Initialization Here]
2. Do an HTTP GET
"http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next"
1. Parse the API Gateway or SQS or other request
2. Repeat
Dockerfile
FROM oracle/graalvm-ce:1.0.0-rc16
WORKDIR /tmp/dist
CMD native-image -jar /tmp/target/app.jar --enable-
http 
--enable-https -H:+JNI bootstrap
build.sh
(cd .. && sbt ";test;project query;assembly")
docker run -v "$(pwd -P)/target/scala-2.12":/tmp/target -v
"$(pwd -P)/dist":/tmp/dist buildable
(cd dist && zip -9 bootstrap.zip bootstrap cacerts
libsunec.so)
User Flow
Plain Scala Code
Reflection
JNI
Dynamic Class Loading
Apache HttpComponents
Most Scala Http Libraries
Jsoniter-Scala
Most Scala JSON Libraries
Hand-Written API Clients
Provided API Clients
reflectconfig.json
{
"name": "com.sun.xml.internal.stream.XMLInputFactoryImpl",
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
}
Vanilla Sally
And The Tale Of The
Growling Lambs!
Vanilla Scala
Safely Compiles
With GraalVM
Okay, Probably I’m
Finished
Are There Any Good Snacks Left?
Introduction
Speaker Introduction
Jason Swartz
@swartzrock
WORK FUNCTIONAL PROGRAMMING
High Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala

High Performance Serverless Functions in Scala