Slide 1

Slide 1 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. Performance-Tweaks für Java-Serverless- Anwendungen Dennis Kieselhorst Sr. Solutions Architect Amazon Web Services

Slide 2

Slide 2 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. What is Serverless? No infrastructure provisioning, no management Automatic scaling Pay for value Highly available and secure

Slide 3

Slide 3 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Let‘s start with a non-serverless architecture… 3

Slide 4

Slide 4 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. …and transform it to a first serverless architecture 4

Slide 5

Slide 5 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Tune the serverless function's resources… AWS Lambda exposes only a memory control, with the % of CPU core and network capacity allocated to a function proportionally. Is your code CPU, network or memory-bound? If so, it could be cheaper to increase memory. > Memory, > vCPU, > Network

Slide 6

Slide 6 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. …with Power Tuning 6 https://github.com/alexcasalboni/aws-lambda-power-tuning

Slide 7

Slide 7 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. The lifecycle of your AWS Lambda function Time Load and initialize handler JVM start Run handler code Compile Package Deploy Download code Build and deploy Initialize Handler invocation

Slide 8

Slide 8 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Time The lifecycle of your AWS Lambda function Load and initialize handler JVM start Run handler code Compile Package Deploy Cold start Download code Warm start Build and deploy Handler invocation Initialize

Slide 9

Slide 9 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Provisioned Concurrency • Managed solution to avoid „cold starts“ • You set provisioned concurrency for individual functions • No code changes required • Integrated with AWS Auto Scaling • Additional costs 9

Slide 10

Slide 10 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Time The lifecycle of your AWS Lambda function Load and initialize handler JVM start Run handler code Compile Package Deploy Download code Boosted host CPU access Build and deploy Handler invocation Initialize up to 10 seconds

Slide 11

Slide 11 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Time Eliminate or move activities to earlier phases Load and initialize handler JVM start Run handler code Compile Package Deploy Download code Build and deploy Handler invocation Initialize up to 10 seconds Avoid: normal Lambda charges incur

Slide 12

Slide 12 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Monitor and tune the Garbage Collection Monitor the Garbage Collection logs, try a fixed heap size specific to your application. Example shows 100 calls with heap size 400 MB: • 5% call duration reduction • Only minor garbage collection activities

Slide 13

Slide 13 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Tiered Compilation Setting Set JVM tiered compilation level to 1 and use the C1 compiler. JAVA_TOOL_OPTIONS= -XX:+TieredCompilation -XX:TieredStopAtLevel=1 C1 compiler quickly produces native code. No profiling overhead, but no benefits from more aggressive C2 compilation. related blogpost

Slide 14

Slide 14 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. AWS SDK and Common Runtime Client • As of today there are two version of the AWS SDK for Java (AWS SDK for Java v1 and AWS SDK for Java v2 ). • We recommend to use the latest version AWS SDK for Java v2 because it has been designed to improve the performance and usability. • The AWS Common Runtime (CRT) HTTP client is a new HTTP client you can use with the AWS SDK for Java v2. The CRT-based HTTP client is an asynchronous, non-blocking HTTP client built on top of the Java bindings of the AWS Common Runtime. 15

Slide 15

Slide 15 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Dependencies • Trade-off between feature richness & performance • Examples ▪ jackson-jr for serializiation ▪ SimpleLogger for logging ▪ Spring FunctionHandler instead of RestController (directly handle API-Gateway events instead of HTTP) • Be careful with dependency injection: Annotation scanning adds more class loading. 16

Slide 16

Slide 16 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Compile your application ahead-of-time (AOT) • GraalVM creates a native image of your application at build-time. • Frameworks like Quarkus, Micronaut, and Spring Native integrate GraalVM and add further benefits like build-time dependency injection. • Some JVM features not supported. • Application startup time reduced of more than 90%

Slide 17

Slide 17 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Custom AWS silicon with 64-bit Arm cores Targeted optimizations to reduce costs Rapidly innovate, build, and iterate Range of instance types Same AWS Nitro building blocks Best performance per watt of energy use in Amazon EC2 AWS Graviton2 & Graviton3 X86 vs. ARM – AWS Graviton processor

Slide 18

Slide 18 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Future • The Java ecosystem is adapting introduced several new projects to foster innovation. • Project Leyden will address startup time, memory footprint and peak performance by introducing a concept of static images to the Java Platform, and to the JDK. • The changes to the release cycle mean that innovation will be delivered faster. 19

Slide 19

Slide 19 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. Q&A 20

Slide 20

Slide 20 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Resources • Samples: https://github.com/aws-samples/serverless-java- frameworks-samples/ • GraalVM ▪ https://www.graalvmonlambda.com ▪ https://github.com/aws-samples/serverless-graalvm-demo • Quarkus: https://aws.amazon.com/blogs/architecture/deploy- quarkus-based-applications-using-aws-lambda-with-aws-sam/ • Micronaut: https://micronaut-projects.github.io/micronaut- aws/latest/guide/ 21

Slide 21

Slide 21 text

CLOUDLAND 2022 - PERFORMANCE-TWEAKS FÜR JAVA-SERVERLESS-ANWENDUNGEN © 2022, Amazon Web Services, Inc. or its affiliates. Thank you! © 2022, Amazon Web Services, Inc. or its affiliates. Dennis Kieselhorst linkedin.com/in/kieselhorst/