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

Afraid of Java cold starts in Serverless? Fear ...

Afraid of Java cold starts in Serverless? Fear not, Java is super fast!

For years, we’ve been told that Java suffers from cold starts in AWS Lambda and Serverless in general. Believe it not. Java is extremely fast to start, the simplest Java program starts in milliseconds. It’s the Java frameworks and libraries that slow things down in general. But not all of them…

In this session, I want to show you the truth about Serverless Java and cold starts, what’s slow, what’s fast and why it matters. We’ll go through what a cold start is, how cold starts in AWS Lambda impact your application responsiveness and cloud costs, and what are the options to optimize both. We’ll explore and compare Quarkus and Piranha Cloud, the most modern and fastest Jakarta EE frameworks. We’ll test the limits of what they are capable of, how fast they start and whether we even need to think about any optimizations. Then I’ll explain what optimizations may help if you need to go further, like tuning the JVM, using a custom JVM runtime or building a OS-native binary with GraalVM. However, there are also a few limitations and cost implications of these optimizations, which we'll also explain.

More information and source code examples: https://github.com/OmniFish-EE/Presentation-Superfast-Java

OmniFish Presentations

October 26, 2022
Tweet

More Decks by OmniFish Presentations

Other Decks in Programming

Transcript

  1. Ondro Mihályi @OmniFishEE Who am I? Java Champion Czech JUG

    lead (CZJUG) jug.cz or java.cz Jakarta EE specifications committer Director at OmniFish
  2. Ondro Mihályi @OmniFishEE Extensions Runtime Function Request Extensions Runtime INIT

    INVOKE SHUTDOWN At cold start Every invocation Leads to a cold start AWS Lambda Lifecycle
  3. Ondro Mihályi @OmniFishEE Extensions Runtime Function Request INIT INVOKE Every

    invocation Our code (Java) We pay only for this AWS Supported Runtimes
  4. Ondro Mihályi @OmniFishEE Where’s the catch? • Only specific language

    versions are supported – Java 11, Java 8 • Java 17 still missing • Some optimizations require a custom runtime
  5. Ondro Mihályi @OmniFishEE Extensions Runtime Function Request INIT INVOKE Our

    code (Java) We pay for everything Our custom runtime
  6. Ondro Mihályi @OmniFishEE Java startup time Plain Java starts fast

    In milliseconds, way faster than application servers or most frameworks
  7. Ondro Mihályi @OmniFishEE Overview of Quarkus AOT code optimization at

    build time Plugins for many libraries Imperative & reactive AOT injection at the core Compile to native using Graal VM
  8. Ondro Mihályi @OmniFishEE Piranha Cloud Introducing Piranha Cloud Exousia (Authorization)

    Eleos (Authentication) Expressly (EL) Transact (JTA) WaSP (JSP) Jersey (REST) Eclipselink (JPA) Weld (CDI)
  9. Ondro Mihályi @OmniFishEE Architecture of Piranha Cloud Bare‑bone & fast

    Servlet container Flat classpath, easy to embed Jakarta EE distributions Extremely modular & extensible Plain Java, no magic
  10. Ondro Mihályi @OmniFishEE Further optimizations More CPU+RAM Faster JVM Disable

    2nd tier compilation Custom JVM (JLink) Native binary (GraalVM) • CDS • CRaC
  11. Ondro Mihályi @OmniFishEE Conclusion? Similar APIs (Jakarta EE, MicroProfile) Different

    approaches (AOT vs. Optimized code) Java is not slow, frameworks are slow Piranha and Quarkus can get you up to speed
  12. Ondro Mihályi @OmniFishEE OmniFish - Jakarta EE Consulting & Support

    Jakarta EE Consultancy (migrations, tuning) Jakarta EE Application Development GlassFish Server Support omnifish.ee Jakarta EE Training