Skip to content

Document fixed rate scheduling with CRaC #33490

Closed
@asm0dey

Description

@asm0dey

Affects: Spring Boot 3.3.0, but I think every version supporting CRaC is affected


Consider the following simple application:

@SpringBootApplication
@EnableScheduling
class MyApp     

fun main(args: Array<String>) {
    runApplication<MyApp>(*args)
}

@RestController
class SchedulingController {
    val data = AtomicInteger(0)
    @Scheduled(timeUnit = TimeUnit.SECONDS, fixedRate = 1L)
    fun increment(){
        println(data.incrementAndGet())
    }
    @GetMapping("/")
    fun data() = data.get()
}

My actions are following

  1. ./gradlew build
  2. Build with the following Dockerfile (docker build -t last_edit_pre .):
FROM bellsoft/liberica-runtime-container:jdk-crac-slim

ADD build/libs/last_edit-0.0.1-SNAPSHOT.jar /app/app.jar
WORKDIR /app
ENTRYPOINT java -XX:CRaCCheckpointTo=/app/checkpoint -jar /app/app.jar
  1. Run it with docker run --privileged -p 8081:8080 -it --name last_edit_pre last_edit_pre:latest and wait for some time (for example, until count 10)
  2. Create a snapshot with docker exec -it last_edit_pre jcmd 129 JDK.checkpoint
  3. Commit the snapshot to new image docker commit last_edit_pre last_edit_post
  4. Run the newly-created image like this docker run -it --rm --entrypoint java last_edit_post:latest -XX:CRaCRestoreFrom=/app/checkpoint

Here I observe an interesting behavior: Counter very quickly rewinds from the checkpoint moment to current time. The later I restore from the snapshot the more iterations it quickly rewinds.

It is potentially dangerous: if the scheduled operation is CPU-intensive of performs a dangerous operation - it can actually crush the application with all range of causes.

I do realize that sometimes this behavior might be required, in this case it should probably be an application property.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions