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.
Current Situation
The size of the
List<Message<? extends T>> observationsof thePortObserveris not limited. When running MontiArc models for a long time or with a low millisecond per tick rate and observing all the output ports withPortObservers, the listobservationscan overflow. The result is anOutOfMemoryErrorat some point, and very laggy behaviour in the meantime.montiarc/libraries/simulator-rte/main/java/montiarc/rte/port/PortObserver.java
Lines 18 to 20 in 6b0005c
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 thePortObservers.Proposed Change
A method to clear the
observationslist when a certain number of messages have been received should be added. In my project, I added aPortObserverSpy: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
observationslist 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
PortObservershould even be added as an additional feature.