we're running a Java application for rendering ans displaying quite a number of images. To make this smooth, we's like to assign a fair amount of heap space, and would like to check if there's a 64 bit version available on the computer. We'd like to run the application on many different computers, so manually checking the available memory and the Runtime version by trial and error is quite a hassle.
Does anyone know of a method to determine the availably memory that can be reserved for heap space, and to determine the available JREs; so we could somehow pass these parameters on to the JRE when executing the jar?
I'm aware that this would require some sort of batch file, like discussed in this thread:
Setting Launch Parameters In Java Class
Has anyone come across a running example for a Windows environment? My knowledge about Windows Batch-files is limited at best.
Regards, Marius
to check if java is 64-bit:
java -version 2>&1|find /i "64-Bit" && echo YEP!||echo NOPE!
To get free memory :
wmic os get freephysicalmemory
or:
systeminfo | find "Physical Memory"
EDIT
Universal and fast way to get free memory:
mshta "javascript:close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(GetObject('winmgmts:').ExecQuery('Select * from Win32_PerfFormattedData_PerfOS_Memory').ItemIndex(0).AvailableBytes));"|more
assign result to variable:
for /f "usebackq" %%a in (`mshta ^"javascript^:close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(GetObject^(^'winmgmts:^'^).ExecQuery^(^'Select * from Win32_PerfFormattedData_PerfOS_Memory^'^).ItemIndex^(0^).AvailableBytes^)^);^"^|more`) do set free_mem=%%a
Related
This is a problem, that bugs a customer of ours already for a while. Eventhough we provided a 64-bit JavaFX Desktop Application with JVM Options set to:
[JVMOptions]
-Xmx5120m
Runtime.getRuntime().maxMemory() returns roughly about only 1 GB, eventough the client has 16 GB of RAM available.
The application gets deployed by extracting an archive together with an 64-bit runtime and is builded with fx:deploy ant task. Unfortunatly we are unable to reproduce this error here at any time.
Are there any other possibilities to restrict the memory a Java-Application can use? The customer uses some kind of virtualisation system like citrix receiver with windows 7. Can this have an influence on it? I also read it is possible to restrict the amount of memory an application can use due to windows registry entries?
Any help is greatly appriciated, because we are running out of ideas on how to solve this case.
Additional Information: To gather more information, we wrote a diagnostic tool inside our application which is simular to the one of apache diagnostics. It shows that our -Xmx parameter seems to get overwritten:
diagnostics.vmInfoStartup:
-Djava.library.path=K:\PATH\APPLICATION\app;K:\PATH\APPLICATION\
-Djava.launcher.path=K:\PATH\APPLICATION\
-Dapp.preferences.id=FxApplication
-Xmx5120m
-Xmx1024m
But where does the second -Xmx1024m restriction come from? The user starts the EXE deployed from our fx ant task without any further parameters.
How can I know the targets of JVM configuration?
I know how to set JVM for my server, which can be done by command
'java -Xmx3550m -Xms3550m -Xmn2g -Xss128k'.
But what's command can to see what it is like? Any guidance?
You can use VisualVm/Jconsole to connect to your running jvm. This will give you all the information you need.
If you're running linux you can use something like ps -efx | grep java
You can use VisualVM to display information about the JVM.
If you want to see the command line arguments you can use jps -lvm to list all your java processes.
The maximum size is a little suspect. It appear you are trying to pick the maximum size for a 32-bit JVM on a 64-bit OS (which can be about 3.5 GB on some OSes) Personally I would just use a 64-bit JVM and use 4 GB as this uses 32-bit references so there is very little disadvantage in doing so.
I am shipping an Eclipse based application and want to have maximum Heap size. How can I make my application use all avilable memory on different machines. All I have found so far is the paramaters for setting heapsize that I can send the JVM but these are hardcoded. Basically I want the JVM to use whatever memory is available on the machine. Hard coding is not good enough.
Is there an easy way of doing this?
Not possible using standard JVM features. JVM parameters specify the amount of memory to reserve (-Xmx...), not possible to specify "take all memory available". You could try a reasonable value like 1.2GB, that is the upper limit in Windows XP 32bit, for example. The problem is that the OS could not reserve all memory required by JVM so you must be more conservative.
The other approach is to calculate the available memory externally (script, native utility) and then set the JVM parameter with that value. NOt know if any installer like Install4J could achieve this.
Recently I've been getting the notorious error message: OutOfMemoryError. I've a 64Bit Mac with 16GB Ram and 2X2.6 GH quad core. Getting this error message simply doesn't make sense to me because the same algoritm that I'm running (that causes this error message) is running smoothly on another machine (ubuntu 16GB Ram).
System.out.println(java.lang.Runtime.getRuntime().maxMemory());
When I run the above code on my mac I get: 129,957,888 (without the comma of course :-))
And when running this code on the ubuntu machine I get: 1,856,700,416
Can anyone tell me how I can increase my max memory in order to run my algorithm? Thanks!
I tried to set on my eclipse: default VM arguments -Xms512m -Xmx4g, but nothing changed.
-Xmx and -Xms are the correct arguments to the java command to change heap size, but Eclipse has to be configured differently.
You're going to have to elaborate. Are you running a test in Eclipse, or outside of Eclipse? Just passing the "-Xmx" parameter to Eclipse won't do what you want, even if you do it in the correct way to actually change the max mem value for Eclipse (that requires prefixing it with "-vmargs"). If you want to change the max mem value for the forked JVM that's running your algorithm, you have to change the parameters in the run configuration.
It looks like matt b has this one covered. I just wanted to mention that you might not want to set the max heap size as high as 4GB unless your program will really need that much. From what I understand the JVM allocates all of that memory for itself when it starts, and then uses it to run code as needed. Making it allocate that much memory might cause performance problems with other applications you're running. Instead, try stepping it up in increments of 128MB, or more if your code takes a long time to fail. Alternatively, maybe you can use a memory profiler to see how much space you actually use? I have no idea if such a thing exists.
This is probably not a problem on your setup, but for mere mortals like me, blithely allocating that much memory could be problematic.
I recently purchased a VPS, and on paper its supposed to give me 1 GB of dedicated memory and another 1 GB of burstable memory ... So at any given time, the total amount of memory that should be available to me should be between 1 GB and 2 GB, right ? Correct me if I'm wrong ..
How can I check this from within my Ubuntu VPS ? So that I know I'm getting what I'm paying for ..
I want to check this because I installed Java on the VPS, and its not running due to having insufficient memory available ..
By the way, I know of the 'free' command ... Question is, would it serve my purpose ?
EDIT: The reason why I think I'm running low on memory is because when I have a VPN session on and I type in java in the console, I get the following error:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
However, if I restart the VPS and do not start the VPN service, and instead just login through ssh again and type in java, I get the correct response (all java parameters listed, etc) ...
Java only required 64MB of RAM to run on Linux box http://www.java.com/en/download/help/sysreq.xml
If it print "out of memory error", then the problem probably in your Java program.
to check memory allocation in Linux, use free command or "cat /proc/meminfo"
These howto will check realtime RAM memory usage available in Linux VPS using watch command.
a. Check memory usage using “top” command. Watch command not required for top command as top will update the result periodically. :
top
b. Check memory usage using “/proc/meminfo” with watch command :
watch -n 1 cat /proc/meminfo
c. Check memory usage using “free” with watch command :
watch -n 1 free
d. Check memory usage using “vmstat” with watch command :
watch -n 1 vmstat
instead of viewing the static used memory, you can view the live usage using htop. all of the commands suggested show the ram available/used at a point in time. htop allows you to view the dedicated ram and the swap ram usage updated in 1 second intervals which makes it easier to understand your services ram needs. htop also shows the live usage of your cpu's.
Run this command on ubuntu to install htop
sudo apt-get install htop
then run htop with
htop
good luck