World.update gets stuck

Posts regarding potential bugs, enhancement requests, and general feedback on use of dyn4j
zoom
Posts: 141
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: World.update gets stuck

Postby zoom » Sat Nov 19, 2016 4:19 pm

It's a bit tricky but you can set up remote JMX connections so you run JVisualVM or JConsole on your dev-computer and connect to the headless-server.

soylomass
Posts: 10
Joined: Fri Nov 18, 2016 3:40 pm

Re: World.update gets stuck

Postby soylomass » Sat Nov 19, 2016 4:34 pm

zoom wrote:It's a bit tricky but you can set up remote JMX connections so you run JVisualVM or JConsole on your dev-computer and connect to the headless-server.


So now that I've (correctly) set the limit to 4gb, the physics did halt again. I wasn't monitoring the stats the exact moment it fell, but a minutes later.
The HEAP currently in use jumps a lot, some times to 1300MB, which is a lot, but isn't close to the limits.
Maybe it did reach the limits when the physics halted, I'm not sure.

Is 1300MB a lot for that amount of bodies? (1800) The server also has a websocketserver.

If you think it is a lot, I'll try to reduce it.

soylomass
Posts: 10
Joined: Fri Nov 18, 2016 3:40 pm

Re: World.update gets stuck

Postby soylomass » Sat Nov 19, 2016 7:44 pm

I hooked JVisualVM from start until in halted (and some minutes more):

LINK HERE

You can load it with JVisualVM. It has 4 memory samples, which show the Body count grows from 2000 to 75000 in the last one, what makes me think that possibly bodies aren't being removed? (I only create bodies once when I instantiate Fish, Body, Terrain and HideSpace clases, and then remove them with world.removeBody(fody); and set the reference to null)
Also, Vector2 instances grow to 6 million (before GC)

In the snapshot you can also see how the memory grows until it suddendly falls (at the same moment that I pressed the "Heap Dump" button and the world halted).

Sadly, when I decided to make a Heap Dump (after the last snapshot), I pressed the button and it seems that the extra CPU(?) usage accelerated the world's update freezing, so the heap dump was realized with the data posterior to the halt, therefore it's not useful.

--

What's strange is that even if the memory usage grows, it's still far from the limit. Maybe the bodies amount could be a problem, but it doesn't seem that the world is looping over 75k bodies every step either, because the process doesn't become much slower than at the begining.

---

Actually, I think that the sampler data isn't right... Running it locally, the sampler does some times show high Body, Fish, etc. instances, but when i take a Heap Dump, I see the expected numbers. So I don't know what to believe...

William
Site Admin
Posts: 345
Joined: Sat Feb 06, 2010 10:23 pm

Re: World.update gets stuck

Postby William » Sat Nov 19, 2016 8:34 pm

So does it ever resume after it hangs or is it stuck forever? Just want to confirm. It's common to see a memory profile like that. I think the default collector tries to do small collections frequently and then large ones every so often. Could be wrong though.

Is there anyway you can log certain key stats (on an interval like every 10 mins) as the simulation progresses. For example, the number of bodies in the world, the number of bodies in the broadphase, or any other health check type information?

Can you post some code that we might be able to look at?

William

soylomass
Posts: 10
Joined: Fri Nov 18, 2016 3:40 pm

Re: World.update gets stuck

Postby soylomass » Sat Nov 19, 2016 8:46 pm

William wrote:So does it ever resume after it hangs or is it stuck forever? Just want to confirm. It's common to see a memory profile like that. I think the default collector tries to do small collections frequently and then large ones every so often. Could be wrong though.

Is there anyway you can log certain key stats (on an interval like every 10 mins) as the simulation progresses. For example, the number of bodies in the world, the number of bodies in the broadphase, or any other health check type information?

Can you post some code that we might be able to look at?

William


Now I only check the number of "Fish" object, which is normal, and the time it takes to to some of the processes (like world.update, playerhandler.update, foodhandler.update).
The world.update time doesn't grow too much, the max average is 15ms (with some spikes sometimes).

I can check other data. What would be useful? World.bodies and Sap.tree/Sap.map sizes?, what other?

About the code, I'll try to upload the important parts. I noticed that there is only one time in the ContactHandler where I interact with the bodies, it's in the Begin method, given the cirscumstances, sometimes I change the filter of the body, like this:

body.getFixture(0).setFilter(Filters.hiddenFishFilter);
body.getFixture(1).setFilter(Filters.hiddenFishMouthFilter);


I shouldn't do that there, right? Anyway, I don't think the halt is because of this.

And yes, it get's stuck forever.

zoom
Posts: 141
Joined: Sun Mar 17, 2013 3:57 pm
Location: Stockholm, Sweden
Contact:

Re: World.update gets stuck

Postby zoom » Sun Nov 20, 2016 2:30 am

soylomass wrote:I hooked JVisualVM from start until in halted (and some minutes more):
...
What's strange is that even if the memory usage grows, it's still far from the limit. Maybe the bodies amount could be a problem, but it doesn't seem that the world is looping over 75k bodies every step either, because the process doesn't become much slower than at the begining.


I agree, the memory profile shows you are very far from the limits. I think you can rule out memory usage/GC-pauses. More probable that there is some other code causing the slowdowns.

I see that you are using vert.x, have you looked for "Thread stuck"-messages in the log? they might help you track down the problem.


Return to “Bugs, Enhancements, Feedback”

Who is online

Users browsing this forum: No registered users and 2 guests