example-spring-boot's People
Forkers
antonkozlov iamahgoub sullis rogervinas goliath suixingbugai majguo sdeleuze making adel5210 dejan2609 denniskawurek rvansa cyberneticsexample-spring-boot's Issues
Issue CRaC with Postgres DB
I have demo app using CRaC and Postgres DB. I can build app using docker but it can't start
This issue error:
org.springframework.context.ApplicationContextException: Failed to take CRaC checkpoint on refresh at org.springframework.context.support.DefaultLifecycleProcessor$CracDelegate.checkpointRestore(DefaultLifecycleProcessor.java:534) ~[spring-context-6.1.3.jar!/:6.1.3] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:193) ~[spring-context-6.1.3.jar!/:6.1.3] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:978) ~[spring-context-6.1.3.jar!/:6.1.3] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.1.3.jar!/:6.1.3] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.2.jar!/:3.2.2] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.2.jar!/:3.2.2] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.2.jar!/:3.2.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[spring-boot-3.2.2.jar!/:3.2.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.2.2.jar!/:3.2.2] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.2.2.jar!/:3.2.2] at com.example.graalvm.GraalvmApplication.main(GraalvmApplication.java:10) ~[!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) ~[graalvm-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) ~[graalvm-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) ~[graalvm-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] Caused by: org.crac.CheckpointException: null at org.crac.Core$Compat.checkpointRestore(Core.java:144) ~[crac-1.4.0.jar!/:na] at org.crac.Core.checkpointRestore(Core.java:237) ~[crac-1.4.0.jar!/:na] at org.springframework.context.support.DefaultLifecycleProcessor$CracDelegate.checkpointRestore(DefaultLifecycleProcessor.java:528) ~[spring-context-6.1.3.jar!/:6.1.3] ... 17 common frames omitted Suppressed: jdk.internal.crac.impl.CheckpointOpenSocketException: tcp localAddr 192.168.107.3 localPort 56378 remoteAddr 192.168.107.2 remotePort 5432 at java.base/jdk.internal.crac.Core.translateJVMExceptions(Core.java:91) ~[na:na] at java.base/jdk.internal.crac.Core.checkpointRestore1(Core.java:145) ~[na:na] at java.base/jdk.internal.crac.Core.checkpointRestore(Core.java:246) ~[na:na] at java.base/jdk.internal.crac.Core.checkpointRestore(Core.java:231) ~[na:na] at jdk.crac/jdk.crac.Core.checkpointRestore(Core.java:70) ~[jdk.crac:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.crac.Core$Compat.checkpointRestore(Core.java:141) ~[crac-1.4.0.jar!/:na] ... 19 common frames omitted
Repo demo: https://github.com/hoangphuc2k/graalvm-demo
Some questions about CRaC in the case of large memory in Java
I referred to the provided sample project , performed local simulation, and followed the modified code and steps below to verify the working mechanism of CRaC under large memory conditions. I found that Java It turns out that the large memory in the running state does not occupy system memory after checkpoint/restore. Is this because CRaC restore reads process data from the dumped file instead of using system memory? Looking forward to your reply.
code show as below
package com.example.springboot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@Autowired
private HelloService helloService;
@GetMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
@GetMapping("/allocate")
public void allocate(){
helloService.allocate4GB();
}
@GetMapping("/getSize")
public String getListSize(){
return String.valueOf(helloService.getMemoryListSize());
}
@GetMapping("/getBytesSize")
public String getBytesSize(){
return String.valueOf(helloService.getBytesSize());
}
@GetMapping("/getListToString")
public String getListToString(){
return helloService.getListToString();
}
}
package com.example.springboot;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class HelloService{
private List<byte[]> memoryList = new ArrayList<>();
public void allocate4GB() {
try {
long totalMemoryInBytes = 4L * 1024 * 1024 * 1024; // 4GB
int chunkSize = 1024 * 1024 * 1024; // 1GB
int numChunks = (int) (totalMemoryInBytes / chunkSize);
for (int i = 0; i < numChunks; i++) {
byte[] data = new byte[chunkSize];
Arrays.fill(data, (byte) 'A'); // Fill array with character 'A'
memoryList.add(data);
}
System.out.println("Allocated 4GB of memory using chunks.");
} catch (OutOfMemoryError e) {
System.err.println("Out of memory!");
}
}
public long getMemoryListSize(){
return memoryList.size();
}
public long getBytesSize(){
if (getMemoryListSize() <= 0){
return 0;
}
return memoryList.get(0).length;
}
public String getListToString(){
StringBuffer sb = new StringBuffer();
if (getMemoryListSize() <= 0){
return "empty!";
}
for (byte[] bytes : memoryList){
sb.append(bytes[0]);
}
return sb.toString();
}
}
The main purpose of this code is to demonstrate the checkpoint and restore operations when Java allocates large memory (4GB).
My steps are as follows:
- Type the above code into jar
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ ./mvnw package
- Start jar package
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ $JAVA_HOME/bin/java -XX:CRaCCheckpointTo=checkpoint/cr -Xms1g -Xmx6g -jar target/example-spring-boot-0.0.1-SNAPSHOT.jar
- Detect the memory status and list status at this time
# It can be found that the memory used at this time is 4.2GB
tovi@toviserver:~/Projects/CRaC/example-spring-boot/checkpoint$ free -h
total used free shared buff/cache available
memory: 15Gi 4.2Gi 8.5Gi 395Mi 2.9Gi 10Gi
swap: 2.0Gi 0.0Ki 2.0Gi
# And you can find that no large memory has been allocated at this time
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getBytesSize
0
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getSize
0
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getListToString
empty!
- Trigger simulated large memory write scenario
# This situation requires writing 4GB of memory (all character arrays of 'A')
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/allocate
# The console will print Allocated 4GB of memory using chunks.
- Detect the memory status and list status after triggering large memory writing
# It can be found that the memory used at this time is 8.2GB. Compared with the large memory that was not written before, 4GB of memory has been added, indicating that the large memory has been written.
tovi@toviserver:~/Projects/CRaC/example-spring-boot/checkpoint$ free -h
total used free shared buff/cache available
memory: 15Gi 8.2Gi 4.4Gi 395Mi 2.9Gi 6.7Gi
swap: 2.0Gi 0.0Ki 2.0Gi
# It can be found that the size of the bytes array at this time is 1024 * 1024 * 1024 = 1GB, and the starting character is 65, which is 'A'
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getBytesSize
1073741824
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getSize
4
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getListToString
65656565
- Perform checkpoint
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ jcmd target/example-spring-boot-0.0.1-SNAPSHOT.jar JDK.checkpoint
143664:
CR: Checkpoint ...
# After completion, you can find that there is a checkpoint dump file in the cr directory and the size is 4.3GB, which is consistent with the 4GB large memory written.
tovi@toviserver:~/Projects/CRaC/example-spring-boot/checkpoint$ du -sh cr/
4.3G cr/
# At this point the service has been paused and the memory has been released
tovi@toviserver:~/Projects/CRaC/example-spring-boot/checkpoint$ free -h
total used free shared buff/cache available
memory: 15Gi 4.0Gi 4.3Gi 395Mi 7.2Gi 10Gi
swap: 2.0Gi 0.0Ki 2.0Gi
- Perform a restore to check the memory status and list status at this time. the memory usage has not reached 8.4GB
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ $JAVA_HOME/bin/java -XX:CRaCRestoreFrom=checkpoint/cr
2024-01-09T16:00:08.278+08:00 INFO 143664 --- [Attach Listener] o.s.c.support.DefaultLifecycleProcessor : Restarting Spring-managed lifecycle beans after JVM restore
2024-01-09T16:00:08.293+08:00 INFO 143664 --- [Attach Listener] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path ''
2024-01-09T16:00:08.295+08:00 INFO 143664 --- [Attach Listener] o.s.c.support.DefaultLifecycleProcessor : Spring-managed lifecycle restart completed (restored JVM running for 74 ms)
# At this time, the memory usage has not reached 8.4GB? why is that?
tovi@toviserver:~/Projects/CRaC/example-spring-boot/checkpoint$ free -h
total used free shared buff/cache available
memory: 15Gi 4.1Gi 4.3Gi 395Mi 7.2Gi 10Gi
swap: 2.0Gi 0.0Ki 2.0Gi
# At this time, according to the provided interface, it can be seen that the large array written is still there, and it is found that the service is still available, indicating that the restore is successful.
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getBytesSize
1073741824
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getSize
4
tovi@toviserver:~/Projects/CRaC/example-spring-boot$ curl http://localhost:8080/getListToString
65656565
Fails to run with `openjdk 17-crac 2021-09-14`
Running sample application with openjdk 17-crac 2021-09-14
fails with:
java.lang.IllegalStateException: Cannot load configuration class: com.example.springboot.Application
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:414) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:254) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:282) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:126) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) ~[spring-boot-2.0.5.RELEASE.jar!/:2.0.5.RELEASE]
at com.example.springboot.Application.main(Application.java:13) ~[classes!/:0.0.1-SNAPSHOT]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[spring-boot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[spring-boot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[spring-boot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[spring-boot-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: java.lang.ExceptionInInitializerError: null
at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:122) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:110) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:403) ~[spring-context-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
... 20 common frames omitted
Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @198e2867
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:336) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:93) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:91) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:116) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:291) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
... 23 common frames omitted
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @198e2867
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) ~[na:na]
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) ~[na:na]
at org.springframework.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) ~[na:na]
at org.springframework.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:52) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:329) ~[spring-core-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
... 35 common frames omitted
As far as I can tell, the version of Spring Boot used in this example is not compatible with Java 11. On the other hand, raising the Spring Boot version causes incompatibilities with crac-enabled Tomcat fork. Currently I don't see a way to run this example 🤷♂️
How start the app in tomcat
How to run a project using crac in tomcat? Or does crac support tomcat now?
dockerfile
it would be nice if there was an example of how to use CRaC in dockerfile
how to start with CRaC when enable jvm gc files.
Run during development inside IDEA
Is it possible to run during development within IDEA?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.