Slide 1

Slide 1 text

14 performance 
 improvements for your 
 Serverless Java functions Jeroen Reijn # jfall.

Slide 2

Slide 2 text

Foto: Annette Bernhardt (CC BY-SA 2.0) My name is Jeroen Reijn #Luminis #Java #AWS #Serverless | @jreijn

Slide 3

Slide 3 text

Foto: Annette Bernhardt (CC BY-SA 2.0) Serverless functions 🚀 Photo by Vladimir Anikeev on Unsplash

Slide 4

Slide 4 text

Foto: Annette Bernhardt (CC BY-SA 2.0) Java = Slow? 🤔 Photo by Razvan Cristea on Unsplash

Slide 5

Slide 5 text

Foto: Annette Bernhardt (CC BY-SA 2.0) Cold 🥶 Starts Photo by Hakan Aldrin on Unsplash

Slide 6

Slide 6 text

What are cold starts? Source: https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/

Slide 7

Slide 7 text

When do they happen? Source: https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/

Slide 8

Slide 8 text

How often do they happen? Source: https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/

Slide 9

Slide 9 text

Foto: Annette Bernhardt (CC BY-SA 2.0) So what can we do?

Slide 10

Slide 10 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 1. More memory 
 = 
 More vCPUs Photo by Christian Wiediger on Unsplash

Slide 11

Slide 11 text

Memory vs vCPUs Source: https://www.sentiatechblog.com/aws-re-invent-2020-day-3-optimizing-lambda-cost-with-multi-threading

Slide 12

Slide 12 text

Memory vs vCPUs

Slide 13

Slide 13 text

Memory vs vCPUs Source: https://catalog.workshops.aws/java-on-aws-lambda/en-US/02-accelerate/power-tuning

Slide 14

Slide 14 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 2. Static initialization Photo by Michael Dziedzic on Unsplash

Slide 15

Slide 15 text

Static Initialization

Slide 16

Slide 16 text

Static Initialization

Slide 17

Slide 17 text

Static Initialization

Slide 18

Slide 18 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 3. Use lightweight dependencies Photo by Pedro Vit on Unsplash

Slide 19

Slide 19 text

Lightweight dependencies

Slide 20

Slide 20 text

Lightweight dependencies

Slide 21

Slide 21 text

Lightweight dependencies

Slide 22

Slide 22 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 4. Precon fi guration Photo by Rima Krucieneon Unsplash

Slide 23

Slide 23 text

Be explicit in configuration

Slide 24

Slide 24 text

Be explicit in configuration

Slide 25

Slide 25 text

Be explicit in configuration

Slide 26

Slide 26 text

Be explicit in configuration

Slide 27

Slide 27 text

Be explicit in configuration

Slide 28

Slide 28 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 5. Tiered Compilation Photo by Patti Black on Unsplash

Slide 29

Slide 29 text

Tiered compilation Interpreter C1: No pro fi ling C1: Limited Pro fi ling C1: Full Pro fi ling C2 0 1 2 3 4 Compilation level Slower Faster

Slide 30

Slide 30 text

Tiered compilation

Slide 31

Slide 31 text

Tiered compilation

Slide 32

Slide 32 text

Tiered compilation Settings Type # of invocations p90 (ms) p95 (ms) p99 (ms) Default settings Cold start 754 5,212 5,338 5,517 Default settings Warm start 35,247 58 93 255 Tiered compilation stopping at level 1 Cold start 383 2,071 2,086 2,221 Tiered compilation stopping at level 1 Warm start 35,618 23 32 86 Source: https://aws.amazon.com/blogs/compute/increasing-performance-of-java-aws-lambda-functions-using-tiered-compilation/

Slide 33

Slide 33 text

Tiered compilation Settings Type # of invocations p90 (ms) p95 (ms) p99 (ms) Default settings Cold start 754 5,212 5,338 5,517 Default settings Warm start 35,247 58 93 255 Tiered compilation stopping at level 1 Cold start 383 2,071 2,086 2,221 Tiered compilation stopping at level 1 Warm start 35,618 23 32 86 Source: https://aws.amazon.com/blogs/compute/increasing-performance-of-java-aws-lambda-functions-using-tiered-compilation/

Slide 34

Slide 34 text

Tiered compilation Settings Type # of invocations p90 (ms) p95 (ms) p99 (ms) Default settings Cold start 754 5,212 5,338 5,517 Default settings Warm start 35,247 58 93 255 Tiered compilation stopping at level 1 Cold start 383 2,071 2,086 2,221 Tiered compilation stopping at level 1 Warm start 35,618 23 32 86 Source: https://aws.amazon.com/blogs/compute/increasing-performance-of-java-aws-lambda-functions-using-tiered-compilation/

Slide 35

Slide 35 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 6. Provisioned Concurrency Photo by Sigmund on Unsplash

Slide 36

Slide 36 text

Concurrency As demand increases, the Lambda service increases concurrent executions • One function instance handles one request • Concurrency is a measure of concurrent executions

Slide 37

Slide 37 text

Lambda initialisation

Slide 38

Slide 38 text

Provisioned Concurrency Source: https://aws.amazon.com/blogs/compute/operating-lambda-performance-optimization-part-1/

Slide 39

Slide 39 text

Provisioned Concurrency

Slide 40

Slide 40 text

Autoscaling

Slide 41

Slide 41 text

Autoscaling

Slide 42

Slide 42 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 7. Frameworks Photo by Dayne Topkin on Unsplash

Slide 43

Slide 43 text

Which Framework?

Slide 44

Slide 44 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 8. No Framework Photo by Gemma Evans on Unsplash

Slide 45

Slide 45 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 9. Package size Photo by Nam Anh on Unsplash

Slide 46

Slide 46 text

Package size Jar size Libraries + Classpath scanning

Slide 47

Slide 47 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 10. GraalVM 
 AOT Native Image Photo by Patti Black on Unsplash

Slide 48

Slide 48 text

GraalVM

Slide 49

Slide 49 text

GraalVM Source: https://www.graalvmonlambda.com/walkthrough/graalvm-performance/

Slide 50

Slide 50 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 11. CRaC Photo by Malcolm Lightbody on Unsplash

Slide 51

Slide 51 text

Coordinated Restore at Checkpoint- CRAC • Creates a checkpoint (make an image of, snapshot) a Java instance while it is executing and then restores the state of the JVM from this snapshot • Part of OpenJDK • Experimental • Micronaut recently added support

Slide 52

Slide 52 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 12. Parallelize Photo by the blowup on Unsplash

Slide 53

Slide 53 text

Parallelize Leverage those vCPUs!

Slide 54

Slide 54 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 13. Switch to ARM Photo by Christian Wiediger on Unsplash

Slide 55

Slide 55 text

Foto: Annette Bernhardt (CC BY-SA 2.0) 14. Be careful with layers Photo by Clark Van Der Beken on Unsplash

Slide 56

Slide 56 text

Layers can add (a lot) of latency Removed OTEL layer

Slide 57

Slide 57 text

Foto: Annette Bernhardt (CC BY-SA 2.0) Overall impact Photo by César Couto on Unsplash

Slide 58

Slide 58 text

Migrating a Spring Boot application Source: https://catalog.workshops.aws/java-on-aws-lambda/en-US/01-migration/results

Slide 59

Slide 59 text

Thanks for your attention Please rate my session in the J-Fall app # jfall. Reach out at @jreijn