LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: CPU load and FPS decrease spikes after Java garbage collection  (Read 297 times)

Fataho

  • Newbie
  • *
  • Offline Offline
  • Posts: 9

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

Logged

Cornix

  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 470
Re: CPU load and FPS decrease spikes after Java garbage collection
« Reply #1 on: July 20, 2017, 20:17:15 »

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

Fataho

  • Newbie
  • *
  • Offline Offline
  • Posts: 9
Re: CPU load and FPS decrease spikes after Java garbage collection
« Reply #2 on: July 20, 2017, 21:04:34 »

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.
Logged

bobjob

  • Prolific Timewaster
  • ****
  • Offline Offline
  • Posts: 394
  • LWJGL: WOW SO GOOD
Re: CPU load and FPS decrease spikes after Java garbage collection
« Reply #3 on: July 21, 2017, 10:20:39 »

are you manually calling System.gc() in your code?
Logged

Fataho

  • Newbie
  • *
  • Offline Offline
  • Posts: 9
Re: CPU load and FPS decrease spikes after Java garbage collection
« Reply #4 on: July 21, 2017, 10:37:03 »

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.
Logged

Fataho

  • Newbie
  • *
  • Offline Offline
  • Posts: 9
Re: CPU load and FPS decrease spikes after Java garbage collection
« Reply #5 on: July 23, 2017, 03:22:56 »

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.
Logged