简体   繁体   English

Spring Web应用程序内存配置文件怀疑

[英]Spring web application memory profiling doubts

I have Spring application with top command showing following data on Amazon EC2 small instance ( 1.7 GB RAM ) - 我有带有top命令的Spring应用程序,该命令在Amazon EC2小型实例(1.7 GB RAM)上显示以下数据-

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                  
 5019 ubuntu    20   0 1971m 446m  17m S  4.7 27.0  31:25.61 java    

This is taking 446 MB of memory only for booting software and I have about 350 classes and there are libraries brought in as dependencies by Maven. 仅用于启动软件就占用446 MB的内存,我大约有350个类,并且有一些库由Maven引入为依赖项。

free -m 

             total       used       free     shared    buffers     cached
Mem:          1656       1642         14          0         34        519
-/+ buffers/cache:       1088        568
Swap:          895         12        883

Maven Spring dependencies are there - Maven Spring依赖项在那里-

Spring Core, Spring MVC, Spring Data , Spring Data Rest, , Spring
Security, Spring HATEOAS, Spring Boot, Spring Oauth , Spring-Vaadin

I was comparing this memory footprint to jenkins that is taking 277 MB in total but my test application apparently takes +400 MB without running anything significantly. 我将这个内存占用量与jenkins总共需要277 MB进行了比较,但是我的测试应用程序显然占用了+400 MB,而没有运行任何东西。

At this point code has only Entities and Spring Data Rest. 此时,代码只有实体和Spring Data Rest。 I did a heap dump analysis and it shows that hibernate took 15 MB for PID as top consumer from application ( taken using jmap ) 我进行了一个堆转储分析,结果表明休眠状态占用了15 MB的PID作为应用程序的主要使用者(使用jmap进行获取)

Used heap dump  76.9 MB
Number of objects   1,785,039
Number of classes   12,546
Number of class loaders 245
Number of GC roots  2,589
Format  hprof

Biggest Top-Level Dominator Class Loaders report in MAT shows - MAT节目中最大的顶级Dominator类加载器报告-

org.eclipse.jetty.webapp.WebAppClassLoader @ 0xf00f8bb0  - 45 MB - 56.91%
  1. Does Spring web applications in general take +400 MB for just starting up when above libraries are added as dependency and run using mvn jetty:run ? 将上述库作为依赖项添加并使用mvn jetty:run运行时,Spring Web应用程序一般是否仅花费+400 MB即可启动?
  2. Here heap occupancy is shown as 77 MB by jmap though top command shows +400 MB , why they don't match as they both are for same PID 5019 尽管top命令显示+400 MB,但jmap此处的堆占用量显示为77 MB,为什么它们不匹配,因为它们都是相同的PID 5019
  1. It's hard to estimate based on the libraries alone as it depends on your jvm settings, what do you do with your application, did your bootstrap related code used memory efficiently etc? 仅凭库就很难估算,因为它取决于您的jvm设置,如何处理应用程序,与引导程序相关的代码是否有效地使用了内存等? 400mb sounds pretty normal for an app with those dependencies. 对于具有这些依赖性的应用程序,400mb听起来很正常。

  2. Heap occupancy is just the portion of memory used by your code and libraries. 堆占用率只是代码和库使用的内存部分。 jvm needs memory too to run. jvm也需要内存才能运行。 Plus your OS might have its own intricacies when allocating memory. 另外,您的操作系统在分配内存时可能会有其自身的复杂性。

You can try adjusting various jvm heap memory settings (see http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html ). 您可以尝试调整各种jvm堆内存设置(请参见http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html )。 Some pretty common settings are -Xmx -Xms -XX:MaxPermSize. 一些非常常见的设置是-Xmx -Xms -XX:MaxPermSize。

My recommendation is use some jvm profiling tool that gives you a heap usage graph (eg: visualvm), make sure the heap consumption doesn't climbs up (look for a sawtooth pattern), and then you can gauge how much you need and adjust the VM parameter . 我的建议是使用一些jvm分析工具,该工具会为您提供堆使用情况图表(例如:visualvm),确保堆消耗不会增加(查找锯齿状图形),然后您可以确定需要多少并进行调整VM参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM