RED-6126: performance-test
*fixed time calculation
This commit is contained in:
parent
8db0b712f7
commit
7065d098f3
@ -66,15 +66,18 @@ public class OCRService {
|
|||||||
public void runOcrOnDocument(String dossierId, String fileId, OutputStream out) throws IOException {
|
public void runOcrOnDocument(String dossierId, String fileId, OutputStream out) throws IOException {
|
||||||
|
|
||||||
try (ByteArrayOutputStream transferOutputStream = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream transferOutputStream = new ByteArrayOutputStream()) {
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
|
|
||||||
try (InputStream fileStream = fileStorageService.getOriginalFileAsStream(dossierId, fileId)) {
|
try (InputStream fileStream = fileStorageService.getOriginalFileAsStream(dossierId, fileId)) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
log.info("Start invisible element removal for file with dossierId {} and fileId {}", dossierId, fileId);
|
||||||
invisibleElementRemovalService.removeInvisibleElements(fileStream, transferOutputStream, false);
|
invisibleElementRemovalService.removeInvisibleElements(fileStream, transferOutputStream, false);
|
||||||
}
|
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
log.info("Invisible element removal successful for file with dossierId {} and fileId {}, took {}s", dossierId, fileId, format("%.1f", (float) ((end - start) / 1000)));
|
log.info("Invisible element removal successful for file with dossierId {} and fileId {}, took {}s", dossierId, fileId, format("%.1f", (end - start) / 1000.0));
|
||||||
|
}
|
||||||
try (InputStream transferInputStream = new ByteArrayInputStream(transferOutputStream.toByteArray())) {
|
try (InputStream transferInputStream = new ByteArrayInputStream(transferOutputStream.toByteArray())) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
runOcr(transferInputStream, out, fileId);
|
runOcr(transferInputStream, out, fileId);
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
log.info("ocr successful for file with dossierId {} and fileId {}, took {}s", dossierId, fileId, format("%.1f", (end - start) / 1000.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,12 +96,12 @@ public class OCRService {
|
|||||||
Map<Integer, RectCollection> pageIdToRectCollection = imagePositionRetrievalService.getImagePositionPerPage(pdfDoc, true);
|
Map<Integer, RectCollection> pageIdToRectCollection = imagePositionRetrievalService.getImagePositionPerPage(pdfDoc, true);
|
||||||
|
|
||||||
int numProcessedPages = 0;
|
int numProcessedPages = 0;
|
||||||
|
// optimization: only scanning pages that contain images
|
||||||
for (Integer pageId : pageIdToRectCollection.keySet()) {
|
for (Integer pageId : pageIdToRectCollection.keySet()) {
|
||||||
try {
|
try {
|
||||||
// optimization: creating a new document is faster than reusing the same and adding/removing pages one by one
|
// optimization: creating a new document is faster than reusing the same and adding/removing pages one by one
|
||||||
OCROptions options = new OCROptions();
|
OCROptions options = new OCROptions();
|
||||||
PDFDoc ocrPageDoc = new PDFDoc();
|
PDFDoc ocrPageDoc = new PDFDoc();
|
||||||
// optimization: only scanning pages that contain images
|
|
||||||
Page pdfPage = pdfDoc.getPage(pageId);
|
Page pdfPage = pdfDoc.getPage(pageId);
|
||||||
// optimization: this line ensures the ocr text is placed correctly by PDFTron
|
// optimization: this line ensures the ocr text is placed correctly by PDFTron
|
||||||
pdfPage.setMediaBox(pdfPage.getCropBox());
|
pdfPage.setMediaBox(pdfPage.getCropBox());
|
||||||
|
|||||||
@ -31,14 +31,13 @@ public class OcrMessageReceiver {
|
|||||||
|
|
||||||
private final OCRService ocrService;
|
private final OCRService ocrService;
|
||||||
|
|
||||||
|
|
||||||
@RabbitHandler
|
@RabbitHandler
|
||||||
@RabbitListener(queues = MessagingConfiguration.OCR_QUEUE, concurrency = "1")
|
@RabbitListener(queues = MessagingConfiguration.OCR_QUEUE, concurrency = "1")
|
||||||
public void receiveOcr(String in) throws JsonProcessingException {
|
public void receiveOcr(String in) throws JsonProcessingException {
|
||||||
|
|
||||||
DocumentRequest ocrRequestMessage = objectMapper.readValue(in, DocumentRequest.class);
|
DocumentRequest ocrRequestMessage = objectMapper.readValue(in, DocumentRequest.class);
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
log.info("Start ocr for file with dossierId {} and fileId {}", ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId());
|
log.info("Start ocr for file with dossierId {} and fileId {}", ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId());
|
||||||
|
|
||||||
setStatusOcrProcessing(ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId());
|
setStatusOcrProcessing(ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId());
|
||||||
@ -58,10 +57,8 @@ public class OcrMessageReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
long end = System.currentTimeMillis();
|
|
||||||
log.info("Successfully processed ocr for file with dossierId {} and fileId {}, took {}", ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId(), end - start);
|
|
||||||
|
|
||||||
fileStatusProcessingUpdateClient.ocrSuccessful(ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId());
|
fileStatusProcessingUpdateClient.ocrSuccessful(ocrRequestMessage.getDossierId(), ocrRequestMessage.getFileId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user