Memory Management for Java applications is an extensive topic with loads of tuning options. However, the Java Virtual Machine by default takes care of many optimizations on it's own.
Unless explicitly specified, the JVM determines the amount of memory available on the machine and depending on it's findings sets the initial and maximum sizes for different block of memory (called spaces) a Java application uses. As Java works works with explicit maximum sizes for the different spaces, if the application requires more memory than the maximum set, OutOfMemory exceptions occur, which both degrade performance, but more importantly can cause unexpected behavior.
Java's memory management works with automatic Garbage collection: the process of removing objects from memory if they are no longer used, to ensure the Java process doesn't quickly run out of memory. This is a fully automatic process, but the performance of the Java process might be compromised when using the wrong configuration.
Processes in Java, like the Servoy Application Server, need to be told explicitly the maximum of memory they are allowed to use. This setting, the maximum heap size, is important to adjust to the load the Servoy Application Server is to handle.
The maximum heap size setting is located in ../application_server/servoy_server.sh/.bat, through the "Xmx" setting.
When the Application Server is started as a Service the setting can be found in ../application_server/service/wrapper.conf, by the name of "wrapper.java.maxmemory".
By default the maximum heap size is set to 256MB. This setting should be changed when:
- The actual used memory is >= 70% of the specified maximum. The actually used memory can be found on the main page of the Admin page, under System Information, like: Heap memory: allocated=549184K, used=371473K, max=699072K
- When the expected client load will exceed the maximum: As a rule of thumb:
- Smart Client: assume a memory usage of about 600kb for each Smart Client. NOTE: When the Servoy HTTP Tunnel is used, assume 900kb per Client.
- All other type of Clients (Web, Headless, Batch): the required memory for each client depends on the size and design of the solution, but should be in the order of magnitude of a couple of Mb per Client.
- When there is plenty of free real memory available on the OS level. Java processes in general perform better when not having memory constraints. For example, when 2Gb free real memory is left, add the 2Gb to the maximum heap size. The Java process will only take what it needs.
Memory Management basics for Java
Java memory consumption is divided in several different area's, called spaces. The most important ones are the Java Heap Space and the Java Perm Space, but there are others.
Each area is by default configured with an initial size and a maximum size, but these sizes can be overruled using arguments when launching the Java process. The defaults values differ per JVM implementation and can depend on the hardware on which the JVM is started.
The JVM will always respect the maximum size set of a specific space. In the case of the Java process hits the maximum size for a specific space, a relevant exception will be thrown, for example an OutOfMemory or Stack Overflow exception. Thus it's vital to dimension the maximum size of the relevant spaces according to the requirements of the process.
Java Heap Space
lkdflk
Java Perm Space
kl
Initial Java Heap Size
Maximum Java Heap Size
Maximum Java Perm Size
Servoy Application Server
Smart Client
Initial Client Heap
Max. Client Heap
Virtual Machine Arguments
More reading
http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf