Book a Demo

Author Topic: Updates to an Element are SLOW using API  (Read 5544 times)

Gordon Muscroft

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Updates to an Element are SLOW using API
« on: September 13, 2012, 03:27:14 am »
Description of issue:
Update to the Element package is taking a long time when adding a new element.
Notes: We have about 20,000 elements in the package, and I am adding one new it takes from 40 to 60 seconds....

Code Sample:

Dim eaElementPackage As ea.Package
'Snip/Bunch of code....
Set eaElement = eaElementPackage.Elements.AddNew (sNextTageNum, oRQReqType.RQReqType)

eaElementPackage.Update     '--(This is about 40 to 50 seconds.....)

'End code sample

Is there any indexes I can add to the database to speed this up? (Database: SQL Server 2008) Any alternatives?





Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updates to an Element are SLOW using API
« Reply #1 on: September 13, 2012, 04:09:14 pm »
Gordon,

Some tips:

1. I don't think you need to call eaElementPackage.Update() just to add an element in the .Elements connection.

2. 20.000 elements in a single package?!?  :o No wonder it gets slow. Lets put it this way, if you create 20.000 classes in a single namespace/package in code (say Visual Studio) and VS is starting to get slow because of it, are you going to send a bug report to Microsoft? Or are you going to refactor things to reach a bit more sensible numbers.

3. if all else fails, create the element on a different (empty) package,  and then change it's packageID (via an sql query if you have to). That might be a lot faster then adding it to the gigantic package.

4. There's a "new" schema for SQL Server available on the website of Sparx. If you are running EA for years, and you haven't updated the database schema since, it might be worth it.

Geert

Gordon Muscroft

  • EA Novice
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: Updates to an Element are SLOW using API
« Reply #2 on: September 14, 2012, 03:37:32 am »
Geert;

Thanks for the tips. I did need the update statement, but I changed the location to .Update after doing several .AddNew statements.....
IE: Add 20 new elements, and then do the update....

(As a note, I am using a new SQL schema....)

Thanks again
Gord


Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Updates to an Element are SLOW using API
« Reply #3 on: September 14, 2012, 03:43:33 am »
Gordon,

There's three more settings you can use that are supposed to help with performance, but I don't have any proof they actually help:
- Repository.BatchAppend
- Repository.EnableCache
- Repository.EnableUIUpdates

You could give those a try...

Geert

Luis J. Lobo

  • EA User
  • **
  • Posts: 252
  • Karma: +0/-0
  • IT Consultant
    • View Profile
Re: Updates to an Element are SLOW using API
« Reply #4 on: September 14, 2012, 05:43:08 pm »
Gordon, if you are doing an .Update() each 20 elements you're only updating 1 of each 20 elements.

The MyElement.Update() method updates only "MyElement", not all the elements. What you say is a "MyPackage.Elements.Refresh()" that refresh the elements collection of the package where you're adding, and should be called after the entire process (at the end of the elements addition loop).

As Geert says, the .Update() method only should be invoked when you change any attribute. For example:

Code: [Select]
set MyElement = MyPackage.Elements.AddNew("aaa", "aaa")
MyElement.Stereotype = "xxx"
MyElement.Alias = "zzz"
MyElement.Update()

...but if you only are using the .AddNew method, the .update() is unneccesary.

Best regards,

Luis.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Updates to an Element are SLOW using API
« Reply #5 on: September 26, 2012, 02:49:50 pm »
In my view (and I reported it over a year ago - see: Package.Update loops through Element Collection!  Report Ref #: 11048893) its a bug!

Further conversation with Sparx revealed, as in your case - see Luis' post, the package.Update wasn't necessary.  But, from memory, that didn't solve the problem.  The addition of the element still triggered the cycle through the list of elements.

Admittedly, I was only complaining when I have over 1000 elements (legitimately) in the package.  As Geert suggests, 20K may be a bit excessive...  ;D

HTH,
Paolo
« Last Edit: September 26, 2012, 02:50:37 pm by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!