Servoy is built using Java technology and as such the memory management for Servoy is basically Java Memory management. This chapter describes the basics of Java Memory management, which will be sufficient for all but the most extensive and complex deployment scenario's.

Java Memory management introduction

The basics of Java Memory management is straight forward:

Java Memory spaces

The two most important spaces of memory that a Java process uses are the Java Heap Space and the Java Perm Space. 

Java Heap Space
Java Perm Space

For more information on Java Memory management, see http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf

Server Memory management

Dimensioning the Server

The memory consumption of a Servoy Application Server consists of the following parts:

The memory usage of the Servoy Application Server itself is limited to a couple of Mb.

For the database connections assume 2Mb per connection, so sum the Maximum Active connections settings on each configured and enabled Database Server and multiply that by 2Mb to determine the maximum memory consumption by the database connections

The memory usage for the running Servoy Clients is more difficult to obtain, as it depends on the number of running Clients, the type of the running Servoy Clients, the way the Servoy Solutions that are running are built and the way the users use the Solutions. These variables together make it difficult to provide hard numbers on how to configure the memory settings beforehand. Getting it right means monitoring and tuning.

As a starting point the following rule of thumb can be used to determine the initial settings: 

Smart Client Memory usage vs. other Servoy Client

The memory consumption of Smart Client on the Server is an order of magnitude lower that for the other Servoy Clients, as the Servoy Smart Client runs on the client machine, not on the Servoy Application Server. See #Smart Client Memory management for more information on configuring the Memory settings for Smart Clients.

Web Client, Headless Client & Batch processors memory usage

The memory usage of Web Clients, Headless Clients and Batch Processors depends highly on the design of the solution. While Servoy optimizes many things to keep the memory footprint as low as possible, it is logical that a simple solution showing just one form at the time has a different memory footprint than a solution that has a very complex UI, showing 20 Forms and/or different sets of data at the same time.

The memory footprint is not linear with the number of Forms a Solution contains, as Forms are instantiated on a need-to basis.

As there is no way to determine up front how much memory a Web/Headless/Batch Processor Client will use, the only way to dimension the memory correctly is by monitoring and tuning it.

For the initial dimensioning, use the following rules of thumb:

Configuring the memory settings

By default the maximum heap size is set to 256MB. This setting should be changed when:

Depending on how the Servoy Application Server is started, the Memory setting need to be applied in a different location.

Manual start: servoy_server.bat/.sh

When starting the Servoy Application Server manually through {serverInstall}\application_server\servoy_server.bat/.sh, the memory settings for the Application Server can be configured inside servoy_server.bat/.sh:

java -Djava.awt.headless=true -Xmx256m -Xms64m -XX:MaxPermSize=128m .....
Auto start: wrapper.conf

When using the Service component to automatically launch the Servoy Application Server when the machine on which it is installed is booted, the memory settings for the Application Server can be configured inside {serverInstall}\application_server\service\wrapper.conf:

wrapper.java.additional.4=-XX:MaxPermSize=128m
# Initial Java Heap Size (in MB)
wrapper.java.initmemory=32
# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=256

For more information on configuring the Service component, see Running the server as a service

Starting in Servoy Cluster: start_servoy_clustered.bat/.sh

When the Servoy Application Server is part of a Servoy Cluster, the memory settings can be configured in {serverInstall}\application_server\terracotta\start_servoy_clustered.bat/.sh:

-Xmx256m -Xms64m -XX:MaxPermSize=128m
32bit Java Memory assignment limitation

(warning)  When the Servoy Application Server runs under a 32 bit JVM the maximum amount of memory that can be assigned to the Java process is 2Gb. This is a limitation of 32 bit. In order to be able to assign more memory, a 64 bit environment is required.

Smart Client Memory management

Initial Client Heap

Max. Client Heap

Virtual Machine Arguments

Java Virtual Machine (JVM) Tuning

Java version
Servoy supports both Java 5 and Java 6 (for the Application Server, the Smart Client and Servoy Developer). As Java 6 has numerous performance improvements, it is preferred over Java 5.

If the hardware in which Servoy is running is 64bit, make sure to also run a 64 bit Java Virtual Machine. When in doubt which version is used, check the Servoy Admin page, under "Servoy Server Home" > "Servoy Server Status" > "JVM Information":

An 32 bit JVM will allow a max memory of 2 Gb in total, In order to run with larger heap sizes (over 2 Gb) you have to use 64 bit JVM on a 64 bit OS

Java Virtual Machine Server mode
Java has 2 distinct operating modes: client mode and server mode. When running in server mode, the startup of the Java process will take longer and initial execution of code will be slower, but after a while the application will perform faster. The server mode is best suited for the Servoy Application Server.

Whether or not a Java Virtual Machine supports client and/or server mode depends on the hardware, see http://download.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html.

If the JVM supports servermode, it will automatically detect if the machine it is running on is a "capable" machine and automatically run in server or client mode depending. The definition of "capable" may differ from Java version to Java version. For Java 5/6 this means a 2CPU, 2Gb memory machine.

Checking whether or not a Servoy Application Server runs in client or server mode can be seen on the Servoy Admin page, under "Servoy Server Home" > "Servoy Server Status" > "JVM Information":

It is possible to enforce the Servoy Application Server to run in server mode (assuming the JVM is capable to operate in server mode), an extra startup argument can be added to the startup of the Servoy Application Server.

In servoy_server.sh/bat:

java -server -Djava.awt.headless=true .....

When using the Service wrapper:

# Java Additional Parameters
wrapper.java.additional.1=-Djava.awt.headless=true
wrapper.java.additional.2=-Duser.dir="C:\Servoy\application_server"
wrapper.java.additional.3=-XX:MaxPermSize=128m
wrapper.java.additional.4=-server

On Windows 32 bit environments, the Java Runtime Environment does not include support for server mode. In order to take advantage of server mode optimizations on 32 bit Windows systems, it is required to install Java Development Kit (JDK)

Memory

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 {servoy_install}/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 {servoy_install}/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: