I saw Java -server in http://shootout.alioth.debian.org/ for programming language benchmark.
I know that -server is a parameter for running JVM. I want to know:
When we use -server parameter and how it work?
Can we use this parameter for java desktop application?
thanks.
It just selects the "Server Hotspot VM". See documentation (Solaris/Linux) for java.
According to Wikipedia:
Sun's JRE features 2 virtual machines,
one called Client and the other
Server. The Client version is tuned
for quick loading. It makes use of
interpretation, compiling only
often-run methods. The Server version
loads more slowly, putting more effort
into producing highly optimized JIT
compilations, that yield higher
performance.
See: http://en.wikipedia.org/wiki/HotSpot
The -server flag will indicate to the launcher that the hw is a server class machine which for java 6 means at least 2 cores and at least 2 GB physical memory (ie most machines these days). On server class machines the deafult selection is
The throughput gc.
initial heap size of 1/64th of phys mem up to 1 GB
maximum heap size of 1/4th of phys mem up to max of 1 GB.
The server run time compiler.
Note that on 32 bit windows there is no server vm so the client vm is the default.
On the other 32 bit machines the server vm is chosen if the hw is server class, otherwise it's client. On 64 bit machines there is no client vm so the server vm is the default.
A link to the hot spot faq: HotSpot
You can check this blog for additional info: http://victorpillac.wordpress.com/2011/09/11/notes-on-the-java-server-flag/
Basically on most recent machines different from 32bits windows the flag will be turned on by default.
For 32bits windows you will need to download the JDK to get the server system.
More info on server vms : http://download.oracle.com/javase/1.3/docs/guide/performance/hotspot.html#server
Related
I'm using a Windows 2012 server with 7GB of ram that is on Azure.
I have installed 64 bit java on the machine.
When running the jvm, I have set the maximum heapsize to 4GB via the argument
-Xmx6g
However, when I'm running my jar, it encounter a java OutOfMemory exception. I have checked the task manager while it is running and it shows that memory used for the process peaks at around 2GB and never goes past that. This despite me setting heapsize to 6GB.
On my local PC, where I am using a Windows 7 machine with 8GM of ram, I do not encounter this issue.
I used the following commands in my java app
System.out.println(System.getProperty("sun.arch.data.model"));
System.out.println("Max Memory: " + Runtime.getRuntime().maxMemory());
And it gives me the following:
Windows Server 2012
64
1670381568
Local PC
64
6681001984
Why is the Windows Server not allocating the full amount of memory to the JVM? Is there any setting that I am missing?
This is really dumb and stupid of me but I figured out the cause of it.
I had placed the memory arguments at the end of my whole command line when I needed to put it just after the java command.
i.e. Instead of
java -jar "myapp.jar" "myArgs" -Xmx6g
I should have used
java -Xmx6g -jar "myapp.jar" "myArgs"
Either the -Xmx parameter is not being considered or the process is not allowed to get more RAM from the OS.
My suggestions:
Try using -Xmx4096m instead.
Not familiar with Azure but I've read that there are ways to limit memory per process/shell. Could that be an issue here? (Ref: http://msdn.microsoft.com/en-us/library/aa384372(VS.85).aspx , taken from http://social.technet.microsoft.com/Forums/en-US/2ba92acf-e1b9-4a3e-8ae7-f8ac31723959/problem-with-running-java-application-into-a-win-vm-of-azure-by-using-powershell-remoting?forum=WAVirtualMachinesforWindows )
Finally, are the Java versions exactly the same on both places? (I mean, do you need a special Java JRE on Azure?)
Note: I would've used a comment since this is not actually a solution but I don't have the points yet. I apologize if this is not the correct way to contribute.
I am running at the same computer a java game-server and a game-client
the game-client with
java -Xms512m -Xmx1024m -cp etc etc
and the game-server
java -Xmx1024M -Xms1024M -jar etc etc
Computer Properties:
Windows 7 64 bit
8GB RAM
CPU i5-2500 # 3.3GHz
Intel HD Graphics
Problem: The game-client experience serious lags. At the game-server is also connected via LAN another player with no lag issues!
Has the problem of the lag to do anything with java virtual machine? Am I using one instance of machine or two?
Can I setup something different in order to optimize the performance?
I am thinking that the problem has to do with the fact that one machine is running and its max memory is not enough for both instances, but I do not really know how to solve that.
Edit: No app run out of memory.
Solution:
1:
Updated Java version from:
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)
to
java version "1.7.0_15"
Java(TM) SE Runtime Environment (build 1.7.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
2:
Changed the server properties in order to minimize requirements, this seems to be the main reason.
3:
Increased memory:
game-client with java -Xms1024m -Xmx1024m -cp etc etc
and the game-server java -Xmx2048M -Xms2048M -jar etc etc
Server runs at about 700MB now.
Has the problem of the lag to do anything with java virtual machine?
Possibly. You haven't presented enough evidence to be sure one way or the other.
The puzzling thing is that the your client running on a different machine is not laggy.
Am I using one instance of machine or two?
You are running two copies of java then you will have two JVMs.
Can I setup something different in order to optimize the performance?
The answer is probably yes. But you haven't provided enough information to allow us to make solid suggestions.
Lagginess can be caused by a number of things, including:
A network with high latency.
A JVM that has a heap that is too small.
An application that is generating lots of garbage and triggering an excessive number of garbage collection.
A mix of applications that is competing for resources; e.g. physical memory, CPU time or disc or network I/O time.
If you are going to get to the root cause of your problem, you will need to do some monitoring to figure out which of the above is the likely problem. Use the task manager or whatever to check whether the system is CPU bound, short of memory, doing lots of disk or network stuff, etc. Use VisualVM to see what is going on inside the JVMs.
Alternatively, you could try to fix with some totally unscientific "knob twiddling":
try making the -Xms and -Xmx parameters the same (that may reduce lagginess at the start ...)
try increasing the sizes of the JVMs' heaps; e.g. make them 2gb instead of 1gb
try using a more recent version of Java
try using a 64 bit JVM so that you can increase the heap size further
try enabling the CMS or G1 collectors (depending on what version of JVM you are using).
If I knew more about what you were currently using, I could possibly give more concrete suggestions ...
You are using two java apps in same computer, resulting in 2 JVMs running.
For a 64 bit system with 8GB RAM, its recommended to use max 2GB(25% of Physical memory OR 75% of free physical memory up to 2 GB) for JVM for better performance.
You may have to look on JVM size adjustment. For better performance, Xms and Xmx size can be kept same with a max size bracket.
Assigning memory size to Heap is not the only area to think of. JVM uses more memory than just Heap. Others memory areas like Thread Stack, Method areas, Class Loader Subsystem, Native Method Stack etc.
While both of the apps(game-server, game-client) are running, there is a chance of issue in memory management by OS between both apps, resulting in slowness.
In that case, client app can be deployed in another core, if available.
This has been made hard for me:
Windows, so no signals.
Not in a console, so no signals that way.
As a service, so perhaps not run in user session.
Java 5
No JDK, so no jmap, jconsole etc. on machine.
App not running JMX.
No option to install or reconfigure.
Can plug a USB in.
AFAIK You can't trigger a heap dump with Java 5.0 even if you has complete access to the machine. (Admittedly I haven't used Java 5.0 for more than five years) With Java 6 you need JMX or trigger a heap dump on an out of memory error.
Some memory profilers may allow you to do a heap dump (of their own format) if you can find one which supports Java 5.0 but you would have to enable profiling from the start and that tended to be relatively slow on Java 5.0 from memory.
My virtual memory won't go higher than 2GB when I has 8GB available.
I'm running Ubuntu 10.10 x86 with Java JRE 1.6_25 installed.
When I try to launch the .jar file, it just an instantly crash.
It works just fine when I set the VM to 2048M
These are the arguments I use to define the VM -Xmx4096M -Xms4096M
Thankful for any help :)
If that's a 32bit VM, you won't go higher than 2G (or close to 3G with a kernel configured for 3G/1G userspace/kernel address space split). There is no way to have a 32bit process use more than 2G (or 3G with the right settings) of real memory.
You'll need a 64bit kernel and JVM to reach 4G of heap space (and go much beyond that).
See this question for good info about memory limits on Linux for 32bit applications: Memory limit to a 32-bit process running on a 64-bit Linux OS.
(The accepted answer talks both about 32bit and 64bit kernels. It also suggests that there were some patches where you could nearly reach 4G for userspace on a 32bit kernel, but I don't think those kind of things ever went into Ubuntu kernels - kind of a nich server thing.).
You should strongly consider migrating to a 64 bit operating system if you need that large a Java program. This will allow you to use a 64-bit JVM which allows for larger-than-2Gb Java programs.
I am not aware of a procedure to easily migrate from 32-bit to a 64-bit Ubuntu, but you can save your home directory and then reinstall.
You can then easily install the OpenJDK Java and with a bit more effort the official Sun JDK.
I'd like to run a very simple bot written in java on my VPS.
I want to limit jvm memory to let's say 10MB (I doubt it would need any more).
I'm running the bot with the following command:
java -Xms5M -Xmx10M -server -jar
IrcBot.jar "/home/jbot"
But top shows that actual memory reserved for java is 144m (or am I interpreting things wrong here?).
13614 jbot 17 0 144m 16m 6740
S 0.0 3.2 0:00.20 java
Any ideas what can be wrong here?
Java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode)
BTW. I'm running CentOS - if it matters.
EDIT:
Thank you for your answers.
I can't really accept any of them, since it turns out the problem lies within the language i choose to write the program, not the JVM itself.
-Xmx specifies the max Java heap allocation (-Xms specifies the min heap allocation). The Java process has its own overhead (the actual JVM etc), plus the loaded classes and the perm gen space (set via -XX:MaxPermSize=128m) sits outside of that value too.
Think of your heap allocation as simply Java's "internal working space", not the process as a whole.
Try experimenting and you'll see what I mean:
java -Xms512m -Xmx1024m ...
Also, try using a tool such as JConsole or JVisualVM (both are shipped with the Sun / Oracle JDK) and you'll be able to see graphical representations of the actual heap usage (and the settings you used to constrain the size).
Finally, as #Peter Lawrey very rightly states, the resident memory is the crucial figure here - in your case the JVM is only using 16 MiB RSS (according to 'top'). The shared / virtual allocation won't cause any issues as long as the JVM's heap isn't pushed into swap (non-RAM). Again, as I've stated in some of the comments, there are other JVM's available - "Java" is quite capable of running on low resource or embedded platforms.
Xmx is the max heap size, but besides that there's a few other things that the JVM needs to keep in memory: the stack, the classes, etc. For a brief introduction see this post about the JVM memory structure.
The JVM maps in shared libraries which are about 150m. The amount of virtual memory used is unlikely to be important to use if you are trying to minimise physical main memory.
The number you want to look at is the resident memory which is amount of physical main memory actually used (which is 16 MB)