CPU load and FPS decrease spikes after Java garbage collection

Started by Fataho, July 20, 2017, 18:20:33

Previous topic - Next topic

Fataho

Hello,
I am using LWJGL 2 and 3 to generate 3D scene and I get CPU load and FPS decrease (from 60 to 10-20) spikes after Java garbage collection. Does any one had a similar problem? What can cause it?  Here is an image:
https://gyazo.com/3747f30bfdc1d9b8546ea06f100578ff
Similar situation with LWJGL 2:
https://gyazo.com/84fab09dd4a8914def25add7e10712d0
These images are from Java VisualVM, where I measure performance.

EDIT:
I managed to remove spikes by adding these VM paramters, (poor hack):
-Xms2048m
-Xmx2048m
-XX:MaxNewSize=3m
1. I made Heap memory static, so it does not change (first two lines).
2. I made young generation memory only 3m (third line), this forces very frequent, but unnoticable GC.
Ne generation memory is cleared rapidly, however Old generation memory increases very slowly, at some point it should reach limit. This would cause a GC with a lag, however it should happen once in few hours.
Here is an images of Visual GC:
https://gyazo.com/056b496b79f7fae98a272396eb2dc7b3
and a CPU and heap usages:
https://gyazo.com/4d13263e87ad47c733cdfd243428a641


Cornix

Perhaps you are generating too much garbage?
Hard to say without knowing what you do.

Fataho

Quote from: Cornix on July 20, 2017, 20:17:15
Perhaps you are generating too much garbage?
Hard to say without knowing what you do.

But spikes appear even heap is practically empty? It does not look like this is the case. Also you can see in plots that heap memory is not that full.

bobjob


Fataho

Quote from: bobjob on July 21, 2017, 10:20:39
are you manually calling System.gc() in your code?

No. I do nothing what is related to GC. The spike frequency increases when I load more models into 3d space, since more frequently GC is called. And it does not matter how much memory GC has to clean, even if it is few megabytes, the FPS decrease spike still happens.

Fataho

I have found the problem. I was creating a FloatBuffer every time I needed a Matrix4f. GC had to remove all created FoatBuffers and that was the reason of spikes.