I Have set the heap size of tomcat 7 by adding boot script:
export CATALINA_OPTS="-Xms1024m -Xmx248m"
I change /etc/init.d/tomcat7 :
if [ -z "$JAVA_OPTS" ]; then
JAVA_OPTS="-Djava.awt.headless=true -Xmx2048M -Xms1024M"
fi
I Reboot the computer and restart the Tomcat:
service tomcat7 restart
And verify the $CATALINA_OPTS Works:
> echo $CATALINA_OPTS
-Xms1024m -Xmx2048m
But when I go to the tomcat manager, I note that the heap has not changed.
Free memory: 38.02 MB Total memory: 123.75 MB Max memory: 123.75 MB
Please, i need help about this.
Check the setenv.sh in tomcat/bin, according to manual this should be the right place to put those params.
Another option, it depend on your OS tomcat package, may be that config param are overrided in /etc/conf.d/tomcat/ or /etc/tomcat. Just check your init script and your catalina.sh to find where your settings are overrided.
Btw if you run a ps -ef | grep tomcat you should see the full command line with arguments: this may give you an idea of how init script build the command, and so you can investigate where params are set.
Have you tried creating a setenv.sh script in the $CATALINA_HOME/bin directory with your options in it?
I find that setting JAVA_OPTS="-Xmx2048m -Xms1024m" in there works pretty well.
Related
I have a problem with tomcat. Every once in a while Tomcat get's killed by a oom...
So i tested it with stressapptest to force a oom and then trying to restart tomcat.
I wrote a simple bash script, that will restart the tomcat service.
This is the Script:
#!/bin/bash
if [ "$(systemctl is-active tomcat9)" == "failed" ] || [ "$(systemctl is-active tomcat9)" == "inactive" ]; then
echo "Restarting tomcat!"
systemctl restart tomcat9.service
exit
else
exit
fi
And inside the setenv.sh i wrote this option.
-XX:OnOutOfMemoryError='/root/restart.sh'
This is how the setenv.sh script looks like:
#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -server -Xms1536m -Xmx1536m -XX:NewSize=1536m -XX:MaxNewSize=1536m -XX:OnOutOfMemoryError='pkill java;/root/restart.sh' -XX:+DisableExplicitGC -DecadiaConsoleLogLevel=off"
But I don't know, why the Option "XX:OnOutOfMemoryError" is not working...
Can someone help me with this problem?
Thanks in advance!
You are running Tomcat via systemd. That has two consequences:
Likely the startup command for Tomcat is coming from the systemd configuration instead of the script you edited. So you need to look at other files to make an effective change.
All you need to tell the JVM is to die on OutOfMemoryErrors. Then tell systemd to automatically restart the service. Your script is not required at all.
I'm strugling trying to set the Heap size insise a docker container, I'm aware of similar questions but non of them seams to work for me, I'm sure I'm missing something.
My docker file look like this:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=target/spring-boot-web.jar
WORKDIR /opt/app
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java" , "-XX:+UseContainerSupport" , "-XX:MaxRAMPercentage=50.0", "-XshowSettings" ,"-jar","app.jar"]
When I build and execute the image above with the following command:
docker run -m 2G -p 8080:8080 -t springtest
I get te following information due to -XshowSettings:
VM settings: Max. Heap Size (Estimated): 910.50M
After a few seconds my app start without a problem and then I decide to fetch information about the JVM inside the container with the command docker exec MyContainerId java -XshowSettings and I it prints :
VM settings: Max. Heap Size (Estimated): 455.50M
It's clear that the container start with 50% of Max Ram but after the app starts it reduces to the default (25%)
Maybe I have a wrong understanding of JVM and containers, can some one point me to the right direction.
Thank you.
I've been trying to build a maven project using JAVA 11 on CentOS 7.
When ran "mvn clean install" at the first time, I got an error
Error assembling JAR: Problem creating jar: Execution exception: Java
heap space
So, I've been try to search for solutions on the internet. I've found that a lot of people do like
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"
And it's working. Then, I tried this solution and build the project again. But it's not working. It still shows the same error. There's an info log shows "Final Memory: 218M/239M".
I tried export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m" a lot of time but it's not working.
After that, I've found that we can check the maxHeapSize by using command
java -XX:+PrintFlagsFinal -version | grep HeapSize
I got size_t MaxHeapSize = 260046848
It seems like the command MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m" doesn't work normally. Or I did something wrong. Please help.
I just need to do the
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"
by root user. I need to add sudo before using the command.
sudo export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=128m"
I am trying to increase heap size for wildfly in docker container. This is easily done by updating wildfly/bin/standalone.conf in a regular wildfly setup.
Our base docker image for wildfly has a default heapsize of 512 MB which is required to be 1GB in one of the web apps. One way to go is by simple text replace in the Docker file using sed command -
RUN sed -i -- 's/JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m/JAVA_OPTS="-Xms2048m -Xmx6144m -XX:MaxPermSize=256m/g' /path/standalone.conf
I wanted to know if there's another (cleaner) way to solve this?
When using docker-compose set environment variable as follows!
environment:
- JAVA_OPTS=-server -Xms512m -Xmx2048m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -XX:+UseAdaptiveSizePolicy -XX:MaxMetaspaceSize=1024m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true-Djava.net.preferIPv4Stack=true
do not use " (quotes)!
You can pass the value of the JAVA_OPTS environment variable in the command used to run the docker container:
docker run -it --env JAVA_OPTS="-server -Xms2048m -Xmx6144m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true" jboss/wildfly
Alternatively, you can extend the standard image by creating a Dockerfile containing:
FROM jboss/wildfly:latest
COPY standalone.conf $JBOSS_HOME/bin/
and placing your modified standalone.conf in the directory next to it.
Then you can build it:
docker build -t my/wildfly:latest .
and run it:
docker run my/wildfly
I suggest you to use JAVA_TOOL_OPTIONS rather than JAVA_OPTS .Because JVM directly understand JAVA_TOOL_OPTIONS.
I haven't tried it myself, but there is now (at least WF26) a variable JBOSS_JAVA_SIZING in standalone.conf, used as a subpart of JAVA_OPTS.
if [ "x$JBOSS_JAVA_SIZING" = "x" ]; then
JBOSS_JAVA_SIZING="-Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m"
fi
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="$JBOSS_JAVA_SIZING -Djava.net.preferIPv4Stack=true"
...
So you should be able to rewrite it through docker environment variables.
I want to set heap size under Linux OS in order to use it on java -jar command.
I have tried to add _JAVA_OPTIONS property under .bash_profile, but this property is ignored. I know I can run my jar with
java $_JAVA_OPTIONS -jar
command or create an alias like
alias java='java -Xms256m -Xmx512m'
I have found I can also export _JAVA_OPTIONS:
export _JAVA_OPTIONS="-Xms256m -Xmx512m"
But this property is not kept between sessions.
Any idea how can I set permanent heap size for java -jar command?