Discussion:
JAVA_OPTS vs CATALINA_OPTS
Арсений Зинченко
2014-01-27 14:21:37 UTC
Permalink
Hi.

I'm sorry for so kindly question - but needs experts advice...

We have a little dispute with my colleague about using this variables.

So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.

Needs to set memory for Tomcat other, than for all other Java-applications.

My proposal is set to System variables:

JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M"
CATALINA_OPTS "-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M"

But, as he asserts - this is not correct way:


- CATALINA_OPTS must NOT contain memory limits like "Xmx", "Xms" etc;
- Java Garbage collector will work differently because JAVA_OPTS have
another opts for memory then CATALINA_OPTS, so - this will worse Tomcat
performance;
- and so on

His suggestion is to set JAVA_OPTS with memory limits exactly to Tomcat
startup script (not as system variable at all).

So, my question is: is it correct to set memory limits for Tomcat via
CATALINA_OPTS variable? If in system also present JAVA_OPTS - will it
have influence
on to Tomcat's perfarmance?

Thanks.
Daniel Mikusa
2014-01-27 15:18:37 UTC
Permalink
Post by Арсений Зинченко
Hi.
I'm sorry for so kindly question - but needs experts advice...
We have a little dispute with my colleague about using this variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other Java-applications.
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M"
CATALINA_OPTS "-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M”
Don’t set these as system variables. You’d want to define them in setenv.bat if you’re running from the command prompt or with the Windows Service utility (either [1] or [2]), if you’re running as a service.
Post by Арсений Зинченко
- CATALINA_OPTS must NOT contain memory limits like "Xmx", "Xms" etc;
There are no restrictions to what you can set in CATALINA_OPTS. You could put your memory setting there if you wanted. Having said that, if you’re running as a Windows service then you wouldn’t. You'd set your heap memory settings through the service wrapper (either [1] or [2]).

If you’re running from the console (not likely) or on Linux / Unix then you’d set your heap settings in the setenv.sh|bat script. Again, you could put memory settings in CATALINA_OPTS or in JAVA_OPTS. Setting them in CATALINA_OPTS is generally a better choice though because settings in CATALINA_OPTS are only applied when Tomcat is started. If you set them in JAVA_OPTS then they’ll be applied when you start and stop the instance, something you probably don’t want for your heap settings.
Post by Арсений Зинченко
- Java Garbage collector will work differently because JAVA_OPTS have
another opts for memory then CATALINA_OPTS, so - this will worse Tomcat
performance;
I’m not sure I follow your logic here. The JVM is only going to accept one value for Xmx and Xms. Specifying the same options in JAVA_OPTS and CATALINA_OPTS would just be confusing.
Post by Арсений Зинченко
- and so on
His suggestion is to set JAVA_OPTS with memory limits exactly to Tomcat
startup script (not as system variable at all).
Again, don’t set system variables for these. There’s no reason to set them system wide.
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for Tomcat via
CATALINA_OPTS variable?
Generally, but it depends on how you are starting Tomcat. Since you’re on Windows, you’re probably running as a service and that’s going to be a bit different. See above comments.
Post by Арсений Зинченко
If in system also present JAVA_OPTS - will it have influence on to Tomcat's performance?
I think I answered this above. If it’s not clear, let me know.
Post by Арсений Зинченко
Thanks.
Dan

[1] - http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Command_line_parameters
[2] - http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Tomcat7w_monitor_application
Арсений Зинченко
2014-01-27 15:36:36 UTC
Permalink
Hi, Dan. Thanks for replay.
Post by Daniel Mikusa
he JVM is only going to accept one value for Xmx and Xms. Specifying the
same options in JAVA_OPTS and CATALINA_OPTS would just be confusing.

As I says before - we have few Java-application on same machine. So - for
them needs to set Xmx 1G, but for Tomcat - 4G.
Post by Daniel Mikusa
Don’t set these as system variables. You’d want to define them in
setenv.bat
Post by Daniel Mikusa
Again, don’t set system variables for these. There’s no reason to set
them system wide.

Same reason - few Java-applications wich all need same Java_opts (exclude
Tomcat).
Post by Daniel Mikusa
Since you’re on Windows, you’re probably running as a service and that’s
going to be a bit different

No, Tomcat started via command line (rather - from .bat script wich call
%catalina_home%/bin/startup.bat).
Post by Daniel Mikusa
Post by Арсений Зинченко
Hi.
I'm sorry for so kindly question - but needs experts advice...
We have a little dispute with my colleague about using this variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other
Java-applications.
Post by Арсений Зинченко
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M"
CATALINA_OPTS "-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M”
Don’t set these as system variables. You’d want to define them in
setenv.bat if you’re running from the command prompt or with the Windows
Service utility (either [1] or [2]), if you’re running as a service.
Post by Арсений Зинченко
- CATALINA_OPTS must NOT contain memory limits like "Xmx", "Xms" etc;
There are no restrictions to what you can set in CATALINA_OPTS. You could
put your memory setting there if you wanted. Having said that, if you’re
running as a Windows service then you wouldn’t. You'd set your heap memory
settings through the service wrapper (either [1] or [2]).
If you’re running from the console (not likely) or on Linux / Unix then
you’d set your heap settings in the setenv.sh|bat script. Again, you could
put memory settings in CATALINA_OPTS or in JAVA_OPTS. Setting them in
CATALINA_OPTS is generally a better choice though because settings in
CATALINA_OPTS are only applied when Tomcat is started. If you set them in
JAVA_OPTS then they’ll be applied when you start and stop the instance,
something you probably don’t want for your heap settings.
Post by Арсений Зинченко
- Java Garbage collector will work differently because JAVA_OPTS have
another opts for memory then CATALINA_OPTS, so - this will worse Tomcat
performance;
I’m not sure I follow your logic here. The JVM is only going to accept
one value for Xmx and Xms. Specifying the same options in JAVA_OPTS and
CATALINA_OPTS would just be confusing.
Post by Арсений Зинченко
- and so on
His suggestion is to set JAVA_OPTS with memory limits exactly to Tomcat
startup script (not as system variable at all).
Again, don’t set system variables for these. There’s no reason to set
them system wide.
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for Tomcat via
CATALINA_OPTS variable?
Generally, but it depends on how you are starting Tomcat. Since you’re on
Windows, you’re probably running as a service and that’s going to be a bit
different. See above comments.
Post by Арсений Зинченко
If in system also present JAVA_OPTS - will it have influence on to
Tomcat's performance?
I think I answered this above. If it’s not clear, let me know.
Post by Арсений Зинченко
Thanks.
Dan
[1] -
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Command_line_parameters
[2] -
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Tomcat7w_monitor_application
---------------------------------------------------------------------
Daniel Mikusa
2014-01-27 15:49:15 UTC
Permalink
Post by Арсений Зинченко
Hi, Dan. Thanks for replay.
Post by Daniel Mikusa
he JVM is only going to accept one value for Xmx and Xms. Specifying the
same options in JAVA_OPTS and CATALINA_OPTS would just be confusing.
As I says before - we have few Java-application on same machine. So - for
them needs to set Xmx 1G, but for Tomcat - 4G.
I’m not sure how this is relevant. I understand that you have multiple applications running, but it doesn’t matter. Each application you run will have it’s own JVM with it’s own Xmx and Xms settings.

If you set Xmx or Xms twice for one JVM, which is essentially what you’re doing when you put them in both JAVA_OPTS and CATALINA_OPTS that would just be confusing. It’s won’t directly cause a problem, the JVM will pick one and ignore the others, but it’s confusing to someone looking at your configuration.
Post by Арсений Зинченко
Post by Daniel Mikusa
Don’t set these as system variables. You’d want to define them in
setenv.bat
Post by Daniel Mikusa
Again, don’t set system variables for these. There’s no reason to set
them system wide.
Same reason - few Java-applications wich all need same Java_opts (exclude
Tomcat).
This is just my opinion. There’s nothing to prevent you from setting these values system wide. I would suggest that you don’t though. It’s just going to be confusing. Set the values in the configuration for each Java application / Tomcat instance. Then it’s immediately clear which value is being used for which application.
Post by Арсений Зинченко
Post by Daniel Mikusa
Since you’re on Windows, you’re probably running as a service and that’s
going to be a bit different
No, Tomcat started via command line (rather - from .bat script wich call
%catalina_home%/bin/startup.bat).
Ok then. You’ll want to create the file bin/setenv.bat for each of your Tomcat instances. In that file, you can set JAVA_OPTS and / or CATALINA_OPTS. As I mentioned before, I’d suggest putting your heap options in CATALINA_OPTS.

Dan
Post by Арсений Зинченко
Post by Daniel Mikusa
Post by Арсений Зинченко
Hi.
I'm sorry for so kindly question - but needs experts advice...
We have a little dispute with my colleague about using this variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other
Java-applications.
Post by Арсений Зинченко
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M"
CATALINA_OPTS "-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M”
Don’t set these as system variables. You’d want to define them in
setenv.bat if you’re running from the command prompt or with the Windows
Service utility (either [1] or [2]), if you’re running as a service.
Post by Арсений Зинченко
- CATALINA_OPTS must NOT contain memory limits like "Xmx", "Xms" etc;
There are no restrictions to what you can set in CATALINA_OPTS. You could
put your memory setting there if you wanted. Having said that, if you’re
running as a Windows service then you wouldn’t. You'd set your heap memory
settings through the service wrapper (either [1] or [2]).
If you’re running from the console (not likely) or on Linux / Unix then
you’d set your heap settings in the setenv.sh|bat script. Again, you could
put memory settings in CATALINA_OPTS or in JAVA_OPTS. Setting them in
CATALINA_OPTS is generally a better choice though because settings in
CATALINA_OPTS are only applied when Tomcat is started. If you set them in
JAVA_OPTS then they’ll be applied when you start and stop the instance,
something you probably don’t want for your heap settings.
Post by Арсений Зинченко
- Java Garbage collector will work differently because JAVA_OPTS have
another opts for memory then CATALINA_OPTS, so - this will worse Tomcat
performance;
I’m not sure I follow your logic here. The JVM is only going to accept
one value for Xmx and Xms. Specifying the same options in JAVA_OPTS and
CATALINA_OPTS would just be confusing.
Post by Арсений Зинченко
- and so on
His suggestion is to set JAVA_OPTS with memory limits exactly to Tomcat
startup script (not as system variable at all).
Again, don’t set system variables for these. There’s no reason to set
them system wide.
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for Tomcat via
CATALINA_OPTS variable?
Generally, but it depends on how you are starting Tomcat. Since you’re on
Windows, you’re probably running as a service and that’s going to be a bit
different. See above comments.
Post by Арсений Зинченко
If in system also present JAVA_OPTS - will it have influence on to
Tomcat's performance?
I think I answered this above. If it’s not clear, let me know.
Post by Арсений Зинченко
Thanks.
Dan
[1] -
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Command_line_parameters
[2] -
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Tomcat7w_monitor_application
---------------------------------------------------------------------
Christopher Schultz
2014-01-27 15:46:33 UTC
Permalink
Арсений,
Post by Арсений Зинченко
We have a little dispute with my colleague about using this
variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other
Java-applications.
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M" CATALINA_OPTS
"-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M"
- CATALINA_OPTS must NOT contain memory limits like "Xmx", "Xms"
etc; - Java Garbage collector will work differently because
JAVA_OPTS have another opts for memory then CATALINA_OPTS, so -
this will worse Tomcat performance; - and so on
Tomcat runs Java roughly in this way:

$JAVA_HOME/bin/java $JAVA_OPTS $CATALINA_OPTS \
org.apache.catalina.startup.Bootstrap

If you have these options configured using both environment variables,
then CATALINA_OPTS (the later one) will win because that's how the JVM
parses arguments: the last one on the command-line wins. So, it's
perfectly safe to do what you have described above.

On the other hand, note that since JAVA_OPTS specifies 0.5GiB of heap
space for when you are /not/ launching Tomcat, then running
"bin\shutdown.bat" will pre-allocate 0.5GiB of heap space just to send
the "shutdown" command to a running Tomcat instance, and then
terminate. It's kind of a waste.

I totally agree with Dan's comments about how using "system
variables": just use bin/setenv.bat and keep everything locally.
Post by Арсений Зинченко
His suggestion is to set JAVA_OPTS with memory limits exactly to
Tomcat startup script (not as system variable at all).
+1
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for Tomcat
via CATALINA_OPTS variable? If in system also present JAVA_OPTS -
will it have influence on to Tomcat's perfarmance?
See above.

- -chris
Арсений Зинченко
2014-01-27 15:58:51 UTC
Permalink
Thanks, Christopher.

OK, what about next:

Set JAVA_OPTS as system variable (for all other applications); and create
setenv.bat in /bin/ directory with CATALINA_OPTS whith Xmx/Xms for Tomcat?

Will it be more correctly than set CATALINA_OPTS as System variable? Or -
by the way, in setevn.bat must be used JAVA_OPTS too?
<https://plus.google.com/u/0/113253806461878935497?prsrc=4>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
АрсеМОй,
Post by Арсений Зинченко
We have a little dispute with my colleague about using this
variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other
Java-applications.
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M" CATALINA_OPTS
"-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M"
- CATALINA_OPTS must NOT contain memory limits like "Xmx", "Xms"
etc; - Java Garbage collector will work differently because
JAVA_OPTS have another opts for memory then CATALINA_OPTS, so -
this will worse Tomcat performance; - and so on
$JAVA_HOME/bin/java $JAVA_OPTS $CATALINA_OPTS \
org.apache.catalina.startup.Bootstrap
If you have these options configured using both environment variables,
then CATALINA_OPTS (the later one) will win because that's how the JVM
parses arguments: the last one on the command-line wins. So, it's
perfectly safe to do what you have described above.
On the other hand, note that since JAVA_OPTS specifies 0.5GiB of heap
space for when you are /not/ launching Tomcat, then running
"bin\shutdown.bat" will pre-allocate 0.5GiB of heap space just to send
the "shutdown" command to a running Tomcat instance, and then
terminate. It's kind of a waste.
I totally agree with Dan's comments about how using "system
variables": just use bin/setenv.bat and keep everything locally.
Post by Арсений Зинченко
His suggestion is to set JAVA_OPTS with memory limits exactly to
Tomcat startup script (not as system variable at all).
+1
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for Tomcat
via CATALINA_OPTS variable? If in system also present JAVA_OPTS -
will it have influence on to Tomcat's perfarmance?
See above.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBCAAGBQJS5n9ZAAoJEBzwKT+lPKRYXJAQAIoI/6t21bVVHXGH+KZDVOvy
e+YsyWJRdRtFCDCIc+Y3YtY+8q+uDQRyqBQyJLNgdmkNEdbrGf1a/n74Mg4bNilA
GxOi7D75tiMni3T4rz4nUc5nyTnCOBNYuitrpjZMWfvd/ajHdSAEWuivGa87A/oL
C7Y4Bu6KB+2dwNifOwYWPzRq9yl+25G7SBo+URH8HMTHVEBVrDYflTudX0q9D4XI
XK5CNTiOQvfKgu/3HCjcZSq75LspTIC0Kw9P+GRX9PoJJCvAlF3TQgLghJ9S3YOT
l0n3A5UE2cZycUv3NEJrdoerWbYsbDexq47eeQ2CMVoHeTBBFDAZK4uR7EneFsea
89WI39tNT0+jrScFQ7eKCv72yxUb05gunOnWMHe23vx10BXVT2at8jvgSlJs2SSy
co2B9PrNqwZRZtzZCS38A5DmXts9KlEFnc7bd5Fu4ME4jEs/sODd8+CXc9Fpsmee
68v2w0avaAKjngvirhMq+X12t+NZSIK5TTsz9XA36AGEnDEAgWZUNQ/6GSG2oA2F
tiQzIKkl/MTl8ZEYbI0ZydQgsdhbdvcQ+51dRsqlk1wj+Rlp9d3rOnUgtHn0w4xO
wUid16DjQyCKiqBw+2ATpf6bK1m/cCKQxbkBmfMUXa4wR9Hok3M0fCwsJrHOt74T
1k9HFMAfUZSNelfdCvsC
=M2Q+
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
Christopher Schultz
2014-01-27 16:01:22 UTC
Permalink
Арсений,
Post by Арсений Зинченко
Thanks, Christopher.
Set JAVA_OPTS as system variable (for all other applications); and
create setenv.bat in /bin/ directory with CATALINA_OPTS whith
Xmx/Xms for Tomcat?
Will it be more correctly than set CATALINA_OPTS as System
variable? Or - by the way, in setevn.bat must be used JAVA_OPTS
too? <https://plus.google.com/u/0/113253806461878935497?prsrc=4>
Арсений,
Post by Арсений Зинченко
We have a little dispute with my colleague about using this
variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other
Java-applications.
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M"
CATALINA_OPTS "-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M"
- CATALINA_OPTS must NOT contain memory limits like "Xmx",
"Xms" etc; - Java Garbage collector will work differently
because JAVA_OPTS have another opts for memory then
CATALINA_OPTS, so - this will worse Tomcat performance; - and
so on
$JAVA_HOME/bin/java $JAVA_OPTS $CATALINA_OPTS \
org.apache.catalina.startup.Bootstrap
If you have these options configured using both environment
variables, then CATALINA_OPTS (the later one) will win because
that's how the JVM parses arguments: the last one on the
command-line wins. So, it's perfectly safe to do what you have
described above.
On the other hand, note that since JAVA_OPTS specifies 0.5GiB of
heap space for when you are /not/ launching Tomcat, then running
"bin\shutdown.bat" will pre-allocate 0.5GiB of heap space just to
send the "shutdown" command to a running Tomcat instance, and then
terminate. It's kind of a waste.
I totally agree with Dan's comments about how using "system
variables": just use bin/setenv.bat and keep everything locally.
Post by Арсений Зинченко
His suggestion is to set JAVA_OPTS with memory limits exactly
to Tomcat startup script (not as system variable at all).
+1
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for
Tomcat via CATALINA_OPTS variable? If in system also present
JAVA_OPTS - will it have influence on to Tomcat's
perfarmance?
See above.
-chris
I would always recommend that you use bin/setenv.sh (or
bin\setenv.bat) because you can then set the value differently for
each Tomcat instance that you have. This becomes an issue if you have
many different Tomcat instances, which I tend to do.

- -chris
Арсений Зинченко
2014-01-27 16:24:22 UTC
Permalink
OK, thanks - I'll do it from now (really - never used this file before,
just now found reference to it in catalina.bat) . But - last question,
please: in setenv.bat - must be used CATALINA_OPTS or JAVA_OPTS?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
АрсеМОй,
Post by Арсений Зинченко
Thanks, Christopher.
Set JAVA_OPTS as system variable (for all other applications); and
create setenv.bat in /bin/ directory with CATALINA_OPTS whith
Xmx/Xms for Tomcat?
Will it be more correctly than set CATALINA_OPTS as System
variable? Or - by the way, in setevn.bat must be used JAVA_OPTS
too? <https://plus.google.com/u/0/113253806461878935497?prsrc=4>
АрсеМОй,
Post by Арсений Зинченко
We have a little dispute with my colleague about using this variables.
So: have Windows-box machine. On it - runing few different
Java-application, including Tomcat.
Needs to set memory for Tomcat other, than for all other
Java-applications.
JAVA_OPTS "-Xmx1024M -Xms512M -XX:MaxPermSize512M"
CATALINA_OPTS "-Xmx4096M -Xms2048M -XX:MaxPermSize=1024M"
- CATALINA_OPTS must NOT contain memory limits like "Xmx",
"Xms" etc; - Java Garbage collector will work differently
because JAVA_OPTS have another opts for memory then
CATALINA_OPTS, so - this will worse Tomcat performance; - and
so on
$JAVA_HOME/bin/java $JAVA_OPTS $CATALINA_OPTS \
org.apache.catalina.startup.Bootstrap
If you have these options configured using both environment
variables, then CATALINA_OPTS (the later one) will win because
that's how the JVM parses arguments: the last one on the
command-line wins. So, it's perfectly safe to do what you have
described above.
On the other hand, note that since JAVA_OPTS specifies 0.5GiB of
heap space for when you are /not/ launching Tomcat, then running
"bin\shutdown.bat" will pre-allocate 0.5GiB of heap space just to
send the "shutdown" command to a running Tomcat instance, and then
terminate. It's kind of a waste.
I totally agree with Dan's comments about how using "system
variables": just use bin/setenv.bat and keep everything locally.
Post by Арсений Зинченко
His suggestion is to set JAVA_OPTS with memory limits exactly
to Tomcat startup script (not as system variable at all).
+1
Post by Арсений Зинченко
So, my question is: is it correct to set memory limits for
Tomcat via CATALINA_OPTS variable? If in system also present
JAVA_OPTS - will it have influence on to Tomcat's
perfarmance?
See above.
-chris
I would always recommend that you use bin/setenv.sh (or
bin\setenv.bat) because you can then set the value differently for
each Tomcat instance that you have. This becomes an issue if you have
many different Tomcat instances, which I tend to do.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBCAAGBQJS5oLSAAoJEBzwKT+lPKRY8BMP/06E75p4L2fx75ekKgyVFuVX
vM/tBcP3ulHlEVHAzcTl+gNui4Px0hjRRdKBxU9in/gSRSsD2xkJJa5eXF0EvSn1
e9BNiVY78JZITSu1wBar0YmIf11EJEtGhhtj/fSkJUxIMhp9YYpM1s9CrxckkIef
WFQZOnLVdWUq2xxkPiY8AbK7h5zDgo+riBd4HcSC6ymPT0oYCldGIZki7nZ8lxMb
G3i52aTCiuaOlKYBhdKBsfDdkFJvqF+zZEXdsw+FKP+mKZvpEt5Fn1cWSTX7FXxS
mWApl7J8FZW+zwX734qUw3ThLIbY2RCwT78VPkPcHK9rbWcKbI4UQ1WIGZeL5U+K
IqX1MOIJ+dVCJ7rgvtjYWYlfDoovYqfJ6vCoPU5I3Xh0CMzGaKMZY/QZ+gFUXtdu
0ym/DQJB13cgjWbOi4YFeL8jNRjgui2UkdtThOzfSzL4eY3C+L5Ca0bb/ExReWTb
X05q1RVeTB6rTScTYiPCNMKfZ7S2JnXcoXgEeHpKoGo8EPClKLGlLRmFplk/U4Do
ZdCLLjCavrkEVg6pUEf7UZDJ/qH/VDC0nyNnqJJQHRhjUBh/bMR1yjrzNOnkLOeV
x0BMEHK8ND76EZ0L5+bwZlAQxvCqjQ/vH1IBmrUsjS60rgMyocJB//UDIZOEOAiq
9MXTB+fLRv2ziADmiWJ1
=QPaR
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
Caldarale, Charles R
2014-01-27 17:07:23 UTC
Permalink
Subject: Re: JAVA_OPTS vs CATALINA_OPTS
in setenv.bat - must be used CATALINA_OPTS or JAVA_OPTS?
Dan already explained this:

Again, you could put memory settings in CATALINA_OPTS or in JAVA_OPTS.
Setting them in CATALINA_OPTS is generally a better choice though because
settings in CATALINA_OPTS are only applied when Tomcat is started. If
you set them in JAVA_OPTS then they'll be applied when you start and stop
the instance, something you probably don't want for your heap settings.

- Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
André Warnier
2014-01-28 08:47:26 UTC
Permalink
Post by Арсений Зинченко
OK, thanks - I'll do it from now (really - never used this file before,
just now found reference to it in catalina.bat) . But - last question,
please: in setenv.bat - must be used CATALINA_OPTS or JAVA_OPTS?
Ok, let us be really clear here.

1) The command to *stop* Tomcat starts *another* instance of Java JVM (and Tomcat), *just*
to send a stop signal to the running Tomcat. And after that, this second instance of Java
and Tomcat exits.

2) Options given in JAVA_OPTS are used in *both* the command to start and to stop Tomcat.
Options given in CATALINA_OPTS are used *only* in the command that starts Tomcat, and not
in the command that stops Tomcat.
In other words :
- startup.(bat|sh) : java %JAVA_OPTS% %CATALINA_OPTS% tomcat-stuff
- shutdown.(bat|sh) : java %JAVA_OPTS% tomcat-stuff

That is just the way that these command files are written.

3) So,
- if you use JAVA_OPTS to indicate a Heap of 4 GB, then this Heap of 4 GB will be allocated :
- for the JVM instance that starts and runs Tomcat (which is what you want)
- but *also* for the JVM instance that stops Tomcat (which you probably do not want,
just to send a stop signal)(because then, just for a short moment, you need 4 + 4 = 8 GB
of Heap)

- if you use CATALINA_OPTS to indicate a Heap of 4 GB, then this Heap will be allocated
- *only* for the JVM instance which starts and runs Tomcat
- and *not* for JVM instance that stops Tomcat (that one will use a minimal Heap, so the
total would be only 4 + 0.1 GB)

4) and if you make either one of the above be a general "system variable", then they will
be used by *any* Java JVM that you start on that system. This is probably not what you
want either, so don't do that.
Арсений Зинченко
2014-01-28 09:00:42 UTC
Permalink
A lot of thanks, Neven! This is perfect explanation - considering my
English :-)

About point 4 - this is main goal: as we have few Java-applications running
in this very system - they must use "global" memory options, thats why I
suggested set System variable JAVA_OPTS. But namely Tomcat - must use
another memory perametrs.

So, if I correctly understood - for me better solution will be:

1) set CATALINA_OPTS with Xmx4G etc - in /bin/setenv.bat;
2) set JAVA_OPTS with Xmx1G etc - as system variable.

Yep?
Post by André Warnier
Post by Арсений Зинченко
OK, thanks - I'll do it from now (really - never used this file before,
just now found reference to it in catalina.bat) . But - last question,
please: in setenv.bat - must be used CATALINA_OPTS or JAVA_OPTS?
Ok, let us be really clear here.
1) The command to *stop* Tomcat starts *another* instance of Java JVM (and
Tomcat), *just* to send a stop signal to the running Tomcat. And after
that, this second instance of Java and Tomcat exits.
2) Options given in JAVA_OPTS are used in *both* the command to start and to stop Tomcat.
Options given in CATALINA_OPTS are used *only* in the command that starts
Tomcat, and not in the command that stops Tomcat.
- startup.(bat|sh) : java %JAVA_OPTS% %CATALINA_OPTS% tomcat-stuff
- shutdown.(bat|sh) : java %JAVA_OPTS% tomcat-stuff
That is just the way that these command files are written.
3) So,
- if you use JAVA_OPTS to indicate a Heap of 4 GB, then this Heap of 4 GB
- for the JVM instance that starts and runs Tomcat (which is what you want)
- but *also* for the JVM instance that stops Tomcat (which you probably
do not want, just to send a stop signal)(because then, just for a short
moment, you need 4 + 4 = 8 GB of Heap)
- if you use CATALINA_OPTS to indicate a Heap of 4 GB, then this Heap will be allocated
- *only* for the JVM instance which starts and runs Tomcat
- and *not* for JVM instance that stops Tomcat (that one will use a
minimal Heap, so the total would be only 4 + 0.1 GB)
4) and if you make either one of the above be a general "system variable",
then they will be used by *any* Java JVM that you start on that system.
This is probably not what you want either, so don't do that.
---------------------------------------------------------------------
Neven Cvetkovic
2014-01-28 13:16:52 UTC
Permalink
Post by Арсений Зинченко
About point 4 - this is main goal: as we have few Java-applications running
in this very system - they must use "global" memory options, thats why I
suggested set System variable JAVA_OPTS. But namely Tomcat - must use
another memory perametrs.
Arsenije,

That's one way of doing it, yes. My personal preference is to keep
system-wide settings empty, and then size each Java process separately (in
their corresponding startup script). Having said that, it really depends on
type of applications you are running on you system. Are they same type of
applications, or are they significantly different? If different, I probably
want to size them differently, and customize each one of them. Yes, it is
easy to set default values in the JAVA_OPTS globally, but that's rarely
what I want for my applications.

Also, others pointed out - it is confusing to see both JAVA_OPTS and
CATALINA_OPTS both setting up -Xmx and -Xms values. Ultimately, everything
boils down to a single line:

java.exe %JAVA_OPTS% %CATALINA_OPTS% ...
java.exe -Xmx1G -Xms512M -Xmx4G -Xms2G ...

Yes, the later will override former parameter, but I wouldn't count on it :)

Think if you need to add another Java process that requires 4G, how would
you set the size of memory of that process?

So, unless all Java applications on that box (you said you had only few) -
are of similar type and require same sizing, I wouldn't use JAVA_OPTS
system-wide setting.
Post by Арсений Зинченко
1) set CATALINA_OPTS with Xmx4G etc - in /bin/setenv.bat;
2) set JAVA_OPTS with Xmx1G etc - as system variable.
Yep?
It is TOMCAT_HOME/bin/setenv.bat (wherever you installed Tomcat).

Yes, that is one possible solution, if all your Java apps need to be sized
the same.

I prefer sizing each Java application separately in a script that starts it.

Hope that helps!
n.
Christopher Schultz
2014-01-28 14:55:00 UTC
Permalink
Neven,
On Tue, Jan 28, 2014 at 4:00 AM, Арсений Зинченко
Post by Арсений Зинченко
About point 4 - this is main goal: as we have few
Java-applications running in this very system - they must use
"global" memory options, thats why I suggested set System
variable JAVA_OPTS. But namely Tomcat - must use another memory
perametrs.
Arsenije,
That's one way of doing it, yes. My personal preference is to
keep system-wide settings empty, and then size each Java process
separately (in their corresponding startup script). Having said
that, it really depends on type of applications you are running on
you system. Are they same type of applications, or are they
significantly different? If different, I probably want to size them
differently, and customize each one of them. Yes, it is easy to set
default values in the JAVA_OPTS globally, but that's rarely what I
want for my applications.
+1, in general

We have a couple of large-memory servers, and the default heap
ergonomics of JVMs have varied wildly. By default, you'll probably get
more memory than you actually need, especially for small Java
processes. By simply setting JAVA_OPTS to have a small initial and
maximum heap size (usually something like 32MiB), we were able to
restrict any process that hadn't explicitly set its memory
requirements just so things didn't get out of hand.

When you give Java a large heap, the JVM assumes that you intend to
use it and isn't stingy about allowing it to fill-up.
Also, others pointed out - it is confusing to see both JAVA_OPTS
and CATALINA_OPTS both setting up -Xmx and -Xms values. Ultimately,
java.exe %JAVA_OPTS% %CATALINA_OPTS% ... java.exe -Xmx1G -Xms512M
-Xmx4G -Xms2G ...
Yes, the later will override former parameter, but I wouldn't count on it :)
I can't find any documentation specifying this behavior, but it's
probably reasonable to count on this behavior. Tomcat certainly does ;)
Think if you need to add another Java process that requires 4G, how
would you set the size of memory of that process?
So, unless all Java applications on that box (you said you had only
few) - are of similar type and require same sizing, I wouldn't use
JAVA_OPTS system-wide setting.
+1

That's what bin/setenv.sh and bin\setenv.bat are for.

- -chris
Арсений Зинченко
2014-01-28 14:56:08 UTC
Permalink
Thanks for your replay, Neven.
Eventually - I decided to heed advices and remove JAVA_OPTS at all. So -
now using only CATALINA_OPTS in /bin/setenv.bat.
Post by Neven Cvetkovic
Post by Арсений Зинченко
About point 4 - this is main goal: as we have few Java-applications running
in this very system - they must use "global" memory options, thats why I
suggested set System variable JAVA_OPTS. But namely Tomcat - must use
another memory perametrs.
Arsenije,
That's one way of doing it, yes. My personal preference is to keep
system-wide settings empty, and then size each Java process separately (in
their corresponding startup script). Having said that, it really depends on
type of applications you are running on you system. Are they same type of
applications, or are they significantly different? If different, I probably
want to size them differently, and customize each one of them. Yes, it is
easy to set default values in the JAVA_OPTS globally, but that's rarely
what I want for my applications.
Also, others pointed out - it is confusing to see both JAVA_OPTS and
CATALINA_OPTS both setting up -Xmx and -Xms values. Ultimately, everything
java.exe %JAVA_OPTS% %CATALINA_OPTS% ...
java.exe -Xmx1G -Xms512M -Xmx4G -Xms2G ...
Yes, the later will override former parameter, but I wouldn't count on it :)
Think if you need to add another Java process that requires 4G, how would
you set the size of memory of that process?
So, unless all Java applications on that box (you said you had only few) -
are of similar type and require same sizing, I wouldn't use JAVA_OPTS
system-wide setting.
Post by Арсений Зинченко
1) set CATALINA_OPTS with Xmx4G etc - in /bin/setenv.bat;
2) set JAVA_OPTS with Xmx1G etc - as system variable.
Yep?
It is TOMCAT_HOME/bin/setenv.bat (wherever you installed Tomcat).
Yes, that is one possible solution, if all your Java apps need to be sized
the same.
I prefer sizing each Java application separately in a script that starts it.
Hope that helps!
n.
Neven Cvetkovic
2014-01-27 22:17:14 UTC
Permalink
Post by Арсений Зинченко
Set JAVA_OPTS as system variable (for all other applications); and create
setenv.bat in /bin/ directory with CATALINA_OPTS whith Xmx/Xms for Tomcat?
Will it be more correctly than set CATALINA_OPTS as System variable? Or -
by the way, in setevn.bat must be used JAVA_OPTS too?
Others already pointed out, here are few more details:

- use bin/setenv.bat(.sh) for customizing tomcat options (CATALINA_OPTS
preferably, since JAVA_OPTS will be used for both startup and shutdown of
tomcat, CATALINA_OPTS is used only for startup of tomcat)
- setting up JAVA_OPTS as a system-wide setting will apply to ALL Java
programs running on that box, and you would only want to set things in
JAVA_OPTS for settings that you truly want to be set for EVERY Java program
(e.g. -Djava.net.preferIPv4Stack=true)
- the best would be that each Java application manages its own Xmx and Xms
settings from their startup scripts (those other Java apps you were
referring to) - so you are not forcing down someone's throat what JAVA_OPTS
they would use ...

Good luck!
n.
Loading...