How can we verify heap size for running ElasticSearch - java

Am running ElasticSearch Version 6.2.3 and i am increasing heapsize to 4GB in config\jvm.options file. Then am restarting my ES, how i can make sure that my ES is running with my modified heapsize. Is there any command to verify the heap-size of ES.
Am running my ES in Windows machine.
Please find my configuration details.
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms2g
## -Xmx2g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms4g
-Xmx4g

You can find out the heap size used by each node using the _cat/nodes endpoint.
It would look like below:
host=localhost:9200 #replace with your Elasticsearch URL
curl $host/_cat/nodes?h=heap*
This would return an output which should look like below:
554.8mb 30 1.8gb
850.9mb 46 1.8gb
1.7gb 95 1.8gb
Column 1 here is heap.current, aka used heap.
Column 2 here is heap.percent, aka used heap in percentage.
Column 3 here is heap.max, aka max heap available to the node.
The h query string param allows you to select the column names to display. We are using the * wildcard to expand to all the columns that start with the heap prefix.
You can read the documentation here to learn more: https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html.

You can find the JVM arguments used in elasticsearch instance in INFO logs. Make sure that your elastic logging level shows INFO logs.

You can also check the command line arguments used to launch the instance by using either of the options below:
Use Process Explorer, and hover over the process name for java.exe (launched by elasticsearch.exe). Be sure you have selected "Show Details for All Processes" from the File menu.
Run the following command from an elevated command prompt: WMIC PATH win32_process WHERE "caption='java.exe'" GET Commandline
Both will give you the commandline parameters used to launch the instance. Look for the -Xmx and -Xms values.
For more information about these two options, check out How do I find out command line arguments of a running program?

Related

Java.lang.OutOfMemoryError: Java heap space [Ubuntu]

i am trying to run my code and i got this error on my console
[java] Caused by: java.lang.OutOfMemoryError: Java heap space
i run Jconsole on jdk folder the max heap 1.9m ,how can i change it ?
As for hybris, you need to update tomcat.generaloptions property to adjust Xmx value. For instance, via local.properties.
-Xmx2G is a default value.
tomcat.generaloptions=-Xmx4G -ea -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dorg.tanukisoftware.wrapper.WrapperManager.mbean=true -Djava.endorsed.dirs="%CATALINA_HOME%/lib/endorsed" -Dcatalina.base=%CATALINA_BASE% -Dcatalina.home=%CATALINA_HOME% -Dfile.encoding=UTF-8 -Djava.util.logging.config.file=jdk_logging.properties -Djava.io.tmpdir="${HYBRIS_TEMP_DIR}"
You can configure the max heap size using the -Xmx size command line argument.
By default it's 64mb. The 1.9m you see seems strange.
Here is the Oracle doc for the java command:
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html
Specifically:
-Xmxsize
Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value is chosen at runtime based on system configuration. For server deployments, -Xms and -Xmx are often set to the same value. See the section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage Collection Tuning Guide at http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.
The following examples show how to set the maximum allowed size of allocated memory to 80 MB using various units:
-Xmx83886080
-Xmx81920k
-Xmx80m
The -Xmx option is equivalent to -XX:MaxHeapSize.

Increased heap size in java is not reflecting in jconsole

strong text
I am trying to run an java spring boot application by specifying the heap size as argument while starting the jar like below,
java -jar a-1.0.0.jar -Dpidfile=/tmp/a_report.pid -Xmx5196m -Xms512m
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/java_heapdump.hprof
Max Heap Space - 4 GB
But when I try to monitor the application after execution in J-Console, I could not see the actual heap size change getting reflected. I could see in Memory tab the following params
Time:  2018-02-13 15:23:42 Used: 
    73,103 kbytes Committed:   1,181,184 kbytes Max:   1,864,192 kbytes
Also the application throws OOM exception when the heap size is around 2 gb so it is clear that the updated heap space memory given during the start of the application is not getting reflected.
So what should I do to make my application pick heap space as 4gb
Configuration :
RAM - 8 gb JDK - 1.8
You need to provide the options before -jar a-1.0.0.jar, otherwise they're interpreted as arguments for the jar, not for the JVM.

MaxHeapSize in Java

I run command in window machine
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize
and got below value for MaxHeapSize
2118123520
which is 2020MB however, when I call Runtime.getRuntime().maxMemory() , it gives me 259522560 only i.e. 247MB .
Can anyone please suggest why I'm getting this mismatch ?
As per your last comment
I'm using eclipse IDE and didn't change any setting . do you know how to change maximum heap size in eclipse IDE ?
Set the VM arguments found under Run configuration.
VM arguments are typically values that change the behaviour of the Java Virtual Machine (JVM). For example, the -Xmx256M argument allows the Java heap to grow to 256MB.
For more info have a look at Eclipse launching program and VM arguments
Can anyone please suggest why I'm getting this mismatch ?
The Runtime.getRuntime().maxMemory() call is returning the maximum heap size for the current JVM. This is determined by either the -Xmx command line option (e.g. for the java command) or a platform specific default.
The command you are running is giving the maximum allowed value for the -Xmx commandline option on your platform.
Clearly these are different things. Furthermore, the numbers are usually different.

java heap size error for selecting 0.4 million records

i have 2gb ram on my computer. its a windows 7
using eclipse for java
when i run a program that runs a select query on mysql database with 0.4 million records it gives heap size error.
this is my present eclipse.ini
-vmargs
-Xmx1000m
-XX:MaxPermSize=256m
-XX:ReservedCodeCacheSize=64m
what can i do ?
EDIT: You're talking about your eclipse.ini? You should of course use the debug configuration to specify the arguments:
Run > Debug Configurations ... > [your configuration] > Arguments > VM Arguments
How big is one row? 1000 MB / 400,000 records = max 2,5 KB per row (it will be less as you can't use the whole heap).
(Note I used 1MB = 10^6 bytes)
It rows are small, run your application with -XX:+HeapDumpOnOutOfMemoryError and analyse the resulting heap dump using MAT
Do you run the query in a plugin of Eclipse or do you use Eclipse to run a Java program? In the latter case, the settings in eclipse.ini aren't inherited. You must repeat the in the launch configuration of your app.

Problems with java heap space, how to increas the heap size?

I'm running a ".bat" file which points to asant:
C:\Sun\SDK\bin\asant Startbds
asant again points to a xml file i've got, build.xml:
<target name="Startbds" description="Start bds">
This has been fine for now, but now i have added more data, which leads to an out of memory error:
java.lang.outOfMemoryError: Java heap space
So i've tried to increase the heap space by various methods i've found while searching around for a solution:
cmd: set ANT_OPTS=-Xms512m -Xmx512m (did not work, same error message)
Editing the asant.bat where i edited the line "-set ANT_OPTS" from
.
set ANT_OPTS="-Dos.name=Windows_NT" -Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"
TO
set ANT_OPTS="-Xms512m -Xmx512m" "-Dos.name=Windows_NT" -Djava.library.path=%AS_INSTALL%\lib;%AS_ICU_LIB%;%AS_NSS%" "-Dcom.sun.aas.installRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceRoot=%AS_INSTALL%" "-Dcom.sun.aas.instanceName=server" "-Dcom.sun.aas.configRoot=%AS_CONFIG%" "-Dcom.sun.aas.processLauncher=SE" "-Dderby.root=%AS_DERBY_INSTALL%"
but this gave me the error message:
"Invalid initial heap size: -Xms512m -Xmx512m
Could not create the Java virtual machine."
Anyone got an idea of how i should increase the heapsize?
And maybe also give a pointer to where i can find a tool to watch the heapsize.
Thanks in advance.
By using "-Xms512m -Xmx512m" you gave a single argument. -Xms expects the minimum heap size to be specified by the rest of the argument. So you defined the minimum heap size to be "512m -Xmx512m", which is not a valid value.
You will want to provide those switches as two arguments:
set ANT_OPTS=-Xms512m -Xmx512m "-Dos.name=Windows_NT" ...
I think that if you're in windows, you don't need the double quotes in your set.
Here is an example I saw somewhere:
set ANT_OPTS=-Xms512m -Xmx512m (Windows)
export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)
setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
As for monitoring heap usage, if you are using the most recent JDK on Windows, you should have Sun's VisualVM.
In eclipse -> window -> preferences -> Tomcat -> JVM Setting -> Append to JVM Parameters:
-XX:MaxPermSize=512m
-Xms512m
-Xmx512m

Categories

Resources