-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to optimize performance on big inserts
PostPosted: Mon Apr 26, 2010 9:46 am 
Newbie

Joined: Mon May 11, 2009 11:16 am
Posts: 13
Hi to all,

i've a question regarding performance optimizations on big objects.

We've a model where a person can have a list of AttributeValues (both are entities, clearly). Furthermore we save a ActionItem object to be able to trace changes.

This means in summary that when i want to persist one single person there will be around 133 lines in different tables for that.

1 line for the person itself
65 AttributeValues for the person
1 ActionItem for tracing
65 AttributeValues for the ActionItem
1 PersonStructureAssociation (which is an association beetween the person and lets say the place this person works at)

Here the java code for the problem above

Code:
/**
     * This method will create and persist a new person with the provided gid
     * and attribute values and will also try to associate the person with the
     * provided structure node if it is not null
     * @param gid the gid for the person
     * @param attributeValues the attribute values for the person
     * @param actualAssociatedNode the node to associate the person to
     * @return the person itself
     */
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public Person createAndPersistNewPerson(String gid, List<PersonAttributeValue> attributeValues, StructureNode actualAssociatedNode) {
        Person person = new Person();       
        person.setGid(gid);
        /* Attribute values is a list of nearly 65 Objects.
         In person class this list has a persist cascade  */
        person.setAttributeValues(attributeValues);
        person.prePersistOrUpdate();
        em.persist(person);
        /* Here we persist an ActionItem with a list of also 65 attributes */
        ActionItem item = actionItemCreatorBean.createActionItem(ActionType.PERSON_ADD, String.format(PersonImporterLocal.PERSON_ADD_REMARK, gid, new Date()), new ArrayList<AttributeValue>(attributeValues), person.getGid(), null);
        em.persist(item);
        /*Check if new person is associated to a structure*/
        if (actualAssociatedNode != null) {
            PersonStructureAssociation association = new PersonStructureAssociation();
            association.setPerson(person);
            association.setStructureNode(actualAssociatedNode);
            em.persist(association);
            ActionItem anotherItem = actionItemCreatorBean.createActionItem(ActionType.PERSON_ADD_TO_STRUCTURE, String.format(PersonImporterLocal.PERSON_ADD_TO_STRUCTURE_REMARK, gid, actualAssociatedNode.getType().getName(), actualAssociatedNode.getInternalSearchKey(), new Date()), null, person.getGid(), actualAssociatedNode.getInternalSearchKey());
            em.persist(anotherItem);
            actualAssociatedNode.addPersonAssociation(association);
            em.merge(actualAssociatedNode);
        }
        return person;
    }


The attentive reader will notice that the AttributeValues will be persisted twice (in two different tables). This is needed. I quess it would be the most benefiting performance optimization to remove the "redundant" saving of the attributeValues but unfortunally this is not possible.

Does someone know how to increase performance for this problem? Actually a persist operation for one person will last around 75 ms.

Thx for suggestions


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.