jCuDoS is a set of CLI tools for simplifying the use of Application Class Data Sharing to multiple Spring Boot applications of the same project. Usually such applications have quite large common subset of the same classes (from JDK to Spring to application libraries) what makes the leveraging of AppCDS beneficial from both startup time and (especially) memory footprint point of view.
jCuDoS consists of several useful commands which can be called either separately or together (by means of the root jcudos
command). In the last case, they will perform the following algorithm.
- There is a set of Spring Boot “fat” JARs from all the applications (microservices);
- All the JARs reside on the same filesystem (not necessary in the same directory);
- All the microservices were at least once launched with the
-XX:DumpLoadedClassList
JVM option.
- A Glob to the lists of classes gathered with
-XX:DumpLoadedClassList
; - A Glob to “fat” JARs;
- Desired path to a common output directory (the following steps assume
_appcds
).
- Find out the common part of the lists;
- Save it into
_appcds/_shared/list/classes.list
0️⃣.
- Detect the name of the start class.
If no name is detected (i.e. the JAR is not a Spring Boot one), skip the archive.
Remember the name of the application as “raw” class name in lower case (referring later as
<appname>
, for example class namedcom.example.MyCoolApp
yieldsmycoolapp
application name). - Store the start class name into
_appcds/<appName>/start-class.txt
1️⃣. - Extract the libraries of the current “fat” JAR into
_appcds/<appName>/lib/
. - Convert current “fat” JAR into
_appcds/<appName>/lib/<appName>.slim.jar
2️⃣.
-
Find out the common libraries names from listings of each
_appcds/<appName>/lib/
directory. -
Copy all the found libraries into
_appcds/_shared/lib/
. -
Compose the
_appcds/_shared/list/classpath.arg
5️⃣ file from absolute paths of the copied libraries. -
Remember the list of absolute paths of// the common libraries 3️⃣.
-
Navigate to
_appcds
directory and execute there:java -Xshare:dump \ -XX:SharedClassListFile=_shared/list/classes.list \ -XX:SharedArchiveFile=_shared/jsa/classes.jsa \ @_shared/list/classpath.arg &> log/dump.log
Here were used:
_appcds/_shared/list/classes.list
0️⃣ and_appcds/_shared/list/classpath.arg
5️⃣.
- Remove all the common libraries 3️⃣ from the each
_appcds/<appName>/lib/
directory. - Compose
_appcds/<appName>/appcds.arg
4️⃣ file from:-XX:SharedArchiveFile=_appcds/_shared/jsa/classes.jsa
option;-classpath
option which in turn consists of:- common libraries list 3️⃣;
- own libraries list taken as
_appcds/<appName>/lib/
directory listing. The slim JAR_appcds/<appName>/lib/<appName>.slim.jar
2️⃣ should be included there as well; - the name of the start class 1️⃣.
- In the launch script, just replace the
-jar <appName>.jar
with@appcds.arg
4️⃣.
➕ There is much more information about the project like examples, statistics, observations, comparison tables, etc. Please contact me if it interests you.