0

we have big problems with query performance in ObjectDB, this is our code. Any help would be appreciated.

First version of query gives result in 50ms for first 40 records from database but second version which queries 40+ records gives 19 seconds. We pinpointed that from he 53 record performances degrades significantly. On other queries threshold is different, possible due the size of the results (probably related to the number of related objects)

First version of code.

EntityManagerFactory emf = Persistence.createEntityManagerFactory("objectdb://10.10.10.14/E_POLICIJA.odb;user=admin;password=admin"); //$NON-NLS-1$

           em = emf.createEntityManager();


         long startTime;
         long endTime;

         startTime = System.currentTimeMillis();

          int i = 0;
          while(i < 40){
              TypedQuery<AktImpl> queryAkt =
                  em.createQuery("SELECT e FROM AktImpl e", AktImpl.class);

              queryAkt.setFirstResult(i);
              queryAkt.setMaxResults(20);
              queryAkt.getResultList();
              i += 20; 
          }

          endTime = System.currentTimeMillis();
        System.out.println((endTime - startTime));
    }

Second version of code

           EntityManagerFactory emf =
                    Persistence.createEntityManagerFactory("objectdb://10.10.10.14/E_POLICIJA.odb;user=admin;password=admin"); //$NON-NLS-1$

           em = emf.createEntityManager();


         long startTime;
         long endTime;

         startTime = System.currentTimeMillis();

          int i = 0;
          while(i < 60){
              TypedQuery<AktImpl> queryAkt =
                  em.createQuery("SELECT e FROM AktImpl e", AktImpl.class);

              queryAkt.setFirstResult(i);
              queryAkt.setMaxResults(20);
              queryAkt.getResultList();
              i += 20; 
          }

          endTime = System.currentTimeMillis();
        System.out.println((endTime - startTime));
    }

Thanks for any help

dilindul
  • 13
  • 3

1 Answers1

0

The problem was found to be a circular eager relationship, defined in that specific application, which required loading of many objects recursively with the query results.

The solution was to change the relationship setting from eager to lazy.

More details can be found in this forum thread.

ObjectDB
  • 1,312
  • 8
  • 9
  • Actualy lazy loading didnt solve the problem, currently we have changed bidirectional relationship to unidirectional and implementing additional queries. Still work in progres :) – dilindul Jan 19 '14 at 20:28
  • 1
    Conclusion is that ObjectDB is not the source of the problem. Bidirectonal relationships should definetly be better implemented in some standard way. – dilindul Jan 19 '14 at 20:30