3 Replies Latest reply on Jun 8, 2005 1:21 AM by elkner

    How are sessions handled ?

    elkner

      Hi,

      since JBOSS uses hibernate3 for EJB3 support, I wrote a little hibernate3 app to get a better feeling how it works and how one may get a better performance.

      The conclusion of my tests are, that it is very important, that closing or at least clearing a session is one of the keys to get better performance.

      So my question: Is somebody able to explain, how sessions are used/handled by jboss?

      To get a clue, why it is important, here are some test results derived from the plain hibernate appl. described below:

      insert strategie: per entry file file-coll. file
      auto-close session: yes yes yes no
      ------------------------------------+---------+----------+----------+-----------
      sessions opened: 14965 519 9 2
      sessions closed: 14965 519 9 2
      transactions: 29927 1035 15 519
      successful transactions: 14963 517 7 517
      flushes: 14963 14724 14709 14724
      connections obtained: 14965 519 9 2
      second level cache puts: 0 0 0 0
      second level cache hits: 0 0 0 0
      second level cache misses: 0 0 0 0
      entities loaded: 15502 1056 631 0
      entities updated: 13037 13037 13037 13037
      entities inserted: 20104 20104 20104 20104
      entities deleted: 0 0 0 0
      entities fetched (minimize this): 0 0 0 0
      collections loaded: 4 4 4 0
      collections updated: 0 0 0 0
      collections removed: 0 0 0 0
      collections recreated: 17082 17082 17082 17082
      collections fetched (minimize this): 4 4 4 0
      queries executed to database: 29939 15493 15493 15493
      query cache puts: 0 0 0 0
      query cache hits: 0 0 0 0
      query cache misses: 0 0 0 0
      max query time: 237ms 166ms 587ms 446ms
      ------------------------------------+---------+----------+----------+-----------
      Total Execution Time: 02:09,791 01:37,897 07:42,055 53:28,912
       wrt. to best strategie: 132 % 100 % 472 % 3278 %
      



      The app does the following: It reads 5 (actually 7, but the last two are all empty) collections of xml files, where each collection has about 80 files. Each file contains about 2500 elements, which are consolidated to about 50 new entities and 166 associations for a many-to-many relationship, which are inserted into the db. So at the end of the run, there are 20104 new entities and new 66572 entries in the many-to-many assoc. table. The backing db is MySQL InnoDB 4.1.7.

      In the first three test cases (entry, file, file-coll.), hibernate's hibernate.transaction.auto_close_session is set to true, so the session is automatically closed after each transaction. In the "entry" test-case, a new entity gets persisted as soon as it is constructed within a single tx. In the "file" test case, new entities are collected in a list and persited in one tx as soon as the whole file has been read. In the "file-coll." test case (as you probably already guess) all new entities are clollected in a list and persisted, as soon as one whole file collection has been read within a single tx. The last column shows the huge performance loss, if one uses the test case with the best result (i.e. "file"), but auto session close after tx disabled and no manually clearing of the session.

      Testing a little bit more, I found out, that I can get even 15% better perf wrt. the auto-close "file" test case, when using the "file-coll." test case, but with auto close disabled AND clearing the session after every 10 entity persits manually ...

      So, please, give us some advices, whether/how one may influence the sessions within jboss!

      BTW: Of course, tests were made several times and the whole db incl. logs cleared before starting a new test.