Search code examples
anylogic

Frame collector & Out of memory errors (large memory allocations)


Task: Tasks spawn with fixed time intervals (source), each has remaining processing time which is given by uniform random [0 .. x]. Each task is processed by the module (delay). Each module has a fixed processing time. Module substracts it's processing time from the task's remaining processing time. If a task's remaining processing time depleted (less than 0), that task becomes completed reaches (sink). Otherwise it goes to the next module, and the same process repeats. There are N modules, that are linked one after eachother. If the task's remaining processing time has not depleted after processing at the N'th module, it goes to the 1st module with the highest priority and is being processed there until remaining processing time depletes.

Model Image

The issue: I've created the model, the max amount of spawned/sinked agents i could get is 17 for -Xmx8G and 15 for -Xmx4G. Then CPU/RAM usage rises to max and nothing happens.

Task Manager + Simulation Image

Task Manager Image

I've also checked troubleshooting "I got “Out Of Memory” error message. How can I fix it?" page.

Case Result
Large number of agents, or agents with considerable memory footprints My agents have 2 parameters that are unique to each agent. One is double (remaining_processing_time), another one is integer (queue_priority). Also all 17 spawned agents reached sink.
System Dynamics delay structures under small numeric time step settings Not using that function anywhere, besides delay block.
Datasets auto-created for dynamic variables This option is turned off

Maybe i missing something, but i can't really analyze with such small amount of agents. I'll leave a model here.


Solution

  • This model really had me stumped. Could not figure out where the memory was going and why as you run the model visually it stops yet the memory keeps on increasing exponentially... Until I did a Java profiling and found that you have 100s of Main in the memory...

    enter image description here]

    You create a new Main() for every agent that comes from the source - so every agent is a new Main and every Main is a completely new "simulation" if you will..

    Simply change it back to the default or in your case create your own agent type, since you want to save the remaining time and queue priority

    enter image description here

    enter image description here

    You will also need to change the agent type in all your other blocks

    Now if you run. your app it uses a fraction of memory

    enter image description here