Skip to content

Commit

Permalink
chore(process-file): log low memory availability
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien authored and fabiengo committed Oct 4, 2024
1 parent 5fadc0e commit 240cd45
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.dossierfacile.common.entity.messaging.QueueName;
import fr.dossierfacile.common.service.interfaces.QueueMessageService;
import fr.dossierfacile.process.file.service.AnalyzeDocumentService;
import fr.dossierfacile.process.file.util.MemoryUtils;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -32,6 +33,10 @@ public void startConsumer() {

private void receiveDocument() {
try {
if (!MemoryUtils.hasEnoughAvailableMemory()) {
log.warn("There is not currently enough memory to perform consumption ");
return;
}
queueMessageService.consume(QueueName.QUEUE_DOCUMENT_ANALYSIS,
documentAnalysisDelay,
documentAnalysisTimeout,
Expand All @@ -45,5 +50,4 @@ private void receiveDocument() {
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.dossierfacile.common.entity.messaging.QueueName;
import fr.dossierfacile.common.service.interfaces.QueueMessageService;
import fr.dossierfacile.process.file.service.AnalyzeFileService;
import fr.dossierfacile.process.file.util.MemoryUtils;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -30,6 +31,10 @@ public void startConsumer() {

private void receiveFile() {
try {
if (!MemoryUtils.hasEnoughAvailableMemory()) {
log.warn("There is not currently enough memory to perform consumption ");
return;
}
queueMessageService.consume(QueueName.QUEUE_FILE_ANALYSIS,
0,
fileAnalysisTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.dossierfacile.common.entity.messaging.QueueName;
import fr.dossierfacile.common.service.interfaces.QueueMessageService;
import fr.dossierfacile.process.file.service.interfaces.MinifyFileService;
import fr.dossierfacile.process.file.util.MemoryUtils;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -32,6 +33,10 @@ public void startConsumer() {

private void receiveFile() {
try {
if (!MemoryUtils.hasEnoughAvailableMemory()) {
log.warn("There is not currently enough memory to perform consumption ");
return;
}
queueMessageService.consume(QueueName.QUEUE_FILE_MINIFY,
0,
fileMinifyTimeout,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.dossierfacile.process.file.util;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MemoryUtils {
// TODO currently we only log low availability
public static boolean hasEnoughAvailableMemory() {
Runtime runtime = Runtime.getRuntime();
// Arbitrary choose 250MB as minimal requirement to perform
if (runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory() < 262144000) {
log.warn("Memory usage: (Total=" + runtime.totalMemory() / 1024 + " MB , max=" + runtime.maxMemory() / 1024 + " MB , free=" + runtime.freeMemory() / 1024 + " MB , avail=" + (runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory()));
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ spring.profiles.active=test
server.port=${port:8080}
server.tomcat.uri-encoding=UTF-8
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
application.domain=https://api-dev.dossierfacile.fr
application.base.url=

#Liquibase Configuration
spring.liquibase.enabled=false
Expand Down

0 comments on commit 240cd45

Please sign in to comment.