消耗巨大记忆的火焰 [英] blazesds consuming huge memory

查看:256
本文介绍了消耗巨大记忆的火焰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BlazeDS 4用于与Flex4.6进行通信。当flex客户端在blazeds服务器上调用
远程调用时,服务器返回一个包含POJO的arrayList。
假设每个POJO mem大小是12个字节,我期望arrayList大小
是12 *元素的数量。不过,我发现在某个地方,这是
多次复合。假设我将200000个POJO添加到数组列表中,
我期待它的大小为〜2MB。但是,我可以看到通过配置文件,
JVM射击N倍的原始大小和相同的N倍mem是
被转移到灵活的浏览器应用程序也。下面列出的是
示例代码,用jmap分析器捕获来演示这个问题。
如果需要的话,我会很乐意提供flex代码。

$ p $ List list = new ArrayList();
for(i = 0; i <200000; i ++)
{SampleClass sampleClassObj = new SampleClass();
sampleClassObj.setId(1);
sampleClassObj.setAge(20);
list.add(sampleClassObj);
}
返回列表;

和SampleClass类的定义如下

  public class SampleClass 
{
long id;
int年龄;
//每个变量的getters和setters
}

驻留在jdk路径中的jmap.exe。
从客户端收到请求之前,JVM中的intitail内存为〜50MB。
从客户端请求之前的jmap的输出。

num  #instances  #bytes 班级名称

1  63135   8497488  constMethodKlass

2  65671   7858440  [C
3  91344   5217976 符号Klass





总计  658429   50097416&NBSP; //在JVM中的初始内存



处理请求后的jmap的输出



num  ; #instances  #bytes 班级名称

1   11402   20225512  [B
2    200000   1948809  SampleClass //预期为〜2MB

3 62734   8451040  constMethodKlass




total  1175132   93938272&NBSP; //在JVM中消耗的内存不是垃圾收集。

奇怪的是,当我尝试从Flex重复调用同一个方法时,JVM内存不相应增加。在JVM中看到的只是第一次多倍增长。但是,Flex客户端应用程序的内存不断增加,每一次调用。

我甚至尝试在YourKit分析器上运行相同的尝试,并尝试多次调用GC多次枉。



有人可以让我明白在blazeds里面发生了什么事情。

解决方案

默认 ArrayList 容量是10个对象,如果当前容量已经结束,添加新对象后,您的列表会增加当前容量50%的自我容量。也许这是记忆力的原因。尝试阅读这篇文档 http://docs.oracle。 com / javase / 6 / docs / api / java / util / ArrayList.html


BlazeDS 4 is used to communicate with Flex4.6. When flex client invokes a remote call on blazeds server, server returns an arrayList containing POJOs. Assuming each POJO mem size is 12 bytes, I am expecting the arrayList size to be 12*number of elements. However, I find that somewhere in blazeds, it is compounded multiple times. Assuming I add 200000 POJOs into the array list, I am expecting its size to be ~2MB. But, I could see through profilers, that JVM shoots up N times of original size and the same N times mem is being transfered to the flex browser application also. Below listed is a sample code that demonstrates the problem, with jmap profiler captures. I would be happy to provide the flex code also if needed.

    List list = new ArrayList();
for(i=0;i<200000;i++)
{ SampleClass  sampleClassObj = new SampleClass();
  sampleClassObj.setId(1);
  sampleClassObj.setAge(20);
  list.add(sampleClassObj);
} 
return list;

And the SampleClass class definition is as follows

public class SampleClass
{
    long id;
    int age;
    // getters and setters for each variables
}

Memory is profiled in jmap.exe which resides in jdk path. The intitail memory in JVM before recieving a request from client was ~50MB. The output from jmap before request from client.

num  #instances   #bytes   class name
1   63135    8497488   constMethodKlass
2   65671    7858440   [C
3   91344    5217976   symbolKlass
.
.
total  658429    50097416  //initial memory in JVM

The output from jmap after processing request.

num  #instances   #bytes   class name
1   11402    20225512   [B
2   200000    1948809   SampleClass //as expected to be ~2MB
3   62734    8451040   constMethodKlass
.
.
total  1175132    93938272  //consumed memory in JVM which is not garbage collected.

Strange enough, when I try to invoke the same method from Flex repeatedly, the JVM memory does not correspondingly increase. It is only the first time multifold increase that is seen in JVM. However, the flex client application memory keeps increasing for every call.

I even tried running the same on YourKit profiler and tried invoking GC multiple times in vain.

Can someone please make me understand what is going on within blazeds.

解决方案

In default ArrayList capacity is 10 objects, after your adding new object if current capacity is over, your list increase self capacity in 50% of current capacity. Maybe this is reason of memory liks. Try to read this docs http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

这篇关于消耗巨大记忆的火焰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆