paulszefer / Ecosystem-Simulation

MIT License
0 stars 0 forks source link

Application hang-time due to adjustForCrowding method #7

Closed paulszefer closed 7 years ago

paulszefer commented 7 years ago

The adjustForCrowding method in Pool is responsible for about 90% of the application's processing time. This leads to the application hanging as it waits for this method to finish. Surprisingly, the issue is not to do with sorting the guppies according to their health coefficient. Instead, it is to do with the following block of code:

while (volumeLitres < getCreatureVolumeRequirementInLitres()) { weakestCreatures.add(creatures.remove(index)); }

I am not sure whether the problem is getCreatureVolumeRequirementInLitres or the adding and removing of guppies to the lists; I suspect the latter; however, VisualVM is not giving me any hints. The problem spawns (pun-intended) from the frequent Guppy spawning. Given that, I thought of the following solutions:

a. Guppies spawn less frequently (once every 4 weeks perhaps) b. Guppy spawning is hindered by the amount of water available c. Figure out which of the methods mentioned above is the problem and explore possible solutions

paulszefer commented 7 years ago

The hang time from this method was indeed due to the removing and adding from the lists. This method has been modified to remove guppies in bulk to minimize the number of calls to remove a single element from the list. The guppies are also added to the second list in bulk.

Fixed by aa36ea28ab8729c42712ad6d0f81ab65e45a921e

chris-thompson commented 7 years ago

I think it would be helpful for Griffin (and very interesting for me!) if you showed us how you used VisualVM to help you diagnose the problem. We could take a peek (git makes this so easy!) at your code before the fix, monitor it, see the issue, and then see the fix.