Java 500M的表,约1千万的数据放在HashMap里面大约占用内存多大?给多大内存最保险?...

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

Java 500M的表放在HashMap里面大约占用内存多大?给多大内存最保险?

测试1、给 java -Xms2048m -Xmx2048m

运行结果,系统CPU占用很大,GC全局回收比较厉害。

GC:  Scavenge GC - Reason started:  Eden full - parallel with thread number:  8
GC:  Scav 7.613 s  Since start of previous GC: 7.613 s  GC time: 0.572 s
     Time spent executing application: 7.613 s  (93.02%)
     Object size causing failure: 48 bytes  MaxTenure: 7
     Eden: 536870912->48/536870912
     Survivor: 0->88072136/88080384 (survivor used: 99.99%)
     Old: 0->410543440/1434451968       (old used: 28.62%)
     Perm: 10869592->10869592/10911744
GC:  Full GC - Reason started:  Allocation failure  
GC:  Full 14.852 s  Since start of previous GC: 7.239 s  GC time: 12.318 s
     Time spent executing application: 6.667 s  (35.12%)
   **** WARNING: Too much time spent in GC (>20%)
     Object size causing failure: 40 bytes  MaxTenure: 7
     Eden: 536870912->40/536870912
     Survivor: 88072136->0/88080384 (survivor used: 0.00%)
     Old: 410543440->1004089160/1434451968       (old used: 70.00%)
     Perm: 10870672->10870672/10977280
GC:  Full GC - Reason started:  Allocation failure  
GC:  Full 32.144 s  Since start of previous GC: 17.291 s  GC time: 9.114 s
     Time spent executing application: 4.974 s  (35.31%)
   **** WARNING: Too much time spent in GC (>20%)
     Object size causing failure: 152 bytes  MaxTenure: 7
     Eden: 536870912->72980680/536870912
     Survivor: 0->0/88080384 (survivor used: 0.00%)
     Old: 1004089160->1434417264/1434451968       (old used: 100.00%)
   **** WARNING: Sufficient Old Space not reclaimed (<20%)

测试2、给 java -Xms8092m -Xmx8092m

运行还行。

GC:  Scavenge GC - Reason started:  Eden full - parallel with thread number:  8
GC:  Scav 35.977 s  Since start of previous GC: 35.977 s  GC time: 2.516 s
     Time spent executing application: 35.977 s  (93.46%)
     Object size causing failure: 32 bytes  MaxTenure: 7
     Eden: 2147483648->32/2147483648
     Survivor: 0->356483168/356515840 (survivor used: 99.99%)
     Old: 0->1583995632/5729419264       (old used: 27.65%)
     Perm: 10872000->10872000/10977280
GC:  Scavenge GC - Reason started:  Eden full - parallel with thread number:  8
GC:  Scav 72.401 s  Since start of previous GC: 36.424 s  GC time: 3.535 s
     Time spent executing application: 33.908 s  (90.56%)
     Object size causing failure: 104 bytes  MaxTenure: 7
     Eden: 2147483648->104/2147483648
     Survivor: 356483168->356491160/356515840 (survivor used: 99.99%)
     Old: 1583995632->3541143400/5729419264       (old used: 61.81%)
     Perm: 10873672->10873672/10977280
$ 

 

 map's size is 13318240 finshed!, totally used 86229 millionseconds ##处理完成约需要86秒左右

总结:

1千万数据放在内存中,约需要8G启动堆大小。

另外通过这次测试发现 Map 比POJO要更占用内存。

转载于:https://my.oschina.net/u/2308739/blog/708618

你可能感兴趣的:(Java 500M的表,约1千万的数据放在HashMap里面大约占用内存多大?给多大内存最保险?...)