5 Replies Latest reply on Nov 30, 2004 10:41 AM by smileyq

    Better performance?

    smileyq

      I am wondering if there are any perfomance differences between calling the the CMR (Many) method of the entity bean or using a finder on the other bean for getting data. For example lets say we have a Client entity bean that has many Contact entity beans with a 1:M reltionship. Would it be better performance to call the ClientEJB.getContacts() method which is the CMR method or call a finder method on the contacts entity bean like ContactHome.findContactsByClient(client). It seems that the finder might be faster because I can optimize the finder method with read-ahead etc.. I am currious because I haven't some major performance issues with calling several sets of data within page on a web application. I appreciate any input you may have.

        • 1. Re: Better performance?
          schmidts

          I really appreciate all of the responses I have received so far. I am still working on fine tuning perfomance of this application using the jboss loading methods. One problem that I see if that my tables are way too normalized and this cases performance problems while using entity beans. I am still trying to grasp jboss optimization of entity beans using the on-find and on-load features. Agan I appreciate the great responses I have recieved so far.

          Thanks.

          • 2. Re: Better performance?
            jobor

            I have thought about the same thing. Why should I not use a normal finder for getting the childs. But most likely your FK field is not available as a CMP field which can be used in EJB-QL.
            If you need the bean and the childs in 1 transaction you can consider the use of left-join read-ahead. This will read in the SQL resultset (2 joined tables) in the read-ahead cache and wnen you call a method on the child bean the data is loaded from the read-ahead cache.
            If you need the childs at a later time you can call the normal CMR field. But you can optimize also that one with a read-ahead element in the ejb-relation element. This wil select the fields of the eager load group in SQL statement. The page size is used for finding fields that are not loaded in the first SQL statement. But if all your fields are in the eager load group than just 1 SQL statement is executed to populate your child collection.

            <ejb-relation>
             <ejb-relation-name>T1-Tm</ejb-relation-name>
             <foreign-key-mapping/>
             <ejb-relationship-role>
             <ejb-relationship-role-name>t1-has-tm</ejb-relationship-role-name>
             <key-fields>
             <key-field>
             <field-name>key</field-name>
             <column-name>tm_fk</column-name>
             </key-field>
             </key-fields>
             <read-ahead>
             <strategy>on-find</strategy>
             <page-size>8</page-size>
             <eager-load-group>all</eager-load-group>
             </read-ahead>
             </ejb-relationship-role>
             <ejb-relationship-role>
             <ejb-relationship-role-name>tm-belongs-to-t1</ejb-relationship-role-name>
             <key-fields/>
             </ejb-relationship-role>
            </ejb-relation>
            


            Johan

            • 3. Re: Better performance?
              aloubyansky

              You can also map foreign key fields to the columns CMP fields are mapped to. So you could add a CMP column that represents a foreign key and use it in queries.

              • 4. Re: Better performance?
                smileyq

                I really appreciate all of the responses I have received so far. I am still working on fine tuning perfomance of this application using the jboss loading methods. One problem that I see if that my tables are way too normalized and this cases performance problems while using entity beans. I am still trying to grasp jboss optimization of entity beans using the on-find and on-load features. Agan I appreciate the great responses I have recieved so far.

                Thanks.

                • 5. Re: Better performance?
                  smileyq

                  After working with the optimization of my entity beans I have taken the page load down from 5 seconds to 1 or less by switching to using CMR methods of my entity beans instead of using the finder methods of the target side of the relationship. I setup read ahead with on-find and noticed a huge difference in performance. Another thing I made sure of was that my methods were wrapped within transactions to call fewer SQL statements. This just proves that you must plan out your entity beans and implement them properly or you will suffer from some severe performance problems which I'm sure have turned many people away. Best of luck to you all.