Reputation: 500
I have a microservice that generates multiple PDF Documents and saves to database. For generating each document, from the main service class, I call multiple document specific service class methods by passing an arraylist of Documents as argument. Each service class may or may not generate a pdf depending on the conditions and add it to the arraylist. Finally I save the list of documents to the database.
Can I reduce the heap space utilization by having each of the document service classes return a new document list and add them to a main list in main service class instead of passing the main list to each service class?
Upvotes: -1
Views: 43
Reputation: 13556
Have you measured what consumes most heap during your operation? I would guess it's the number of pdf documents in memory at the same time and not how large any given list is. I don't see how you would reduce the number of pdf documents in memory with your approach.
I would either suggest applying "Tell, don't ask" and tell your document specific services where to save a document in the database. Then you would have at most 1 document in memory at the same time. However this may extend the duration of a transaction because it would also span pdf generation and therefore consume other resources crucial to the overall throughput of your application.
Another suggestion is to tell your document specific services where to write the pdf documents to and use temp folders/files to keep them during the operation therefore trading heap utilization for disk IO.
Upvotes: 0