Child pages
  • Memory Management
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

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.

In This Chapter

Java Memory management introduction

The basics of Java Memory management is straight forward:

  • A Java process uses several memory spaces (called the Perm Space or Heap Space for example), each of which use a dedicated block of memory
  • For each space the Java process determines the initial and maximum amount of memory it is allowed to use, of not explicitly specified through configuration. The defaults values differ per JVM implementation and can depend on the hardware on which the JVM is started.
  • The initial and maximum's for each space can also be explicitly specified through configuration
  • The initial memory sizes for all spaces are allocated at startup of the Java process
  • The Java process will allocate more memory only when required, up the specified maximum per space
  • Allocated memory that is not used anymore will periodically be released in a process called Garbage collection. In Java this is a fully automated process
  • If the Java process requires more memory than the maximum in any of the spaces, the Java process will throw a relevant exception, for example an OutOfMemory or Stack Overflow exception. These exceptions should be prevented as they both degrade performance, but more importantly can cause unexpected behavior.

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

The Heap Space is the main space used by Java while operating. As such this space will use the most memory. The settings related to the Java Heap Space are the following:

  • Xmx - Maximum Heap Space value
  • Xms - Initial Heap Space Value

When the Maximum Heap Space size is too low for that is actually needed by the Java process, the following exception will be thrown: java.lang.OutOfMemoryError: Java heap space

Java Perm Space

The Perm Space is the space used by Java to store objects that are long lived. As such this space will ...... The setting related to the Java Perm Space is only the following.

  • XX:MaxPermSize - Maximum Perm Space value

When the Maximum Perm Space size is too low for that is actually needed by the Java process, the following exception will be thrown: java.lang.OutOfMemoryError: PermGen space

(warning)  The above mentioned settings are settings that can be applied when launching a Java process command-line or form a .bat/.sh script. Certain application might provide other ways to specify the same settings, for example the Service component that is part of the Servoy distribution. For more information on how to configure these settings withing Servoy, read the next paragraph.

Server Memory management

Determining the required memory

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

  • The Servoy Application Server itself
  • The memory usage related to active/idle database connections
  • The memory usage related to running Servoy Clients

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 using the Servoy HTTP Tunnel:  assume 900kb for each Smart Client
  • Smart Client using another connection mode than the HTTP tunnel: assume 600kb for each Smart Client
  • Web Client, Headless Client & Batch processors: 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. For more guidelines, see below.

Smart Client Memory usage vs. other Servoy Client

The Smart Client runs on the client machine, not on the Servoy Application Server like the other Servoy Clients, like the Web Client, Headless Client or Batch Processor. The Smart Client is only registered with the Application Server and thus consumes far less memory on the Application Server compared to the other Servoy Clients. See #Smart Client Memory management for more information on configuring the Memory settings for Smart Clients specifically.

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:

  • Small solution (1 - 50 forms), simple user interface: 2Mb
  • Medium size solution (51 - 500 forms), average complex user interface: 10Mb
  • Large solution (> 500 forms), complex user interface: 20Mb

Configuring the memory settings

The setting that requires tuning based on the determined required memory for the Servoy Application Server is the Maximum Heap Space setting (Xmx). By default the Maximum Heap Space is set to 256MB withing Servoy. This setting should be changed when:

  • The expected load is higher (see previous paragraph for determining the required memory)
  • 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: Heap memory: allocated=549184K, used=371473K, max=699072K
  • 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.

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

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 by altering the "wrapper.java.maxmemory" setting: 

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

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, by altering the -Xmx value:

java -Djava.awt.headless=true -Xmx256m -Xms64m -XX:MaxPermSize=128m .....
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, by altering the -Xmx value:

-Xmx256m -Xms64m -XX:MaxPermSize=128m

Specifying -Xmx and -Xms values

When specifying the -Xmx and -Xms values, the following needs to be taken into account:

  • The value can only be an integer value
  • The value needs to be places directly behind the parameter, no spaces or equal signs
  • The value needs to be post fixed with the unit: "m" or "M" for megabytes, "g" or "G" for gigabytes
  • When changing the -Xms options,  make sure that the -Xmx option has a higher value
  • Both values need to be lower than the available memory on the machine
32bit Java Memory assignment limitation

(warning)   An 32 bit JVM will allow a maximum memory assignment of 2Gb in total. In order to assign more than 2Gb of memory, a 64 bit JVM on a 64 bit OS is required.

Monitoring the Memory usage

The actual memory usage of a Servoy Application Server can be observed on the Servoy Admin page. The "Servoy Server Status" overview on the "Servoy Server Home" page displays the allocated, used and maximum values for the Heap memory and all other spaces combined (non-Heap memory).

Smart Client Memory management

Similar to the Servoy Application Server, the Servoy Smart Client is also a Java application and as such the same memory management also applies to the Smart Client.

Through the Servoy Admin page, the following settings are exposed that related to the Smart Client's memory configuration:

Setting

What is does

Comment

servoy.initialClientHeap

Sets the Initial Heap Space size

 

servoy.maxClientHeap

Sets the Maximum Heap Space size

 

servoy.vmClientArgs

optional arguments that can be send to the Smart Client's JVM

Set to "-XX:SoftRefLRUPolicyMSPerMB=3600000" by default: this setting improves performance

(info)  Within the Servoy Smart Client, the actual memory usage can be monitored through the Help > About menu item. 

  • No labels