Sparx Systems Forum

Enterprise Architect => Bugs and Issues => Topic started by: Thomas Arnbjerg on December 09, 2022, 12:21:52 am

Title: MDA transformation explodes in memory usage
Post by: Thomas Arnbjerg on December 09, 2022, 12:21:52 am
Hi all,
We have an MDA transformation, which has suddenly caused EA to use extreme amounts of memory (>30 GB) and the transformation never completes. I have narrowed the problem down to 1 custom template (Class__xx). I've removed all calls to other templates (e.g. Connector__xx) with the list macro, but the problem persists.

Any suggestions?

The template is shown below:

%if elemType != "Component"%
%endTemplate%

%if classLanguage == "Java"%
Package
{
   %TRANSFORM_REFERENCE("MessagingClassesPackage","IMPLEMENTATION", "ONLY_ONE")%
   name = "datastructureclasses"

   Class
   {
      %TRANSFORM_REFERENCE("ComponentEventbusFacade",className,classGUID)%
      name=%qt%%className%Implementation%qt%
      notes=%qt%*** AUTOGENERATED - Do not modify by hand. ***
   This class implements the interface against the system for component '%className%'.%qt%
      Language="Java"
      stereotype="system_interface_implementation"
      Tag
      {
         name="application"
         value=%qt%%className%%qt%
      }
      
      Attribute
      {
         name="PROPERTYBAGNAME"
         default=%qt%%sl%%qt%propertyBagName%sl%%qt%%qt%
         type="String"
         Constant="true"
         
         
      }
      
      Attribute
      {
         name="COMMANDID"
         default=%qt%%sl%%qt%commandId%sl%%qt%%qt%
         type="String"
         Constant="true"
         
         
      }
            
      Attribute
      {
         Name = "communicationMap"
         Type="Map<String, ISocketChannel>"
      }
      
      Attribute
      {
         Name = "logger"
         Type="Logger"
      }
      Operation
      {
         Name = "handleMessage"
         Type="void"
         Scope="public"
         Parameter
         {
            Name="_message"
            Type="IMessage"
         }   

         Code=%qt%
try
{
   PropertyBagMessage pbMessage = (PropertyBagMessage)_message;
   Map<String, Object> propertyBag = pbMessage.getPropertyMap();   
      
   return;
}
catch(Exception e)
{
   logger.error(String.format(%sl%%qt%Exception caught: %s  Stack trace:%s%sl%%qt%, e.getMessage(), e.getStackTrace()));
   throw e;
}

      
               %qt%
      }
      
      Header=%qt%
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dk.medtrace.util.socket.data.PropertyBagMessage;
import dk.medtrace.util.socket.interfaces.ISocketChannel;
import dk.medtrace.util.socket.impl.SocketFactoryImpl;
import dk.medtrace.util.socket.interfaces.IMessage;
import dk.medtrace.util.autogenerated.framework.ESocketChannel;
import dk.medtrace.util.autogenerated.framework.ComponentSocketChannels;
import java.util.*;

%qt%      
   }

   Realisation
   {
      %TRANSFORM_REFERENCE("FacadeRealizesInterface",className,classGUID)%
      direction="Source->Destination"
         
      Source
      {
         %TRANSFORM_REFERENCE("ComponentEventbusFacade",className,classGUID)%
      }
      
      Target
      {
         %TRANSFORM_REFERENCE("ComponentInterfaceClass",className,classGUID)%
      }
   }
   
   Realisation
   {
      %TRANSFORM_REFERENCE("FacadeRealizesIMessageHandler",className,classGUID)%
      direction="Source->Destination"
         
      Source
      {
         %TRANSFORM_REFERENCE("ComponentEventbusFacade",className,classGUID)%
      }
      
      Target
      {
         GUID="{115E54AE-749C-4552-92D2-C8BDF85BD460}"
      }
   }   
}
%endIf%
Title: Re: MDA transformation explodes in memory usage
Post by: Geert Bellekens on December 09, 2022, 12:36:06 am
Thomas,

Are you sure you didn't create an endless loop somewhere?

e.g.
- templateA calls template B
- templateB calls templateC
- templateC calls templateA

That seems like a (the only?) logical explanation for that behavior.
I'm not very familiar with the template language (and I try to stay as far away from it as possible), so I can't quickly identify if that is the case here.

Geert
Title: Re: MDA transformation explodes in memory usage
Post by: Thomas Arnbjerg on December 09, 2022, 12:39:55 am
Thanks for the response.

I found the reason

'%' needs to be escaped with '%pc%' in 'logger.error(String.format(%sl%%qt%Exception caught: %s  Stack trace:%s%sl%%qt%, e.getMessage(), e.getStackTrace()));'
Title: Re: MDA transformation explodes in memory usage
Post by: Geert Bellekens on December 09, 2022, 01:03:17 am
'%' needs to be escaped with '%pc%' in 'logger.error(String.format(%sl%%qt%Exception caught: %s  Stack trace:%s%sl%%qt%, e.getMessage(), e.getStackTrace()));'

You see why I try to stay away from it  ;D

Geert
Title: Re: MDA transformation explodes in memory usage
Post by: Thomas Arnbjerg on December 09, 2022, 01:06:10 am
Yeah - it's one of those situations where the entry barrier is quite high - but so are the gains.

This is one of the most powerful features with model driven development. Hope Sparx will improve ease-of-use - lot's of low hanging fruits.
Title: Re: MDA transformation explodes in memory usage
Post by: Geert Bellekens on December 09, 2022, 02:11:54 am
Yeah - it's one of those situations where the entry barrier is quite high - but so are the gains.

This is one of the most powerful features with model driven development. Hope Sparx will improve ease-of-use - lot's of low hanging fruits.
I'm not convinced.
If you are familiar with scripting and EA's API, it's usually faster, and definitely more flexible to create your own transformation script.

With the added bonus that you can actually debug when things don't work as planned.

Geert
Title: Re: MDA transformation explodes in memory usage
Post by: qwerty on December 09, 2022, 02:14:38 am
They may hang low, those fruits. But they are not tasty. I'd wish they would not waste time here but improve the API.

q.
Title: Re: MDA transformation explodes in memory usage
Post by: Paolo F Cantoni on December 09, 2022, 09:20:11 am
They may hang low, those fruits. But they are not tasty. I'd wish they would not waste time here but improve the API.

q.
"you might well think that; I couldn't possibly say that!"

Paolo