How to set permanent memory settings for java? - java

I use jre-7u40-linux-x64 on SL6.4.
Server with more than 30Gb of RAM. User's memory limits sets to several gigabytes, but
command java returns error.
"Not enough memory heap..."
Under root it's ok and -XshowSettings:vm shows that memory size is automaticaly estimated.
Under user with options -Xmx256m it's ok also.
So is it possible to set the property(-Xmx256m) permanently?
I tried environtment variables (JAVA_OPTS,JAVA_OPTIONS) and jvm.cfg. With no results.
Any advices and keywords?
Thank you.

JAVA_OPTS / JAVA_OPTIONS do not help: Running java with JAVA_OPTS env variable
However, if you want such feature, you can create a simple shell script.
A script called java in a location that is in user's PATH environment variable before the actual java binary should do the trick:
#!/bin/bash
/usr/local/java/oracle/bin/java "$JAVA_OPTS" "$#"

Related

JMeter Dashboard Generation Java Heap Space

I've been able to create dashboards for small amounts of log data (3mb) with JMeter. However, when trying to create dashboards with large amounts of data (35mb), jmeter will throw a java.lang.OutOfMemoryError: Java Heap Space.
So far I've tried to create an environment variable called JVM_ARGS=-Xms1024m -Xmx10240m but I still do not have enough space.
Is there anything else I can try to create these dashboards? Or is there a way to reduce the number of entries that get written to the log file?
Thank you!
There are 2 possibilities :
Option 1 : your JVM options are not taken into account. Show the first lines or all content of jmeter.log
Option 2 : you have added some dynamic parameter to your http requests that has created a lot of different (name) SampleResult
Edit 8 october 2018:
Root cause was point Option 2
Make sure you've really created the environment variable and it has the anticipated value, double check this by running the following command in the terminal window where you will be launching JMeter from:
echo %JVM_ARGS% for Windows
echo $JVM_ARGS for Linux/Unix/MacOS
You should see your increased JVM heap settings
Make sure to use either jmeter.bat for Windows or jmeter.sh for other operating systems wrapper script
Make sure to use 64-bit version of JRE as 32-bit will not be able to allocate more than 3G heap
Make sure you can execute java command with your 10G heap
java -Xms1024m -Xmx10240m -version
you should see your Java version
Try running ApacheJMeter.jar executable directly:
java -Xms1024m -Xmx10240m -jar ApacheJMeter.jar -g result.jtl -o destination_folder
If nothing helps be aware that you can generate tables/charts using JMeterPluginsCMD Command Line Tool (it is not a part of standard JMeter installation, can be installed using JMeter Plugins Manager)

Increase heap size in java for weka

I'm trying to increase the heap size in java for weka which keeps crashing. I used the suggested line:
> java -Xmx500m -classpath
but I get the following error:
-classpath requires class path specification
I'm not sure what this means. Any suggestions?
What I found was the actual issue was in the file 'RunWeka.ini' in '\Program Files (x86)\Weka-3-6'. I opened it with notepad and in the middle of the file there is a line 'maxheap = 512m'.
I changed the line to read 'maxheap=2000m', saved the file and reloaded weka and this fixed my problems.
I'm not sure if this is the correct way to do it or not but it worked for me.
Run this command in your terminal:
java -Xmx1024m -jar weka.jar
Omit the -classpath option. Use just -Xmx500m option.
So, instead of just:
java weka.core.Instances data/soybean.arff
you do:
java -Xmx500m weka.core.Instances data/soybean.arff
If you run weka via some script (RunWeka.bat for example), then you need to modify that script (with some text editor like notepad).
If you're using Weka 3.8.1 on Windows you can save yourself a lot of trouble by editing the javaOpts parameter. The parameter maxheap isn't used anymore, so you can set javaOpts like this in RunWeka.ini file:
javaOpts= -Xmx1040m
Where 1040m is the amount of memory you want to allocate.
Mind that the file is case sensitive.
There are a lot of ways to set this up, but this is the faster way to get Weka runing on a Windows environment at this version.
Edit: If you want Weka to use more than 1gb on windows, you need to have JDK installed. Regular JRE wont do it.
The official Weka answer (for all operating systems and Weka versions) can be found on http://weka.wikispaces.com/OutOfMemoryException.
In case you are using a recent Weka version on Windows, the answer is:
Modify the maxheap parameter in the RunWeka.ini file.
On Ubuntu i had the same problem
but i solve it by increasing the amount of memory to use for the Java Virtual Machine
run this : weka -m 1024m
You need to specify a classpath after -classpath, similar to the PATH env variable you need to specify the path where Java can find the classes.
The -Xmx500m setting looks fine, except that I would suggest to use 512m.
For Mac OS, you have to edit a configuration file in order to increase the heap size of the Weka UI application.
I am repeating what I wrote in: Is there a workaround to solve "Java heap space" memory error when the max heap value has been already specified?
Quit out of Weka if it is running.
cd into /Applications/weka-XXX.app/Contents , or wherever your weka executable was installed. There will be a file called Info.plist there. It is an XML text file. I suggest you save a copy of it to another location, as you'll need to edit it in the next step.
Open the Info.plist (XML) file in your favorite text editor and look for a block that says "VMOptions". There should be a value that says "-Xmx256M" or something similar that specifies the maximum heap size. You should change that value to something bigger, such as "-Xmx1024M".
Start Weka.
I am running Weka 3.6 in windows. This is what i did.
Go to the Weka installation directory and you will find a RunWeka.bat file. Open this file in a text editor and add -Xmx argument in the java command line.
for instance this sets to 4GB memory,
%_java% -Xmx4096m -classpath . RunWeka -i .\RunWeka.ini -w .\weka.jar -c %_cmd% "%2"
The official Weka answer is right..But....crucial is to first get rid of all JVM files and install the relevant 32 or 64 bit Java version. Not using the relevant version causes many problems including the impossibility to increase the heap further than 1024m (by changing the ini file).
Weka 3.9.2 also does not has the option of maxheap anymore. RunWeka.ini have the option of javaOpts, So you may change the below to your required memory allocation,
javaOpts=%JAVA_OPTS% ---- > javaOpts= -Xmx1024m
Here 1024m is the customised amount of memory you want to allocate.
The best way to do it using this command
java -Xmx1024m -[weka classifier] -t [training file path]
The answers above are too old (last one is 1 year ago).
I had same issue with my WEKA (version 3.8.1) on Windows 10.
I had a problem to update the heap size , the way I fixed it is by adding an environment variable (under control panel) as follows:
JAVA_OPTS = -Xms30000m -Xmx30000m
Tip: Just ensure that RunWeka.ini is using this environment variable.
In the above example I give WEKA 30GB. It works.
Hope it will be helpful for some people.
You should also see if default thread stack size 20MB is enough. Increase the value to 50MB in the file /Applications/weka-3-8-1-oracle-jvm.app/Contents/Info.plist (on MAC) like below:
<string>-Xss50M</string>
If we are using Weka Workbench CLI or Knowledge explorer we need to
change as below.
As the documentation suggests the runtime parameter should be -Xmx[size_required]m where [size_required] is memory size you intend to keep to avoid memory exception.
Open RunWeka.ini
Define maxheap=[size_required]G
In my case I kept maxheap=4G , One can set like maxheap=4096m and add -Xmx#maxheap# to all the run options at # setups (prefixed with "cmd_") sections next to java commands
like below
cmd_default=javaw -Xmx#maxheap# ...............
cmd_console=cmd.exe /K start cmd.exe ..................
cmd_explorer=java -Xmx#maxheap# .................
cmd_knowledgeFlow=java -Xmx#maxheap#....................
maxheap=4G
Verify the same by restarting Weka and Help>>SystemInfo
If you run weka from the command line but not through java i.e. typing weka into the command line, instead of typing
weka
specify the memory flag
weka -m 1024m
This will specify 1024 megabytes.
If you're running weka via weka.sh, you can directly run it with memory option.
For example,
sh weka.sh -memory 10g
This will increase the heap size to 10Gb (tested using Weka 3.8.4 on Ubuntu 18.04)

How to increase heap size for jBoss server

I have an upload files scenario in my project. When I'm trying to upload the large files it's giving me an OutOfMemory error. That error is related to Java heap size.
How can you increase the heap size in Java and which file do I need to alter for this? I'm using jboss 5.1 server for running my application.
You can set it as JVM arguments the usual way, e.g. -Xms1024m -Xmx2048m for a minimum heap of 1GB and maximum heap of 2GB. JBoss will use the JAVA_OPTS environment variable to include additional JVM arguments, you could specify it in the /bin/run.conf.bat file:
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"
However, this is more a workaround than a real solution. If multiple users concurrently uploads big files, you'll hit the same problem sooner or later. You would need to keep increasing memory for nothing. You should rather configure your file upload parser to store the uploaded file on temp disk instead of entirely in memory. As long as it's unclear which parser you're using, no suitable answer can be given. However, more than often Apache Commons FileUpload is used under the covers, you should then read the documentation with "threshold size" as keyword to configure the memory limit for uploaded files. When the file size is beyond the threshold, it would then be written to disk.
On wildfly 8 and later, go to /bin/standalone.conf and put your JAVA_OPTS there, with all you need.
Edit the following entry in the run.conf file. But if you have multiple JVMs running on the same JBoss, you might want to run it via command line argument of -Xms2g -Xmx4g (or whatever your preferred start/max memory settings are.
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms2g -Xmx4g -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true
Use -Xms and -Xmx command line options when runing java:
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
For more help type java -X in command line.
I have mentioned the configuration changes needed for the increase of heap size in Windows or Linux environments.
Linux:
bin/standalone.conf
Check for the following line,
JAVA_OPTS
and change it accordingly to suit your heap size needs
-Xms1303m: initial heap size in megabytes
-Xmx1303m: maximum heap size in megabytes
JAVA_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=2048M -XX:MaxHeapSize=2048M"
Windows:
bin/standalone.conf.bat
JAVA_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=2048M -XX:MaxHeapSize=2048M"
Now restart the server and it will work without prompting any heap size errors.
For more information you can refer this link below.
https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/5/html/getting_started_guide/adjust_memory_settings
Look in your JBoss bin folder for the file run.bat (run.sh on Unix)
look for the line
set JAVA_OPTS, (or just JAVA_OPTS on Unix) at the end of that line add -Xmx512m. Change the number to the amount of memory you want to allocate to JBoss.
If you are using a custom script to start your jboss instance, you can add the set JAVA_OPTS option there as well.
In my case, for jboss 6.3 I had to change JAVA_OPTS in file jboss-eap-6.3\bin\standalone.conf.bat and set following values -Xmx8g -Xms8g -Xmn3080m for jvm to take 8gb space.
Add following option in jboss in bin/standalone.conf.bat
set "JAVA_OPTS=-Xms1G -Xmx1G -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=1024m"
What to change?
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"
Where to change? (Normally)
bin/standalone.conf(Linux) standalone.conf.bat(Windows)
What if you are using custom script which overrides the existing settings? then?
setAppServerEnvironment.cmd/.sh (kind of file name will be there)
More information are already provided by one of our committee members!
BalusC.
You can increase or set the heap size configuration i.e. -Xms/Xmx or any other JVM options in the JBoss application server in JAVA_OPTS JVM options in standalone.conf(Linux) & standalone.conf.bat file in Windows.
JAVA_OPTS="-Xms2048M -Xmx2048M"

How to increase Java heap space for a tomcat app

There are lots of questions that ask this or a similar question.
They all give the command that has to be executed, what I don't understand is where do I write this command. I want to permanently increase the heap space for my tomcat apps.
I read this page http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html and it says under the Tomcat section
Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,
set CATALINA_OPTS=-Xms512m -Xmx512m (Windows, no "" around the value)
export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash, "" around the value)
setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh, "" around the value)
So I replaced the line
set CATALINA_OPTS=
with
set CATALINA_OPTS=-Xms512m -Xmx512m
But I still get the error.
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.OutOfMemoryError: Java heap space
java.lang.reflect.Array.multiNewArray(Native Method)
java.lang.reflect.Array.newInstance(Array.java:90)
nom.tam.util.ArrayFuncs.newInstance(ArrayFuncs.java:1028)
nom.tam.fits.ImageData.read(ImageData.java:259)
nom.tam.fits.Fits.readHDU(Fits.java:573)
controller.UploadServlet.retreiveFITSFileFields(UploadServlet.java:206)
controller.ScanServerFiles.doPost(ScanServerFiles.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
There is a mechanism to do it without modifying any files that are in the distribution. You can create a separate file %CATALINA_HOME%\bin\setenv.bat or $CATALINA_HOME/bin/setenv.sh and put your environment variables there. Further, the memory settings apply to the JVM, not Tomcat, so I'd set the JAVA_OPTS variable instead:
set JAVA_OPTS=-Xmx512m
First of all you cannot change the memory settings only for a tomcat application but rather for all tomcat instance.
If you are running tomcat from console (using startup.bat) you'll need to edit catalina.bat and play around with CATALINA_OPTS. For example:
set CATALINA_OPTS=-Xms512m -Xmx512m
Restarting tomcat will apply the new settings.
If you are still getting OutOfMemoryError you need to know how much memory does your application need at that particular moment (nom.tam.util.ArrayFuncs...). You'll either have to optimize the application or simply increase the memory provided to tomcat.
Your change may well be working. Does your application need a lot of memory - the stack trace shows some Image related features.
I'm guessing that the error either happens right away, with a large file, or happens later after several requests.
If the error happens right away, then you can increase memory still further, or investigate find out why so much memory is needed for one file.
If the error happens after several requests, then you could have a memory leak - where objects are not being reclaimed by the garbage collector. Using a tool like JProfiler
can help you monitor how much memory is being used by your VM and can help you see what is using that memory and why objects are not being reclaimed by the garbage collector.
Open the server tab in eclipse
right click open
click on open lauch configuration
Go to arguments
Here you can add in VM arguments after endorsed
-Xms64m -Xmx256m
You need to add the following lines in your catalina.sh file.
export CATALINA_OPTS="-Xms512M -Xmx1024M"
UPDATE : catalina.sh content clearly says -
Do not set the variables in this script. Instead put them into a script setenv.sh in CATALINA_BASE/bin to keep your customizations separate.
So you can add above in setenv.sh instead (create a file if it does not exist).
Easiest way of doing is: (In Linux/Ububuntu e.t.c)
Go to tomcat bin directory:
cd /opt/tomcat8.5/bin
create new file under bin directory "setenv.sh" and save below mention entries in it.
export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx2048m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
and issue command:
./catalina.sh run
In your catalina log file you can see entry like this:
INFO [main] VersionLoggerListener.log Command line argument: -Xms512m
INFO [main] VersionLoggerListener.log Command line argument: -Xmx2048m
INFO [main] VersionLoggerListener.log Command line argument: -XX:MaxPermSize=256m
Which confirms that above changes took place.
Also, the value of "Xms512m" and "-Xmx2048m" can be modified accordingly in the setenv.sh file.
Startup of tomcat could be done in two steps as well.
cd /opt/tomcat8.5/bin
Step #1
run ./setenv.sh
Step #2
./startup.sh
If you're using systemd edit:
/usr/lib/systemd/system/tomcat8.service
and set
Environment=CATALINA_OPTS="-Xms512M -Xmx2048M -XX:MaxPermSize=256m"
if you are using Windows, it's very simple. Just go to System Environnement variables (right-clic Computer > Properties > Advanced System Parameters > Environnement Variables); create a new system variable with name = CATALINA_OPTS and value = -Xms512m -Xmx1024m. restart Tomcat and enjoy!
For Windows Service, you need to run tomcat9w.exe (or 6w/7w/8w) depending on your version of tomcat.
First, make sure tomcat is stopped. Then double click on tomcat9w.exe. Navigate to the Java tab. If you know you have 64 bit Windows with 64 bit Java and 64 bit Tomcat, then feel free to set the memory higher than 512. You'll need to do some task manager monitoring to determine how high to set it. For most apps developed in 2019... I'd recommend an initial memory pool of 1024, and the maximum memory pool of 2048. Of course if your computer has tons of RAM... feel free to go as high as you want.
Also, see this answer: How to increase Maximum Memory Pool Size? Apache Tomcat 9
you can set this in catalina.sh as CATALINA_OPTS=-Xms512m -Xmx512m
Open your tomcat-dir/bin/catalina.sh file and add following line anywhere -
CATALINA_OPTS="$CATALINA_OPTS -Xms1024m -Xmx3024m"
and restart your tomcat
Just set this extra line in catalina.bat file
LINE NO AROUND: 143
set "CATALINA_OPTS=-Xms512m -Xmx512m"
And restart Tomcat service

increase the java heap size permanently?

Is there a way that I can set the default heap size for the jvm on my own computer? I want to set it to 1g, because I'm always running custom programs that always hit the overage point in the default jvm size.
I just dont want to have to remember to type -XmX1g everytime I run my java app from the command line...
There has to be an admin way to do this right?
Apparently, _JAVA_OPTIONS works on Linux, too:
$ export _JAVA_OPTIONS="-Xmx1g"
$ java -jar jconsole.jar &
Picked up _JAVA_OPTIONS: -Xmx1g
For Windows users, you can add a system environment variable named _JAVA_OPTIONS, and set the heap size values there. The JVM should be able to grab the virtual machine options from _JAVA_OPTIONS.
This worked for me:
export _JAVA_OPTIONS="-Xmx1g"
It's important that you have no spaces because for me it did not work. I would suggest just copying and pasting. Then I ran:
java -XshowSettings:vm
and it will tell you:
Picked up _JAVA_OPTIONS: -Xmx1g
what platform are you running?..
if its unix, maybe adding
alias java='java -Xmx1g'
to .bashrc (or similar) work
edit: Changing XmX to Xmx
if the platform is Linux, then adding an entry in bash_profile will help.
vim ~/.bash_profile
then add
export _JAVA_OPTIONS="-Xmx4g"

Categories