-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable to generate and package a CDS archive #2471
Comments
Never heard of CDS, but this does seem worth looking into it at some point. Thanks for the feedback! Does CDS only work with |
Wrote a quick post about it: https://rmannibucau.metawerx.net/post/java-class-data-sharing-docker-startup Long story short, CDS is supported by any java app but classpath beginning must be stable and match the archive so jib can't use lib/*.jar for example. I wrapped jib in a custom main and gain is ~30% on java 11 (i'm using zulu) on my app (CDI) so definitively worth enabling :). |
Thanks for the info. From which Java version can we use this feature?
@GoogleContainerTools/java-tools-build I remember the discussion that we can't get rid of the classpath wildcard I have lost the confidence. (And who knows if Windows would matter if, e.g., running a Linux container on a Windows dev machine?) |
@chanseokoh think it was around java 10 (not sure commands are 100% the same in the first versions). These commands work well on java 11. |
I took Jib for a spin to see how to do this mechanically (w/o automation). The basics premises are:
It turns out that Jib's I was experimenting w/ my Hello World Spring Boot App https://github.com/saturnism/jvm-helloworld-by-example/tree/master/helloworld-springboot-tomcat
|
#2866 added the option |
@saturnism @rmannibucau @koeberlue @holledauer @olivierboudet @bric3 @guillaumeblaquiere @bilak we've released Jib 2.7.0 which added a new configuration option (
instead of the default
Expanding the dependency list will help the AppCDS use case above. Note that an expanded dependency list can become very long in practice, and we are not sure if there may be a potential issue due to a long command line ("argument list too long" or "command line is too long"). As with other Jib configurations, this option can also be set through the system property ( |
Does it work with extra classpath? Cds works with classpath prefix which must be expanded but end can stays a wildcard which helps to mount plugins. Would be great to have that feature without going with jibcore programmatic option. |
@rmannibucau no, Jib will just add the list of strings set by |
@chanseokoh it is more about ensuring extra classpath is appended to the libs than prepended (recall it was prepended at some point - https://github.com/GoogleContainerTools/jib/pull/1642/files#diff-a5317ef6dce278f4451fa8e298358067261e7d10b3cca71c093673202ebb6d5cR276 ). If prepended it breaks cds, if appended it will keep CDS working well. |
Oh, now I understand. For AppCDS to work, it's enough for only some front portion of the entire classpath to be identical and it's fine to have a different classpath entries for the back portion, including using a wildcard, right? Hmm... yeah, intentionally we prepend |
@chanseokoh well we can do anything with extensions but it kind of break using jib and using multiple extensions will quickly be hard so let's try to maybe keep it "core" until it is a specific feature? I see three simple options (in terms of usage and impl):
To have written several mains manipulating the entrypoint I'm really unhappy with this solution and it does not merge well with a concurrent extension doing the same so hope it hits jib-core/maven-plugin soon. |
Thanks for the input. Perhaps it makes sense to reduce the scope of #894 and enable simple keyword substitution only for Just in case, Jib extensions don't run concurrently but in the order they are defined. |
Yes in order but combining them is hard, it is easy to break previous one and in practise easier to use exec mvn plugin with jib-core :(. |
@saturnism I've updated your AppCDS demo using Jib 2.7.0 which has the option |
@saturnism @rmannibucau @koeberlue @holledauer @olivierboudet @bric3 @guillaumeblaquiere @bilak @bademux @ykayacan @bilak @biro456 @zecit @chlund Jib 3.1.1 is released and it creates two new JVM argument files inside an image, where they hold the computed classpath and the main class respectively. Although I haven't tried, I think this will greatly simplify the process to generate and use AppCDS. See the doc for more details. I'd like to try it myself and update the example above, but I'm not sure when I will find time for that. |
Ah, very interesting project. Thanks for the pointer. |
In my case, I can't have it to work but perhaps it is a JDK issue.
This is described in this issue but I am using OpenJDK 11.0.11 so it should be fixed. |
@olivierboudet maybe use packaged mode? |
You are totally right, it works with packaged mode but I don't see the point to use Jib without building layered images. |
@olivierboudet nothing prevents you to use layered images, put spring-boot stack in a first image (a project without spring app, use SpringApplication as fake main) then your app with the spring-boot stack as a provided dependencies and voilà. Side note being pakcage mode is not related to layers, I spoke of using target/yourapp.jar instead of resources/ and classes. |
Hi! Because this topic revolves about App CDS, I would like to know if jib will work ootb with Spring Boot 3.3's App CDS support? |
@chanseokoh @elefeint can I gently tag you to answer the question above, please? SB 3.3.0 has been released and we'd like to leverage |
Sorry, I am 2 years into a new adventure, so I can no longer make any decisions on these projects. |
@meltsufin for routing |
Is there a proposal for how this could be supported in Jib? |
I currently use the following workflow in a GitLab CICD pipeline to get this to work (this being what Spring Framework recommends: https://docs.spring.io/spring-framework/reference/integration/cds.html)
All this is with Jib and without ever using Docker (something we cannot do in our GitLab CICD environment). It works quite well, except step 3.
Now the Generally speaking, it would be good for Jib to provide a way to easily take an image previously created by Jib, and to append in various ways. That would benefit the CDS workflow of starting an application via a container, capturing some data and then putting it into a new image (optionally overwriting the old one) and adding some jvm flags. |
For that particular matter, I can think of some hacks. <properties>
<!-- comma-separated flags -->
<jib-extra-jvm-flags></jib-extra-jvm-flags>
<jib.container.jvmFlags>${jib-extra-jvm-flags}-Xms512m</jib.container.jvmFlags>
</properties>
<profiles>
<profile>
<!-- Activate this profile with `mvn -Pcds ...`. -->
<id>cds</id>
<properties>
<!-- Should end with a comma (`,`). -->
<jib-extra-jvm-flags>-XX:SharedArchiveFile=/application.jsa,</jib-extra-jvm-flags>
</properties>
</profile>
</profiles> or <properties>
<!-- single dummy flag -->
<jib-extra-jvm-flag>-Ddummy-system-property</jib-extra-jvm-flag>
</properties>
<profiles>
<profile>
<!-- Activate this profile with `mvn -Pcds ...`. -->
<id>cds</id>
<properties>
<jib-extra-jvm-flag>-XX:SharedArchiveFile=/application.jsa</jib-extra-jvm-flag>
</properties>
</profile>
</profiles>
...
<container>
<jvmFlags>
<jvmFlag>${jib-extra-jvm-flag}</jvmFlag>
<jvmFlag>-Xms512m</jvmFlag>
</jvmFlags>
|
Don't use empty tag ( tip: using -Dcontainer=true can be more relevant/less weird as default but shouldn't be used from the app to enable the customization. |
@wleese could you explain why we should build it with
I can not figure out why you pack. Thank you in general for the issues and support here. |
@artemptushkin cds works wih *.jar generally speaking so packaged is needed to not keep classes folder. |
I'm getting running the app in the container with the
the Wonder on actual of the actual algorithm of "header checksum verification" |
Okay then now I'm thinking (sorry out of the JIB context) how come CDS be more efficient if we have to the |
@artemptushkin means you compare the time to open and browse a zip or filesystem (I/O + CPU, #jars <<1000) vs the time of loading classes from zips/filesystem vs in memory (CDS). Key thing is #classes >> #jars in most apps so CDS is often way faster at memory cost for most applications and since it includes JVM classes too it is often also the cases for very small apps. Since zip are indexed and startup CPU is generally not an issue exploded vs packaged does not make a huge difference (in particular compared to having "free" classloader (in mem)). Side note: indeed it is totally wrong for spring fat jar which are zips in zip and there is is way too costly until you lost it all in mem at startup but spring boot does not do that and do a double zip lazy opening which is insanely slow. |
Maybe helpful some resources on how to run Spring Boot with Docker + CDS:
Don't know if this helps, but I though I will share it. |
@skin27 Thank you, I noticed too that they published Sebastian's presentation video from the Spring IO. And btw, I succeded with CDS and JIB - I hope a will publish a full working example |
I got back to the issue and I saw your support - thank you! I published an example of how I configured the Spring Boot app with CDS, AOT, and Jib Gradle plugin I documented it briefly but it could have been better |
@artemptushkin should we really need this in the Gradle kotlin script? I assume that should be taken care of by the spring boot plugin..rt? |
@sureshg I'd like too to be carried automatically but it's not, I'm not sure if it's an issue of AOT plugin or kinda expected. I just reversed and found so far. So yes, it's needed |
@artemptushkin Thank you for your example, but after script:
when I execute:
I got message:
although in reality it is present, somehow it is strange. I just shared with you. |
@roman4ello thanks for sharing, usually it's about the platform. It is probably built with amd/arm and docker runs another by default, I'm not sure why but this is why docker typically can not find an image |
Hi,
CDS enables java application to boot way faster (in particular when any scanning/reflection is involved) so it would be neat to integrate it with JIB.
It requires to launch 2-3 commands to generate the archive and then just bundle it and modify the jvm arguments.
https://blog.codefx.org/java/application-class-data-sharing/#Creating-A-JDK-Class-Data-Archive explains it quite well.
Since the classpath must be stable and not use folders nor wildcards, doing it in jib seems the most reliable and relevant IMHO.
Romain
The text was updated successfully, but these errors were encountered: