惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Maciej Walkowiak - Java & Spring

Blog Generating HTTP clients in Spring Boot application from OpenAPI spec PostgreSQL and UUID as primary key Dynamic Projections with Spring Data JPA Container logs with Spring Boot and Testcontainers Reified Generics in Java? Faster integration tests with reusable Testcontainers and Flyway Running one-time jobs with Quartz and Spring Boot The best way to use Testcontainers with Spring Boot Spring Boot & Flyway - clear database between integration tests What's new in Spring? Activate Maven Profile by Operating System Spring Boot with Thymeleaf and Tailwind CSS - Complete Guide How to publish a Java library to Maven Central - Complete Guide Docker Compose - waiting until containers are ready Single file Java applications with JBang Beautiful bash scripts with Gum Running Java on CRaC How to log PostgreSQL queries with Testcontainers Creating Spring Cloud Function projects with AWS SAM Loading classpath resources to String with a custom JUnit extension Creating Project Templates with Cookiecutter Auto-Registering JUnit 5 extensions Spring Boot component scanning without annotations Listing Maven dependencies in Spring Boot Actuator Info endpoint Spring Cloud AWS 2.3 RC2 Released How I built vlad-cli - command line interface to Vlad Mihalcea The State of Java Relational Persistence On Choosing a Tech Stack
Spring Boot 3.0 & GraalVM Native Image - not a free lunch
2022-10-24 · via Maciej Walkowiak - Java & Spring
Published on
  • Spring Boot
  • Graalvm

Spring Boot 3.0 RC1 has just been released and GA is behind the corner. One of the most important new features is a support for building GraalVM native images.

There has been a lot of hype around native images - for good reasons. In comparison to running on JVM, it brings following benefits:

  • extremely fast application startup time
  • low memory consumption
  • minimizes vulnerability
  • produces compact packages

But there are some downsides too - some specific to GraalVM, some specific to how Spring supports it.

Potentially worse runtime performance ​

It is often said that native image is faster than the JVM equivalent. It may or may not be and it heavily depends on what do you mean by "faster".

Unquestionably the startup time is orders of magnitude faster than on the traditional JVM, but the actual latency and throughput may be worse on the native image - there is no JIT compiler that optimizes code execution paths in runtime.

GraalVM team at Oracle is actively working on Native Image performance so eventually the differences may become (or have already become) negligible.

Ideally, run you own performance tests to find out how your application behaves as a native image and how as traditional JVM application.

Native hints for dependencies ​

While all projects from the Spring umbrella - including their dependencies - have been adjusted to work well with native images - there is a chance that you will want to use a dependency does not support native image out of the box.

If you are lucky, the support for it is already commited to GraalVM Reachability Metadata repository, but if not - you will be doing the work of finding out what hints specific to this library GraalVM needs.

You will either have to limit yourself to dependencies provided by the framework, or account additional efforts for making the dependencies native image friendly.

Read how to provide custom native hints.

Ideally libraries authors include all the native hints required by GraalVM in the libaries themselves, but we are not there yet.

No support for Spring Profiles ​

To build a native image, Spring beans configuration must be fixed during the build time. This means that beans cannot change in runtime or to put it in different words - beans arrangement cannot depend on the environment (environment variables, system properties, external configuration sources).

Effectively, you cannot use @Profile or @ConditionalOnProperty annotations to configure if bean will be created. When these annotations are in place, only the values known during the build time will be taken into account.

Significantly longer build times ​

Building native image takes significantly more time than building JVM equivalent. Ideally, you won't build a native image on your local machine but leave it to a CI server.

What about running tests? While you can just run regular tests on JVM, the more non-standard native image specific code you have, the more you will need to run your tests in the native mode to gain enough confidence to run it in production or even push code changes to the repository.

Luckily, Spring Boot provides a simple way to run tests in the native mode:

With Maven:

With Gradle:

Read more about Testing GraalVM Native Images.

With every GraalVM release build times get shorter - I hope this eventually becomes a non-issue.

Conclusion ​

With all these drawbacks I still believe that GraalVM is a fantastic game changing technology for the Java ecosystem, and I think there is a high chance that native image eventually becomes the default target build type we choose for Spring Boot applications.

I hope that this short blog post will help you with taking the decision if your application should be native or should run on traditional JVM.

Let's stay in touch and follow me on Twitter: @maciejwalkowiak

Subscribe to RSS feed