Skip to content

libraries/simulator-rte/main/java/montiarc/rte/port/PortObserver: Fix OutOfMemoryError after long execution time of PortObserver #5

Description

@moritzsommer

Current Situation

The size of the List<Message<? extends T>> observations of the PortObserver is not limited. When running MontiArc models for a long time or with a low millisecond per tick rate and observing all the output ports with PortObservers, the list observations can overflow. The result is an OutOfMemoryError at some point, and very laggy behaviour in the meantime.

public class PortObserver<T> implements InPort<T> {
protected List<Message<? extends T>> observations;

In our case, we faced this issue while working on the Model-Based Systems Engineering lecture project. Our goal was to model the top-level behaviour of an aircraft (e.g. landing gear, cockpit and propulsion) and visualise it using a custom GUI. To transfer the behaviour of the model to the GUI, we used mentioned PortObservers, and two out of three groups experienced lagging and crashing simulations because of the PortObservers.

Proposed Change

A method to clear the observations list when a certain number of messages have been received should be added. In my project, I added a PortObserverSpy:

public final class PortObserverSpy<T> extends PortObserver<T> {
  
  public List<Message<? extends T>> snapshot() {
    return List.copyOf(observations);
  }
  
  public void clear() {
    observations.clear();
  }
  
  public T latestValue() { ...

However, this was only a short-term solution to ensure that a working simulation could be presented in the end. I suggest that MontiArc itself implements a method to delete values from the observations list when it grows too big, so that end users don't have to implement a hacky spy pattern themselves.

If you are happy for me to do so, I would like to contribute the code myself. However, before opening a pull request, I would like to hear your opinions on the issue and any potential solutions, as well as whether the deletion of messages in the PortObserver should even be added as an additional feature.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions