-
1. Re: How does memory management work?
adrian.brock Jun 19, 2003 5:46 PM (in response to sven.baumgarten)The pool has little effect on memory usage.
It is just a bunch of ready to use bean
instances.
Your problem will be the default cache size
<max-capacity>1000000</max-capacity>
That is 1 million bean instances per entity bean.
Regards,
Adrian -
2. Re: How does memory management work?
sven.baumgarten Jun 25, 2003 1:13 PM (in response to sven.baumgarten)Hi Adrian,
I've made some test the last few days. First of all I limited the cache from 10 to 50 beans. but there was no real improvement. Then I did some memory monitoring with JMP (Java Memory Profiler).
There are 2 Entity Beans "OrderBean" and "OrderItemBean" connected by 1:N relation an a Session Bean "OrderCtrlBean". The OrderCtrl has the following method:
1 public void testReadOrderItem(int id) {
2 try {
3 InitialContext ctx;
4 ctx = new javax.naming.InitialContext();
5 Object obj = ctx.lookup("ejb/OrderLocal");
6 OrderLocalHome orderHome = (OrderLocalHome) PortableRemoteObject.narrow(obj, OrderLocalHome.class);
7
8 OrderLocal order = orderHome.findByPrimaryKey(new Integer(id));
9
10 Iterator it = order.getOrderItem().iterator();
11 while (it.hasNext()){
12 OrderItemLocal orderItem = (OrderItemLocal) it.next();
13 System.out.println(orderItem.getId());
14 }
15 }
16 catch (Exception ex) {
17 ex.printStackTrace();
18 }
19 }
In the test database every order has two items.
At start there are no instances of OrderBean and OrderItemBean. After first call of this method there are two instances of "OrderBean$Proxy" (OrderBean) and "OrderItemBean$Proxy" (OrderItemBean). The first instance of OrderBean is created at line 8 and the second one at the first call of line 10 (I don't know why this). The instances of OrderItemBean are created at line 12.
On Every call of the method testReadOrderItem two OrderBean instances and two OrderItemBean instances are created until 51 instances of each class are reached. Then somthing strange happens. If the method is called again one instance of OrderBean would be created and no more instances of OrderItemBean.
In this way more and more instances of OrderBean are created and this fills the memory. Garbage Collection does not remove any instance of OrderBean.
Why are so many OrderBean instances created?
Regards
Sven -
3. Re: How does memory management work?
adrian.brock Jun 25, 2003 8:23 PM (in response to sven.baumgarten)The finder needs an instance of OrderBean
that is not associated with a primary key.
I would expect this to be served from the pool
rather than creating a new one everytime.
The 1 in the 51 (50 are in cache).
Can you post your simple test and config?
Regards,
Adrian -
4. Re: How does memory management work?
sven.baumgarten Jun 26, 2003 5:27 AM (in response to sven.baumgarten)Hi Adrian,
here is my test project. JBossTest.zip contains the complete JBuilder project. JBossTest.jar is the server component and contains the deployment descriptors. In JBossTestClient.java you have to change the IP "192.168.1.36" to the IP of your JBoss server. The configuration files are in JBoss_Conf.zip. The EJB use default database connection. JBossTestDatabase_MSSQL2000.sql contains the database creation skript for MS SQL Server 2000.
The client JBossTestClient first creates order objects (method writeOrders). This works as expected. Second the client reads the orders (method readOrders). This is where the problem is.
Java Memory Profiler: http://www.khelekore.org/jmp
JBoss start with Java Memory Profiler: C:\Programme\Java\j2sdk1.4.1\bin\java -Xms64m -Xmx128m -classpath C:\Programme\Java\j2sdk1.4.1\lib\tools.jar;C:\jboss-3.2.1\bin\\run.jar -Xrunjmp:nomonitors;nomethods:filter=jbosstest org.jboss.Main -
5. Re: How does memory management work?
sven.baumgarten Jul 4, 2003 4:00 AM (in response to sven.baumgarten)Hi Adrian!
did you find out everything? I would be very satisfied if you can give a short feedback if you could retrace my problem.
Regards,
Sven -
6. Re: How does memory management work?
adrian.brock Jul 5, 2003 5:14 AM (in response to sven.baumgarten)I don't have JBuilder or MSSQL so I left it until
I felt like converting it. But it has dropped off
my radar.
Could you convert it to run under a default jboss
installation, i.e. a ready to deploy ejb application
and hsqldb.
Regards,
Adrian -
7. Re: How does memory management work?
sven.baumgarten Jul 7, 2003 2:42 AM (in response to sven.baumgarten)JBossTest.jar in JBossTest.zip is ready for deployment. You only have to copy it into the deploy folder. It uses the default db-connection defined in standardjbosscmp-jdbc.xml. JBossTestClient.java is the client.
Regards,
Sven -
8. Re: How does memory management work?
adrian.brock Jul 7, 2003 8:47 AM (in response to sven.baumgarten)I had lots of fun trying to get your testcase to work with
hsqldb. Catching Exception, dumping the trace and continuing
is not recommended practice.
Anyway, I don't see the problem you state. When I set the
cache to 50, there are 51 OrderItems and Orders.
50 for the cache (commit-option B) and one each in your
EJBLocalHome factory.
You did run the garbage collector?
Regards,
Adrian -
9. Re: How does memory management work?
sven.baumgarten Jul 7, 2003 9:24 AM (in response to sven.baumgarten)No i did not. Do I have to run the garbage collector myself?
Regards,
Sven -
10. Re: How does memory management work?
adrian.brock Jul 7, 2003 9:33 AM (in response to sven.baumgarten)It is non-determinstic when the gc runs.
It does make a best effort to remove all garbage
before throwing OutOfMemory
Regards,
Adrian -
11. Re: How does memory management work?
sven.baumgarten Jul 7, 2003 10:15 AM (in response to sven.baumgarten)I did the test again with the source code i posted. I only reduce the for iteration in the client from 2500 to 500. In the attached word document you can see the results. Writing works correctly and reading not. I made the screen shots always after running gc (autmatically by the server).
Regards,
Sven -
12. Re: How does memory management work?
adrian.brock Jul 7, 2003 10:47 AM (in response to sven.baumgarten)I see the same for both tests, although I only had 50
in my cache and 100 in my test.
I am using jboss3.2.2RC2 from CVS rather than 3.2.1
Regards,
Adrian -
13. Re: How does memory management work?
sven.baumgarten Jul 8, 2003 6:20 AM (in response to sven.baumgarten)That's it! I have downloaded jboss3.2.2RC1 binary and now it works.
Thank you very much for your help.
Regards,
Sven