Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Performance-Tweaks für Java-Serverless-Anwendungen

Performance-Tweaks für Java-Serverless-Anwendungen

Serverless-Funktionen erfreuen sich zunehmender Beliebtheit. Der Fokus auf den Funktionscode (und nicht auf die darunterliegende Serverinfrastruktur) sowie die dynamische Anpassung an den aktuellen Ressourcenbedarf sind einige Gründe dafür. Doch nicht selten orientieren sich erfahrene Java-Entwickler und -Architekten in diesem Zuge neu und schwenken auf alternative Programmiersprachen wie Node.js oder Python. Hintergrund ist die Abrechnung von Serverless-Funktionen basierend auf Ausführungsdauer (CPU-Zeit) und Speicherverbrauch. Java wird in diesem Zuge immer noch als Speicher-hungrig und langsam (Cold starts) eingeordnet.

Der Vortrag zeigt auf, welche Stellschrauben bei Java in Verbindung mit Serverless-Anwendungen betrachtet werden sollten. Dabei werden sowohl Parameter der JVM (wie Heap Size, Garbage Collection und Tiered Compilation) betrachtet als auch ein Überblick über Frameworks und Tools (wie GraalVM, Quarkus, Micronaut und Spring Native) gegeben.

Dennis Kieselhorst

June 30, 2022
Tweet

More Decks by Dennis Kieselhorst

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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<Event> instead of RestController (directly handle API-Gateway events instead of HTTP) • Be careful with dependency injection: Annotation scanning adds more class loading. 16
  16. 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%
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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/