In the process of implementing batch jobs in Spring Batch and Spring WebFlux environments, OOM occurred. We also confirmed memory leaks through heap memory graphs, etc.
While looking for the cause of the memory leak, I removed the part that used ReactiveMongoTemplate and found that the memory leak did not occur. Accordingly, we tested a number of cases and found the following conclusions:
CustomStudentRepository: CustomRepository created using ReactiveMongoTemplate
Student: Entity
- Mono.block() after Flux.collectList()
fun write(chunk: Chunk<out Mono<Student>>) {
Flux.concat(chunk.items)
.flatMap { customStudentRepository.upsert(it) }
.collectList()
.block()
}
- List.map() after Flux.block()
fun write(chunk: Chunk<out Mono<Student>>) {
Flux.concat(chunk.items)
.collectList()
.block()!!
.map {
customStudentRepository.upsert(it)
.block()
}
}
Memory leaks only occur in the former case(1. Mono.block() after Flux.collectList()).
Why does the memory leak occur only in the former case?
- I tried using the ReactiveMongoRepository implementation instead of ReactiveMongoTemplate, but the result was the same.
Sangyoon Jeong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.