ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

Memeory Rlease issue with ZK on JBoss 4.3

Willemvdw
9 Feb 2010 03:34:20 GMT
9 Feb 2010 03:34:20 GMT

We are using ZK 3.6 on jboss 4.3 with Rest Easy (Jboss).. Our Memory consumption is being increased gradully and it never comes down...
We are Using RHEL 4 32 bit machine...JDk 6...I have tried to find the memory heap information using JProfiler...Not getting clear data...

Please share some thoughts on this...we have used all combination of Java Opts setting...Even Hugedata demo application of the community is also taking memory in Jboss stack...

Thanks,
Willem

iantsai
9 Feb 2010 04:35:00 GMT
9 Feb 2010 04:35:00 GMT

I think the first step here is to identify which part of your application cause the problem.

You need to do an architecture review.

any cache module, Sessions, static Collections and Singleton member fields should be analyzed.

without this, there's noway for tools to dig out the issue.

xmedekoTop Contributor
10 Feb 2010 08:37:09 GMT
10 Feb 2010 08:37:09 GMT

Hi Willemvdw,

ZK has a serious memory leak when you redeploy WAR, see http://www.zkoss.org/forum/listComment/10270

Willemvdw
4 Mar 2010 04:39:05 GMT
4 Mar 2010 04:39:05 GMT

This is more details about my finding..probably people can advice me on basis of this..

I ran JBoss through JProfiler total memory is 2 gb ..
i ran a load test of 50 users for 30 mintues.. CPU and memory has gone to upper limits and server stops responding upto 1 hour..GC interval is 30 mintues..


Our ZK Application uses mostlly Grid, Tab, List (It is being poplated by List Render )and Label
This is brief details of top objects that occupies the most memory from Jprofile GUI screen

char[]: 491 mb
Java.lang.String: 210 mb
init[]: 168 MB
bsh.token: 90 mb
byte[]: 90 mb
zul.listcell: 80 mb
hasmap$entry: 50 mb
hashmap 35 mb
object[] 35 mb
CourseBean: 32 MB our custom java Class ...this been use to populate the list object
bsh:node[] 20 mb
BSHPrimaryExpression 15 mb
BSHAmbigiousName 15 mb
zk.ui.AbstractComponent$ch... 12 mb

so subsequntlly other object that occupies the memory related with ZK classs, our custom class and bsh object..

xmedekoTop Contributor
4 Mar 2010 05:10:26 GMT
4 Mar 2010 05:10:26 GMT

Do you experience these problems only when you redeploy your app? Redeploy means undeploy and deploy. See my comment above or see http://xmedeko.blogspot.com/2010/02/java-web-container-hunting-redeploy.html

If not, then you should be able to easily find the root of your leak by JProfiler or Eclipse Memory Analyzer (MAT). Just take a suspected leak object and follow the path to the root GC without weak and soft references.

Willemvdw
4 Mar 2010 05:14:44 GMT
4 Mar 2010 05:14:44 GMT

This posting is talking about the BSH jar...that cuses memory leak
http://sourceforge.net/tracker/index.php?func=detail&aid=1736858&group_id=152762&atid=785191
I have also implemented that and checked the memory status..

This is the finiding..

with fixed jar, 50 user 30 mintues... Jboss has recollected the memory and has come back to its prestatus aftre 60 mintues..
with not fixed jar , 50 user 30 mintues locad, Jboss has recollected partial memory aftre 80 mintues...
now replicating same schenario and checking whether it is consistent behaviour or not..

Willemvdw
4 Mar 2010 05:18:31 GMT
4 Mar 2010 05:18:31 GMT

Thanks for your quick response
No, this is not at all related with redeploy or deploy problem..

Willemvdw
4 Mar 2010 08:42:29 GMT
4 Mar 2010 08:42:29 GMT

My Finding is when load is very extreme let us say 50 concurrent user for long time for an hour, server stops responding...and outofmemory Error occurs..otherwise if load is moderate server goes up and comes down at ceratin interval..that bsh.jar related fixes has no implication... please advice

xmedekoTop Contributor
4 Mar 2010 10:38:53 GMT
4 Mar 2010 10:38:53 GMT

Probably it is not a leak. Looks like you have too many of listcells. How long lists do you generate? If you have very long lists, try paging. Even if you use "live" list model, then it keeps all list items in the memory, when the user scrolls down the whole list down.

Willemvdw
4 Mar 2010 22:30:15 GMT
4 Mar 2010 22:30:15 GMT

we using paging...

xmedekoTop Contributor
5 Mar 2010 02:25:03 GMT
5 Mar 2010 02:25:03 GMT

And does your implementation of paging release the unused listitems properly?

Willemvdw
5 Mar 2010 08:59:16 GMT
5 Mar 2010 08:59:16 GMT

I would like to paste my render class and zul file as well here...probably you can advice me ....thanks for your valuable input...

----------------------------------------------RendererClass-------------------------------------------------------------------------------
/*
* Created on Apr 21, 2006
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.kwantu.kdl.dao;

import java.text.DecimalFormat;

import org.kwantu.kdl.data.WorkersBean;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.ListitemRenderer;

/**
*
* @author ajay.abrol
*
*/
public class RenderReadWorker implements ListitemRenderer {

/**
*
*/
public RenderReadWorker() {
super();
}

/*
* (non-Javadoc)
*
* @see com.potix.zul.html.ListitemRenderer#render(com.potix.zul.html.Listitem,
* java.lang.Object)
*/
public void render(Listitem item, Object data) throws Exception {

DecimalFormat df = new DecimalFormat("#,###.##");
WorkersBean subscription = (WorkersBean) data;
Listcell cell = new Listcell(subscription.getSurName());
cell.setParent(item);
cell = new Listcell(subscription.getInitial());
cell.setParent(item);
cell = new Listcell(subscription.getIdNumber());
cell.setParent(item);
cell = new Listcell(subscription.getDateOfBirth());
cell.setParent(item);
cell = new Listcell();
Checkbox chkbox = new Checkbox();
if (Integer.parseInt(subscription.getEmpDays()) > 0) {
chkbox.setChecked(true);
} else {
chkbox.setChecked(false);
}
chkbox.setDisabled(true);
chkbox.setParent(cell);
cell.setParent(item);
cell = new Listcell(df.format(Double.parseDouble(subscription
.getEmpRate())));
cell.setStyle("float:right;");
cell.setParent(item);
cell = new Listcell(" ");
cell.setParent(item);
cell = new Listcell(subscription.getEmpDays());
cell.setStyle("float:right;");
cell.setParent(item);
cell = new Listcell(" ");
cell.setParent(item);
cell = new Listcell(df.format(Double.parseDouble(subscription
.getEmpTotal())));
cell.setStyle("float:right;");
cell.setParent(item);

cell = new Listcell();
Checkbox chkboxtraining = new Checkbox();
if (subscription.getTrainingCourse() != null
&& !subscription.getTrainingCourse().equals(" ")) {

chkboxtraining.setChecked(true);
} else {
subscription.setTrainingCourse(" ");
subscription.setTrainingDays("0");
chkboxtraining.setChecked(false);
}
chkboxtraining.setDisabled(true);
chkboxtraining.setParent(cell);
cell.setParent(item);
cell = new Listcell(subscription.getTrainingCourse());
cell.setParent(item);
cell = new Listcell(subscription.getTrainingDays());
cell.setStyle("float:right;");
cell.setParent(item);
cell = null;
subscription = null;

}

}

---------------------------------------------------ZUL FIle----------------------------------------------------------


<zk>
<zscript>
import org.kwantu.kdl.dao.KDLCommonData;
import org.kwantu.kdl.data.*;
import java.util.*;
import java.text.DateFormat;

exitread()
{
readformnn.detach();
}

void initViewScreen()
{
subscription = params.get("subscription");
KDLCommonData kdlCommonDataedit = new KDLCommonData();
List subscriptions1=kdlCommonDataedit.workersData("0","","",periodId);
kdlCommonDataedit=null;
ListModel listboxData1 = new SimpleListModel(subscriptions1);
subscriptionListbox.model=listboxData1;
subscriptionListbox.invalidate();
}

params = Executions.getCurrent().getArg();
action = params.get("action");
periodId=params.get("periodId");
initViewScreen();

</zscript>

<window title="Worker Details" id="readformnn" use="" border="normal" width="900px"
xmlns:h="http://www.w3.org/1999/xhtml">

<listbox id="subscriptionListbox" model="${listboxData1}"
itemRenderer="org.kwantu.kdl.dao.RenderReadWorker" width="880px" height="300px" >
<auxhead forEach="${profileControllernew.capturerList}">
<auxheader label="Capture Data for : ${each.periodName}" colspan="6"/>
<auxheader label="Employment" colspan="4"/>
<auxheader label="Training" colspan="4"/>
</auxhead>
<listhead sizable="true" >
<listheader label="SurName" width="90px" />
<listheader label="Initial" width="90px" />
<listheader label="ID Number" width="70px"/>
<listheader label="DOB" width="70px"/>
<listheader label=" " width="30px"/>
<listheader label="Rate" width="70px"/>
<listheader label=" " width="5px"/>
<listheader label="Days" width="70px"/>
<listheader label=" " width="5px"/>
<listheader label="Amount" width="70px"/>
<listheader label=" " width="40px"/>
<listheader label="Course" width="70px"/>
<listheader label="Days" width="60px"/>
</listhead>
</listbox>
<div align="center">
<button label="Cancel" sclass="button" onClick="exitread()" />
</div>

</window>
</zk>

terrytornadoTop Contributor
5 Mar 2010 09:34:21 GMT
5 Mar 2010 09:34:21 GMT

Willem, have you ever try to cut the zscript (for prototyping) and do the logic in a JAVA controller ?
So you can exclude that it doesn't come from the BSH.

xmedekoTop Contributor
5 Mar 2010 14:10:29 GMT
5 Mar 2010 14:10:29 GMT

Well, I do not see any paging in your ZUL. SimpleListModel loads all data. E.g. when your subscriptions1 has size 10000, then 10000 ZK listitem is created. I guess this eats your memory.

Check http://docs.zkoss.org/wiki/Handling_huge_data_using_ZK#The_PagingListModel_and_the_AbstractPagingListModel

And use MVC as terrytornado has suggested.

Willemvdw
6 Mar 2010 02:37:21 GMT
6 Mar 2010 02:37:21 GMT

this is very less used code that is why paging has not been used else hage data example and obviously paging has been followed ...

Willemvdw
6 Mar 2010 07:39:48 GMT
6 Mar 2010 07:39:48 GMT

THis is the results case of ZKHugeDataExample/hugedata.zul ..i used the JProofiler and using WAFT load test tool ..i put a load of 50 user for 20 mintues..

char[]: 221 mb
Label 166 MB
Java.lang.String: 88 mb
init[]: 71 MB
byte[]: 54 mb
zul.listcell: 80 mb
hasmap$entry: 83 mb
hashmap 65 mb
object[] 28 mb
zul.row :45 mb
ListBoXEventListenerCourse: 31 MB

and other objects are related with ZK classes..

This has not released the memory upto 1 hour ....When GC interval would run .....it will recollect the memory ....please share your valuable thoughts

xmedekoTop Contributor
6 Mar 2010 12:21:01 GMT
6 Mar 2010 12:21:01 GMT

Interesting. May you try to make the same test with the simple list (no paging, no huge data) with only 20 or so items?

How WAFT handles cookies? Does mean WAFT 50 users creates only 50 HTTP sessions?

iantsai
7 Mar 2010 19:52:53 GMT
7 Mar 2010 19:52:53 GMT

First, put your code inside Java using a GenericForwardComposer is very easy, you can google it.
Second, even there's a few people access this page, this page still allowed one user to use more than 10 MB memory of your Server, which means a Note Book with Apache Benchmark could knock you down.

I'll suggest at the first step, you should refactor your code to ZK MVC way, and do your test again.
then, create a smaller dummy model which only has 100 ~ 200 records comparing to your original one, and do the test again.

Willemvdw
8 Mar 2010 00:12:32 GMT
8 Mar 2010 00:12:32 GMT

xmedeko, Thanks again...I have just run a schenario to check no of http sessions..it has created 24000 session object in load test of 20 users 20 mintues..
iantsai, We are using Jboss Restesy in our service layer...going with ZK MVC would not be easier for us...

xmedekoTop Contributor
8 Mar 2010 01:49:56 GMT
8 Mar 2010 01:49:56 GMT

Hm, it has just proved ZK is vulnerable to DoS attacks. It would be interesting to try your tests on http://www.zkoss.org/zkdemo/userguide/ :-)

Willemvdw, I think iantsai wanted to say that BSH script in the ZUL increases the memory footprint and decreases the speed. Better is to avoid it in a high load environment, see http://docs.zkoss.org/wiki/Performance_tip

1 2