Memory Settings
Overview
MailArchiva requires three different types of memory:
- Heap space - this memory is used for allocating objects inside the Java runtime environment. When running the setup, you will be prompted for this value.
- Virtual memory - this memory is used for direct buffering. For performance reasons, it is allocated outside the confines of the Java runtime environment. It represents the remaining amount of memory.
Total Physical RAM = PermGen (Program Code) + Java Heap + Virtual Memory (Direct Buffering) + OS
Since MailArchiva also allocates memory outside of the Java runtime environment, it necessary to leave at least 1/2 of available memory freely available. This memory is also needed for basic operating system functions.
Suggested Memory Settings
Linux
8 GIG Physical RAM Spec - Typical Server
Assuming, the server machine with 8 Gigs of physical RAM, the following apply:
Java Heap Space: 5192MB
4 GIG Minimum Memory Spec - Small Server
If MailArchiva is expected to deal with very little volume and the goal is to conserve as much memory as possible, the below spec applies:
Java Heap Space: 2048MB
Windows
8 GIG Physical RAM Spec - Typical Server
Assuming, the server machine with 8 Gigs of physical RAM, the following apply:
Java Heap Space: 5192MB
4 GIG Minimum Memory Spec - Small Server
If MailArchiva is expected to deal with very little volume and the goal is to conserve as much memory as possible, the below spec applies:
Java Heap Space: 2048MB
How To Change Memory Settings
Checking the Total RAM Available - MailArchiva will always use the maximum amount of RAM that you specify
Change Heap Space - Increase heap space available to MailArchiva
Checking Total RAM Available
Before, allocating more RAM, please check the physical amount of RAM that you have available.
1. Windows 7:
a) Click Start
b) From the search box, type 'ram' without the quotes
c) Click "Show how much RAM is available on this computer"
2) Linux
a) Type "top" in a terminal window
Change Heap Space
- Linux: From the commandline:
a) Run the "configure" script as follows:
b) Restart the MailArchiva server
systemctl start mailarchiva
- Windows:
a) Right click task tray applet, click Configure...
b) Select Java tab
c) Enter a higher amount for the maximum memory size
d) Restart the MailArchiva Service (this is required for the changes to take effect!)
Refer to: http://java.sun.com/docs/hotspot/HotSpotFAQ.html#gc_heap_32bit for more information.
After allocating more memory, do not be alarmed if the MailArchiva process is using the full extent of memory allocated. This is normal behaviour for Java-based applications. For more information on common memory usage patterns in Java-based applications, please refer to Out Of Memory.
Large Enterprise Server
MailArchiva runs inside a Java Virtual Machine (JVM). As such, its performance is subject to the effectiveness of the chosen garbage collection (GC) algorithm. The garbage collector (GC) is responsible for freeing up allocated memory. Different garbage collectors perform different strategies for clearing memory. Since freeing up memory is in of itself a (potentially) resource intensive process, both in terms of time and CPU cycles, GC has the potential to put a drag on application performance.
By default, MailArchiva is configured to use the G1 garbage collector. It is tuned as follows (see startserver.sh):
In large enterprise deployments with hundreds of millions of emails archived, it is often desirable/necessary to allocate a large heap (e.g. 16GB). In such cases, the use of the default G1 garbage collector is not suitable. The chart below illustrates what happens when the default G1 collector is used in combination with a large amount of allocated heap. As is illustrated, this server spends more time collecting items in the heap, than doing useful work.
Thus using the G1 collector combined with a large amount of allocated memory, will likely cause MailArchiva to become unresponsive due to an excessive amount of time spent on major collections.
In contrast, the illustration below (left chart), garbage collector activity (indicated by the thin blue line at the bottom) is kept to a minimum.
FYI: The settings below are known to work well on an enterprise server with 32GB of RAM or more. This particular server has several hundred million emails archived, with excellent response times.
export CATALINA_OPTS="-Dversion=enterpriseedition -server -Xms10g -Xmx10g -XX:NewSize=1g -XX:MaxNewSize=1g -XX:+UseParNewGC -XX:MaxTenuringThreshold=2 -XX:SurvivorRatio=8 -XX:+UnlockDiagnosticVMOptions -XX:ParGCCardsPerStrideChunk=32768 -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+ParallelRefProcEnabled -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -XX:-OmitStackTraceInFastThrow -XX:-UseSplitVerifier"
The above settings can be modified by editing the startserver script (Linux) or right click task tray applet, click Configure..., select Java tab, enter the parameters Java Options panel. Thereafter, restart the MailArchiva service for the changes to take effect.
20K Mailbox Example Configuration
The below example memory config applies to larger installations of > 20K mailboxes.
cat /opt/mailarchiva/server/startserver
# MailArchiva Enterprise Edition Start Server Script
# Visit http://www.mailarchiva.com for more information on this product
umask 022
MAILARCHIVA_HOME=/opt/mailarchiva
#LD_PRELOAD_64=/usr/lib/64/libumem.so
# tune glibc memory allocation, optimize for low fragmentation
# limit the number of arenas
export MALLOC_ARENA_MAX=2
# disable dynamic mmap threshold, see M_MMAP_THRESHOLD in "man mallopt"
export MALLOC_MMAP_THRESHOLD_=131072
export MALLOC_TRIM_THRESHOLD_=131072
export MALLOC_TOP_PAD_=131072
export MALLOC_MMAP_MAX_=65536
export JAVA_HOME=$MAILARCHIVA_HOME/jre64
export JRE_HOME=$MAILARCHIVA_HOME/jre64
#export LD_PRELOAD_64;
export CATALINA_PID=$MAILARCHIVA_HOME/mailarchiva.pid
export CATALINA_HOME=$MAILARCHIVA_HOME/server
export CATALINA_BASE=/var/opt/mailarchiva/tomcat
export JAVA_OPTS="-d64 -Dfile.encoding=UTF-8"
export JAVA_ENDORSED_DIRS=$CATALINA_HOME/endorsed
export PATH=$JAVA_HOME/bin:$PATH
export CATALINA_OPTS="-server -XX:+AggressiveOpts -Dversion=enterpriseedition -Dhardmount=yes -Xms64g -Xmx64g \
-XX:MaxDirectMemorySize=512g -Dgraphdb.cache.size=64 -Dstorage.diskCache.bufferSize=8192 \
-XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+ParallelRefProcEnabled -XX:+CMSConcurrentMTEnabled -XX:+CMSClassUnloadingEnabled \
-XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark \
-XX:CMSInitiatingOccupancyFraction=80 -XX:+UseCMSInitiatingOccupancyOnly \
-XX:+AlwaysPreTouch -XX:-OmitStackTraceInFastThrow
-Xloggc:/var/log/gc-$(date +%Y_%m_%d-%H_%M).log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime
export LC_ALL=en_US.UTF-8
ulimit -n 128000
ulimit -v unlimited
bash $MAILARCHIVA_HOME/server/bin/startup.sh
Found this information useful? Visit mailarchiva.com to learn more about MailArchiva.