java Tomcat内存消耗

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6663179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:51:13  来源:igfitidea点击:

Tomcat Memory Consumption

javatomcatjvmheaptomcat7

提问by ajduke

I am going to install Tomcat on linux with JVM Heap size as 2048m(2GB) to 2304m(2GB+256MB) by setting CATALINA_OPTS="-Xms2048m -Xmx2304m"in cataina.sh fileand the Linux OS have 8GB of the RAM so i am making some points , please help with this

我将通过设置CATALINA_OPTS="-Xms2048m -Xmx2304m"在linux 上安装 Tomcat,JVM 堆大小为 2048m(2GB) 到 2304m(2GB+256MB),cataina.sh fileLinux 操作系统有 8GB 的​​ RAM,所以我要提出一些观点,请帮助解决这个问题

  • Should tomcat consume directly 2GB from OS?
  • If no to above ,then how much it should take?
  • If memory is taken by the tomcat is less than 2GB then this 2GB memory allocated by os for this tomcat is only used for this only or some app can use this memory?
  • and finally we are setting the this max and min memory , means OS allocates all that amount of the memory for tomcat?
  • tomcat 应该直接从操作系统消耗 2GB 吗?
  • 如果上面没有,那么应该花多少钱?
  • 如果tomcat占用的内存小于2GB,那么os为此tomcat分配的这2GB内存仅用于此用途还是某些应用程序可以使用此内存?
  • 最后我们设置了这个最大和最小内存,意味着操作系统为 tomcat 分配了所有的内存量?

回答by AngerClown

The JVM will pre-allocate whatever memory you specify for -Xms. So, it will request and allocate 2GB of memory at startup. If it needs more memory later (up to -Xmx), the JVM will request more memory from the OS.

JVM 将预先分配您指定的任何内存-Xms。因此,它会在启动时请求并分配 2GB 的内存。如果稍后需要更多内存(最多-Xmx),JVM 将向操作系统请求更多内存。

But, do you know you need this much memory? The main driver of memory consumption will be your appication notTomcat. Simple webapps with a few servlets or JSPs can easily run in less than 32MB of heap. You need to measure your application for performance / load to determine the optimal setting.

但是,你知道你需要这么多内存吗?内存消耗的主要驱动因素将是您的应用程序,而不是Tomcat。带有几个 servlet 或 JSP 的简单 web 应用程序可以轻松地在不到 32MB 的堆中运行。您需要测量应用程序的性能/负载以确定最佳设置。

A side note - the preferred method for setting JVM parameters is with the JAVA_OPTSsetting in setenv.sh, not catalina.sh.

旁注 - 设置 JVM 参数的首选方法是使用 中的JAVA_OPTS设置setenv.sh,而不是 catalina.sh。