12 Replies Latest reply on Sep 15, 2002 10:33 PM by richlin

    it is slow to add entity to collection(relationship) in CMR

    richlin Newbie

      Hi,
      I have 1 to n relation in my EntityBean(Company to Persons, JBoss 3.0 use CMR )
      and there will have more than 10000 persons in one Company

      when i create a person i will add to company
      but i find JBoss will call SQL to find all Person when i get Collection
      and it will wast a lot of time(in JDBC i just only set the foreign key, it is very fast)

      code is like:
      Company theCompany=CompanyHome.finByXX(...);
      Person thePerson=PersonHome.create(...);
      Collection thePersons=theCompany.getPersons();
      //there will have a SQL call like-->
      //SELECT primaryId from PERSON
      //where PERSON.company = ?

      thePersons.add(thePerson);


      In JBoss (or EJB)
      Is container always execute SQL when i get Collection??( there may be some setting i dont know)
      or is there any other way can fast build the relationship ??

      Thanks a lot

      arich

        • 1. Re: JBoss vs WebLogic --- findings
          Georg Schmid Newbie

          This more or less mirrors my findings when comparing JBoss to IBM Websphere. JBoss is slow.

          In my case, there was (practically) no database access in the mix, either. Beyond the very first call in 10,000 calls, the data was cached and the actual work in the call ammounted to a simple HashMap lookup. There was no HTTP access involved, either. I was just calling a stateless session bean's method over and over again.

          The computer is a 2260 MHz Pentium 4, IBM JDK 1.3.0 used for both WebSphere and JBoss. JBoss 2.4.4 with Catalina. Testing locally, but from different JVM's:

          - When keeping a reference to the bean (i.e., a single JNDI lookup, then keep calling the methods):

          WebSphere 4.01: 9.313s (~ 1074 calls / sec)
          JBoss: 19.239s (~ 520 / Sec)

          - With a JNDI lookup each time (which is closer to what our clients will do.)

          WebSphere 4.01: 22.766s (~ 439 / Sec)
          JBoss: 70.297s (~ 142 / Sec)

          Just for curiosity sake, I also tested calling the EJB's over the network, on an Ultra 10 machine. (Which is even closer to the experience our clients will have.) Sadly, I don't have a WebSphere installed on that machine at the moment, so this is more to illustrate the effect of having a network in between.

          With only 1 JNDI lookup: 77.641s (~ 131 / Sec)
          With JNDI lookup each time: 298.391s (~ 33.5 / Sec)

          Sorry, IMHO that is a bit too slow for an enterprise environment. Even at the rate of one EJB call per web page view, 33.5 calls per second might just be enough for someone's home page. And even then, only as long as it doesn't get too popular. For something that's supposed to be the core system called by all of a corporation's web services... nope.

          Doubly so when a more realistic scenario involves 3-5 EJB calls per page.

          • 2. Re: it is slow to add entity to collection(relationship) in
            Colin Yates Newbie

            You can still create a Person and then call Person.setCompany with the primary key of the the company.

            See http://jboss.org/forums/thread.jsp?forum=46&thread=20427

            • 3. Re: it is slow to add entity to collection(relationship) in
              richlin Newbie

              cyates, thanks for your reply

              I have try this way before
              but JBoss(3.0.0 & 3.0.2) still call
              "SELECT primaryId FROM PERSON WHERE (company=?)"
              when i use thePerson.setCompany(theCompany);

              And when i remove the Person, JBoss will also call the SQL
              ...
              so...
              if your have more relationship object your performance will more slow(when create and delete)

              maybe i have some wrong setting?

              cyates
              can you tell me how do you solve this problem.. how your SQL log look like??...

              anyway appreciate your help

              arich

              • 4. Re: it is slow to add entity to collection(relationship) in
                richlin Newbie

                cyates, thanks for your reply

                I have try this way before
                but JBoss(3.0.0 & 3.0.2) still call
                "SELECT primaryId FROM PERSON WHERE (company=?)"
                when i use thePerson.setCompany(theCompany);

                And when i remove the Person, JBoss will also call the SQL
                ...
                so...
                if your have more relationship object your performance will more slow(when create and delete)

                maybe i have some wrong setting?

                cyates
                can you tell me how do you solve this problem.. how your SQL log look like??...

                anyway appreciate your help

                arich

                • 5. Re: it is slow to add entity to collection(relationship) in
                  richlin Newbie

                  cyates, thank your reply

                  I have try that before
                  but there are still have a SQL call
                  "SELECT primaryId FROM PERSON WHERE (company=?) "
                  even i rewrite the code to
                  thePseron.setCompany(theCompany);

                  and i also find this SQL will be call when i remove thePerson Bean

                  so when i have more relation entitybeans the System performance will more slow (remove and create)

                  maybe i have some wrong setting

                  how do you solve the problem
                  and what do your SQL look like??

                  very thank for your help


                  arich

                  • 6. Re: it is slow to add entity to collection(relationship) in
                    richlin Newbie

                    thank for your reply

                    i have try this way before
                    but it dont have any change
                    JBoss still call the SQL
                    "SELECT primaryId FROM PERSON WHERE (company=?)"
                    even i use thePerson.setCompany(theCompany);

                    and when i remove the Person theSQL will be call..

                    In My Application, more relation entitybeans will have more slow performance(when create and remove)

                    maybe i have some wrong setting

                    cyates
                    how do you solve this problem?
                    and what is your SQL log look like?

                    or have any one have this problem...

                    Thanks

                    arich

                    • 7. Re: it is slow to add entity to collection(relationship) in
                      richlin Newbie

                      oh my god ...
                      Administrator i am sorry for reply too many message...
                      forgive me


                      arich

                      • 8. Re: it is slow to add entity to collection(relationship) in
                        Fusayuki Minamoto Apprentice

                        > i have try this way before
                        > but it dont have any change
                        > JBoss still call the SQL
                        > "SELECT primaryId FROM PERSON WHERE (company=?)"
                        > even i use thePerson.setCompany(theCompany);

                        Yes.
                        But I believe the persons is cached in the read-ahead cache and the second setCompany call doesn't cause the SQL again in a same transaction.

                        We could see this when you change the log4j priority to TRACE.

                        Miki

                        • 9. Re: it is slow to add entity to collection(relationship) in
                          richlin Newbie

                          >>But I believe the persons is cached in the read-ahead >>cache and the second setCompany call doesn't cause the >>SQL again in a same transaction.
                          thank Miki


                          And you mean that will work in same transaction(by cache)

                          but my client only create a person at one time...
                          in my system, create a person will wast 3~5 second(there are only 100000 persons)
                          the time will become longer when the person get more
                          (My persons may get more than 10000000) :-(


                          Maybe JBoss cant have a great relation Collection...
                          maybe we should use BMR to solve this problem

                          do anyone have solution...???

                          Thanks

                          PS.the same problem also happened in "n to m relationship"
                          JBoss also call some SQL that i dont need when i add some entitybean to relation collection...


                          arich

                          • 10. Re: it is slow to add entity to collection(relationship) in
                            richlin Newbie

                            >>read-ahead settings.
                            thank Georg

                            but I have try this setting too(on-find, on-load, none, page-size 1~250 and fetch-size on entitybean )

                            I remember the page size is work when you iterator the Entities on collection.

                            My situation is on adding a Entity to a large Relation Collection, there will be a slow execution SQL.



                            maybe you can try a test
                            Create a log of detail(more than 1000000) under one master (every creation on different transaction)
                            if your create rate is always fast
                            please tell me how you setting your Bean Relationship...

                            Thanks

                            Rich

                            PS.forgive my poor stupid English :-)

                            • 11. Re: it is slow to add entity to collection(relationship) in
                              Frank Adcock Newbie

                              Is your relationship unidirectional ?

                              • 12. Re: it is slow to add entity to collection(relationship) in
                                richlin Newbie

                                i have try both(unidirectional and directional)

                                and i modify the JBoss's source

                                http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ seem work

                                when you set relation the JBoss will check the other side relation collection...(even it is unidirectional)
                                so i jump the check which if the collection not load yet.


                                arich