Work with many large objects acceptable to the GC in space with a lot of memory

I have an application that creates large result objects and queues them. Several workflows create result objects and queue them, and one thread of threads writes the queues to objects, converts them to CSV, and writes them to disk. Because of both the I / O operations and the size of the result objects, writing the results takes much longer than generating them. This application is not for the server, it is just a command-line application that goes through a large batch of requests and ends.

I would like to reduce the total memory of the application. Using the heap analysis tool ( IBM HeapAnalyzer ), I find that just before the program terminates, most objects with great results are still in the heap, although they were in the queue and had no other references to them. That is, they are all root objects. They occupy most of the heap.

For me, this means that they turned it into a bunch of space while they are still in line. Since the full GC does not start during the run, they remain. I understand that they need to be hired, otherwise I will copy them back and forth in the spaces of Eden while they are still in the queue, but at the same time I want to be able to do something to facilitate their deliverance after de-queueing without dialing System.gc().

I understand that one way to get rid of them would be to simply reduce the maximum heap size and run a full GC. However, the inputs to this program vary greatly in size, and I would prefer to have one setting -Xmxfor all runs.

Added for clarification : all this is a problem because Eden also has a large amount of memory for actually writing the object (mostly Stringinstances that also appear as roots in the heap analysis). As a result, a minor GC is often found in Eden. They would be less frequent if the result objects did not hang around in the space on which it was occupied. It could be argued that my real problem is the overhead of the release at Eden, and I am working on it, but I would like to continue this problem.

, - , ? . JDK 1.8.

: @maaartinus , (, , ) . , , , , (CSV byte[] ). , , , .

+4
1

, GC, , , :

, ...

... , ...

, , : , .

, , . , ( , , ). , .

CSV, String byte[] ByteBuffer ( , ), , ( , , ).

, . , -.

, , - . , .

Update

, Writer?

:

  • . , , , . , CSV, CSV ( ). PrintWriter , .

  • Concurrency: , FileWriter char byte s, . parallelism, IO, , , , .

+2

Source: https://habr.com/ru/post/1548647/


All Articles