Uploaded image for project: 'Configuration Persistence Service'
  1. Configuration Persistence Service
  2. CPS-886

Fragment handling decreasing performance for large number of cmHandles





      While sending DMI registration requests, I observed that the response is getting slower and slower with increasing number of cm handles and fragments in the database.
      After about few thousand entries in the `fragment` table, the performance degradation gets noticeable.

      The time consumed to insert a new fragment can take up to 20-30+ seconds and will increase.


      Steps to reproduce

      Create thousands of entries in the fragment table and execute a single DMI registration request for a new cmHandle.


      RCA (Root Cause Analysis)

      The problem is in the CpsDataPersistenceServiceImp class.

      The implementation of adding new fragment entities is implemented in a way, that the parent fragment is populated with all it's child elements into a set of fragment entities. The new fragment is then added to this set using the `addAll` method of the Set interface. This can be observed at:



      The problem with this solution is that it will issue thousand and thousand of requests to get all child fragments of the main parent fragment (xpath: "/dmi-registry", attributes: "{}" ). With increasing child fragments after his main parent fragment, the query to the database will be slower and slower.


      Possible solution

      Decompose to two steps:

      • Save fragment
      • Update parent for the saved fragment

       It will result in just 3 database operations (determine parent id, save new fragment, update parent) instead of thousands / new fragment.

      For updating the parent id, a new native query can  be added to the FragmentRepository.


      save new fragment fragmentRepository individually first

      add method in fragmentRepository to update new fragment parent id (from parent fragment) (using native query to execute Update) ensure steps 1 and 2 are part of a transaction (use transaction on new method in repository too) Also consider update of fragmentEntity itself using the parent id.

      Testing Locally 

      Modify fragment entity to set parent id, then write unit test around setting and saving parent id to a pre-existing dmi registry parent, with children.


        # Subject Branch Project Status CR V



            DylanB95EST Dylan Byrne
            emolger Gergely Molnar
            0 Vote for this issue
            1 Start watching this issue