Java 如何在不使用配置程序的情况下调整 Tomcat 5.5 JVM 内存设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/286007/
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-08-11 12:34:14  来源:igfitidea点击:

How to tune Tomcat 5.5 JVM Memory settings without using the configuration program

javatomcatmemoryjvm

提问by red

I need to configure Tomcat memory settings as part of a larger installation, so manually configuring tomcat with the configuration app after the fact is out of the question. I thought I could just throw the JVM memory settings into the JAVA_OPTS environment variable, but I'm testing that with jconsole to see if it works and it... doesn't.

我需要将 Tomcat 内存设置配置为较大安装的一部分,因此事后使用配置应用程序手动配置 tomcat 是不可能的。我以为我可以将 JVM 内存设置扔到 JAVA_OPTS 环境变量中,但我正在用 jconsole 测试它是否有效,但它......没有。

As per the comment below, CATALINA_OPTS doesn't work either. So far, the only way I can get it to work is via the Tomcat configuration GUI, and that's not an acceptable solution for my problem.

根据下面的评论,CATALINA_OPTS 也不起作用。到目前为止,我可以让它工作的唯一方法是通过 Tomcat 配置 GUI,这不是我的问题可接受的解决方案。

采纳答案by Glenn

Serhii's suggestion works and here is some more detail.

Serhii 的建议有效,这里有更多细节。

If you look in your installation's bin directory you will see catalina.sh or .bat scripts. If you look in these you will see that they run a setenv.sh or setenv.bat script respectively, if it exists, to set environment variables. The relevant environment variables are described in the comments at the top of catalina.sh/bat. To use them create, for example, a file $CATALINA_HOME/bin/setenv.sh with contents

如果您查看安装的 bin 目录,您将看到 catalina.sh 或 .bat 脚本。如果您查看这些,您将看到它们分别运行 setenv.sh 或 setenv.bat 脚本(如果存在)来设置环境变量。catalina.sh/bat 顶部的注释中描述了相关的环境变量。例如,要使用它们创建一个包含内容的文件 $CATALINA_HOME/bin/setenv.sh

export JAVA_OPTS="-server -Xmx512m"

For Windows you will need, in setenv.bat, something like

对于 Windows,您将需要在 setenv.bat 中,类似于

set JAVA_OPTS=-server -Xmx768m

Hope this helps, Glenn

希望这会有所帮助,格伦

回答by matt b

Use the CATALINA_OPTSenvironment variable.

使用CATALINA_OPTS环境变量。

回答by FoxyBOA

Not sure that it will be applicable solution for you. But the only way for monitoring tomcat memory settings as well as number of connections etc. that actually works for us is Lambda Probe.

不确定它是否适合您。但是监视 tomcat 内存设置以及连接数等的唯一方法是Lambda Probe

It shows most of informations that we need for Tomcat tunning. We tested it with Tomcat 5.5 and 6.0 and it works fine despite beta status and date of last update in end of 2006.

它显示了 Tomcat 调优所需的大部分信息。我们使用 Tomcat 5.5 和 6.0 对其进行了测试,尽管测试状态和上次更新日期为 2006 年底,但它仍能正常工作。

回答by kgiannakakis

If you'd start Tomcat manually (not as service), then the CATALINA_OPTS environment variable is the way to go. If you'd start it as a service, then the settings are probably stored somewhere in the registry. I have Tomcat 6 installed in my machine and I found the settings at the HKLM\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat6\Parameters\Javakey.

如果您要手动启动 Tomcat(而不是作为服务),那么 CATALINA_OPTS 环境变量就是要走的路。如果您将其作为服务启动,则设置可能存储在注册表中的某处。我在我的机器上安装了 Tomcat 6,我找到了HKLM\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat6\Parameters\Java关键的设置。

回答by Cozzman

Just to add to the previous comment, the documentation for the command line tool for updating the Tomcat service settings (if Tomcat is running as a service on Windows) is here. This tool updates the registry with the proper settings. So if you wanted to update the max memory setting for the Tomcat service you could run this (from the tomcat/bin directory), assuming the default service name of Tomcat5:

补充一下之前的评论,更新 Tomcat 服务设置(如果 Tomcat 作为服务在 Windows 上运行)的命令行工具的文档在这里。此工具使用正确的设置更新注册表。因此,如果您想更新 Tomcat 服务的最大内存设置,您可以运行它(从 tomcat/bin 目录中),假设 Tomcat5 的默认服务名称:

tomcat5 //US//Tomcat5 --JvmMx=512

回答by Serxipc

Create a setenv.(sh|bat) file in the tomcat/bin directory with the environment variables that you want modified.

在 tomcat/bin 目录中创建一个 setenv.(sh|bat) 文件,其中包含要修改的环境变量。

The catalina script checks if the setenv script exists and runs it to set the environment variables. This way you can change the parameters to only one instance of tomcat and is easier to copy it to another instance.

catalina 脚本检查 setenv 脚本是否存在并运行它以设置环境变量。通过这种方式,您可以将参数更改为仅 tomcat 的一个实例,并且更容易将其复制到另一个实例。

Probably your configuration app has created the setenv script and thats why tomcat is ignoring the environment variables.

可能您的配置应用程序已经创建了 setenv 脚本,这就是 tomcat 忽略环境变量的原因。

回答by Dmitriy Kochergin

I use following setenv.batcontents:

我使用以下setenv.bat内容:

==============setenv.bat============

    set JAVA_OPTS=-XX:MaxPermSize=256m -Xms256M -Xmx768M -Xdebug -Xnoagent  -Xrunjdwp:transport=dt_socket,address=7777,server=y,suspend=n %JAVA_OPTS%

====================================

It also enables debugging and sets debug port to 7777, and appends previous content of JAVA_OPTS.

它还启用调试并将调试端口设置为 7777,并附加JAVA_OPTS.

回答by DrTune

Handy for linux virtual machines; Use 75% of your total system memory for Tomcat. Yay AWK.

适用于 linux 虚拟机;将系统总内存的 75% 用于 Tomcat。是啊,AWK。

Put at start of "{tomcat}/bin/startup.sh"

放在“{tomcat}/bin/startup.sh”的开头

export CATALINA_OPTS="-Xmx`cat /proc/meminfo | grep MemTotal | awk '{ print *0.75 } '`k"

回答by Ondrej Kvasnovsky

I like the idea of seting tomcat6 memory based on available server memory (it is cool because I don't have to change the setup after hardware upgrade). Here is my (a bit extended memory setup):

我喜欢基于可用服务器内存设置 tomcat6 内存的想法(这很酷,因为我不必在硬件升级后更改设置)。这是我的(有点扩展内存设置):

export CATALINA_OPTS="-Xmx`cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.75 } '`k -Xms`cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.75 } '`k -XX:NewSize=`cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k -XX:MaxNewSize=`cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k -XX:PermSize=`cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k -XX:MaxPermSize=`cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k"

export CATALINA_OPTS="-Xmx `cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.75 } '`k -Xms `cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.75 } '`k -XX:NewSize= `cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k -XX:MaxNewSize= `cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k -XX:PermSize= `cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k -XX:MaxPermSize= `cat /proc/meminfo | grep MemTotal | awk '{ print $2*0.15 } '`k"

Put it to: "{tomcat}/bin/startup.sh" (e.g. "/usr/share/tomcat6/bin" for Ubuntu 10.10)

把它放到:“{tomcat}/bin/startup.sh”(例如 Ubuntu 10.10 的“/usr/share/tomcat6/bin”)

回答by martinusadyh

If you using Ubuntu 11.10 and apache-tomcat6 (installing from apt-get), you can put this configuration at /usr/share/tomcat6/bin/catalina.sh

如果您使用 Ubuntu 11.10 和 apache-tomcat6(从 apt-get 安装),您可以将此配置放在/usr/share/tomcat6/bin/catalina.sh

# -----------------------------------------------------------------------------

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1024m \
-Xmx1024m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m \
-XX:MaxPermSize=512m -XX:+DisableExplicitGC"

After that, you can check your configuration via ps -ef | grep tomcat :)

之后,您可以通过 ps -ef | 检查您的配置。grep tomcat :)