Performance Concerns for TIFF to PDF Conversion

Itsak26:
Could you please share the converted PDF.
Hi Wasim,

Please find attached the PDF generated over my end using latest release of Aspose.Pdf for Java 10.9.0.

Hi Wasim,


Thanks for your patience. In reference PDFNEWJAVA-34791 our product team has investigated the issue and it is recommended to use SetBlackWhite() property to true in TIFF to PDF conversion, it will not only improve the performance but will also reduce the size of resultant PDF document.

…<o:p></o:p>

image.setBlackWhite(true);

....



Furthermore increasing java heap memory size as following will also enhance the performance.

Xmx1024m -Xms1024m


Please feel free to contact us for any further assistance.


Best Regards,

Hi,

I installed latest Aspose PDF library 11.0 and below is the observation,
1. Time taken to generate the PDF is reduced considerably. File got converted within a minute.
2. The size of the generated PDF is at par with the source image file.

Thanks so much for fixing these issues.
But still the memory taken for this conversion is too much and CPU utilization also reaching very high about 60-70% during conversion.
I have already set JVM to max 1024 MB in 32 bit JVM env.
I had also tried some “CacheOndiskOnly” method which was suggested earlier but that didnt work.

Can you please look into high memory and CPU usage?

Thanks,
Wasim

Hi Waseem,


Thanks for your feedback. It is good to know that image processing time and size issues’ fix worked for you.

In reference to memory consumption and CPU usage, I have tested the scenario using your above shared TIFF image(200001999.tif) and noticed that CPU usage remains between 40-20% most of the time. It rises to 60% for a fraction of second in start, it can be the reason that Aspose.Pdf uses memory for processing instead disk space. However if you have noticed the issue with some other image then please share that sample image so we will investigate it further and guide you accordingly.

Best Regards,

Hi again,

Yes the CPU utilization remains high only for some time but the other issue I mentioned is of memory consumption.
It is now seen as after processing 5-6 files of such kind, the memory consumption goes to the maximum available RAM ( 1GB in this case) and after that the applications just stops processing any more file.
Once the file is processed, memory used should come down to normal usage value similar to CPU utilization, isnt it?
Can we avoid the RAM being used to load the image pixels into PDF something like “cacheondiskonly” solution?
Please look into it urgently as we are again stuck to the issue where files are not getting processed albeit after some time now after your fix.

Thanks,
Wasim

Hi Wasim,

Thanks for your feedback. I am afraid Aspose.Pdf does not support cache on disk feature. However you can use MemoryCleaner object to clean the memory. After completing operations with Aspose.Pdf object you can close object with close() or dispose() methods and finally use com.aspose.pdf.MemoryCleaner.clear() method, It clears Aspose.Pdf specific instances and will enables you to effective memory usage.

Please note it is recommended that you should call this method only if there is a shortage of available memory. Please find sample code to check memory status.

Runtime rt = Runtime.getRuntime();
long max = rt.maxMemory()/1048576;
long total = rt.totalMemory()/1048576;
long free = rt.freeMemory()/1048576;
long used = total - free;

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

com.aspose.pdf.MemoryCleaner.clear() doesn’t seem to clear the memory as memory taken to process Tiff remains high even after PDF is generated.
Here is the thing
1) I tried setBlackWhite as true, it works for the size and time issue but memory taken up is too high and eventually the applications goes in hanging mode.
2) I tried converting multipage tiff to Jpeg images and generating PDF from jpeg. Still the same memory issue.
3) I tried scaling down the tiff frames at compromise of quality. It works for some time and delays the inevitable but application still hangs albeit after processing more number of files compared to point 1 above.

Therefore, I am requesting you yet again for the issue which I faced more than one year back and notified the support team. My application still hangs during high resolution multipage tiff file to PDF conversion.
Please mark this request as urgent and fix as soon as possible. We are in critical stage of our project and hope that this issue would not need further escalation.

Thanks,
Wasim

Hi Wasim,


Thanks for your feedback. We are looking into it and will get back to you soon.

Best Regards,
Hi Wasim,

We are sorry for the inconvenience. We will appreciate it if you please share a sample (high resolution)TIFF that causing the issue. We will look into it and will provide you information accordingly.

Furthermore please provide some more details about com.aspose.pdf.MemoryCleaner.clear() issue, You mean once you call this method after TIFF to PDF conversion it does not release the memory of Aspose.Pdf specific instances? If you are using some old version of Aspose.Pdf for Java, then please try latest version of Aspose.Pdf for Java and share the results as well.

Best Regards,

Hi,

Sample file attached. <Test 100009387.tif>
Please check the memory consumption before and after the attached file processing in the application.

How to verify whether memory has been released or not post method call? I can see from Task Manager Memory consumed by the application remains high post Tiff processing and method call.

Aspose PDF version is aspose.pdf-11.0.0.jar.

Thanks,
Wasim

Hi Wasim,


Thanks for sharing the source TIFF document, but I am afraid it is not uploaded properly as I am getting an image with 0 KB size. Please share it again, so we will look into it and will guide you accordingly.

Furthermore, please note com.aspose.pdf.MemoryCleaner.clear() clears the Aspose.Pdf instances occupied memory after completion of the processing. It does noting during processing.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Sharing again,

Regarding ‘after completion of the processing’ and not completion of the application, right?
As I stated earlier, eventually the process gets stuck not immediately after processing. So yes, I am talking about the times well after the processing is complete.
Thanks
Wasim

Hi Wasim,

Itsak26:


Sharing again,



Thanks for sharing again the source TIFF. I have tested TIFF to PDF conversion scenario using following code snippet and unable to notice high memory consumption.

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

doc.getPages().add();

com.aspose.pdf.Image image = new com.aspose.pdf.Image();

image.setFile("C:\\Users\\Home\\Downloads\\Test+100009387.tif");

image.setBlackWhite(true);

doc.getPages().get_Item(1).getParagraphs().add(image);

doc.save(myDir+"100009387_converted_bw.pdf");

Itsak26:

Regarding 'after completion of the processing' and not completion of the application, right?
As I stated earlier, eventually the process gets stuck not immediately after processing. So yes, I am talking about the times well after the processing is complete.

As stated above, you can call MemoryCleaner.clear() method to clear memory when there is shortage of memory, either at the end of a conversion method or end of the application.

Best Regards,

Hi Waseem,


Thanks for sharing the details. I am looking into it and will update you soon.

Best Regards,

Hi Waseem,


I am sorry for the delayed response. We have logged an investigation ticket PDFNEWJAVA-35793 in our issue tracking system to analyze the scenario. We will keep you updated about the issue resolution progress within this forum thread.

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Whats the status of the ticket #35793? Is there a tracking tool where I can see the update?

Thanks,
Wasim

Hi Wasim,


We are sorry for the inconvenience. Our product team has investigated the issue and unable to replicate the reported issue. Please note your used memory testing method is not correct. JVM occupy almost all the available memory for java heap and does not return it back after the memory for java objects is released. Java Garbage Collector(GB) cannot be handled. But GB cleans the memory when a new object is trying to create. Also Java caches some objects, text strings, static fields in classes. These objects occupy the minimum of memory, just a few megabytes.

We have test the scenario in another way. After setting the limit for java virtual machine: -Xmx1024m -Xms1024m. Firstly We have created the maximum object that does not prevent to OutOfMemoryException ().

byte[] array = new byte[1024 * 1024 * 680];<o:p></o:p>


then clean the object by assigning it null and running your sample code 20 times. Finally We created the same big object in the memory again. Taking into account JVM caching we have reduced the array size in 30 mb. And we were able to create the object. Which means that the memory is free and available for use.


The full code snippet is as following:


//Enabled Java options: -Xmx1024m
-Xms1024m
<o:p></o:p>

byte[] array = new byte[1024 * 1024 * 680];<o:p></o:p>

printMemoryStatus(“init”);<o:p></o:p>

array = null;<o:p></o:p>

for (int i = 0; i < 20;
i++)<o:p></o:p>

{<o:p></o:p>


//
license initialization
<o:p></o:p>

init();<o:p></o:p>


// logger.info(“Process Tiff
attachment with latest lib fix 19/04/2016.”);
<o:p></o:p>


com.aspose.pdf.Document doc = new com.aspose.pdf.Document();<o:p></o:p>


doc.getPages().add();<o:p></o:p>


com.aspose.pdf.Image image = new com.aspose.pdf.Image();<o:p></o:p>


image.setFile(myDir + “Test+100009387.tif”);<o:p></o:p>


// logger.info("TIFF file name:
" + fileName);
<o:p></o:p>


image.setBlackWhite(true);<o:p></o:p>


doc.getPages().get_Item(1).getParagraphs().add(image);<o:p></o:p>


doc.save(myDir + “Test+100009387.pdf”);<o:p></o:p>


// At the end of method, I am calling
these,
<o:p></o:p>


doc.close();<o:p></o:p>


com.aspose.pdf.MemoryCleaner.clear();<o:p></o:p>


com.aspose.pdf.MemoryCleaner.clearAllTempFiles();<o:p></o:p>


com.aspose.pdf.MemoryCleaner.clearFontRegistry();<o:p></o:p>


com.aspose.pdf.MemoryCleaner.clearLicense();<o:p></o:p>


doc = null;<o:p></o:p>


image = null;<o:p></o:p>

}<o:p></o:p>

printMemoryStatus(“after
Aspose.Pdf”
);<o:p></o:p>

array = new byte[1024 * 1024 * 650];<o:p></o:p>

printMemoryStatus(“after
creating new array”
);<o:p></o:p>

array = null;<o:p></o:p>

<o:p> </o:p>

----

<o:p> </o:p>

static void
printMemoryStatus(String position)<o:p></o:p>


{<o:p></o:p>


Runtime rt = Runtime.getRuntime();<o:p></o:p>


long max = rt.maxMemory()
/ 1048576;<o:p></o:p>


long total =
rt.totalMemory() / 1048576;<o:p></o:p>


long free =
rt.freeMemory() / 1048576;<o:p></o:p>


long used = total - free;<o:p></o:p>


System.out.println(“Memory status for “+position+”:
\n\tenabled\t used\t free\n\t”
+ max + "\t " + used + " \t
"
+ free);<o:p></o:p>

}


Best Regards,