Sitemap
Brij

Brij

Engineer | High Performance Computeting(HPC) | Real-Time Solutioning | Investor | Learner

Optimize Linux for high performance Java Services

3 min readApr 1, 2023

--

Press enter or click to view image in full size
Linux Tuning for Java

Tuning up a server for Java process involves optimizing the server’s configuration settings to ensure that it can handle the resource requirements of the Java application. Tuning is separated in 2 categories JVM and Operating System.

My primary focus is on developing high-performance services that operate with minimal latency, particularly for stock exchange-related services and trading terminals.

Here are some steps you can take

JVM Tuning

Adjust memory settings(-Xmx and -Xms)

The amount of memory allocated to the Java process should be adjusted to ensure optimal performance. The memory settings can be adjusted by modifying the -Xmx and -Xms flags in the Java command line. These flags control the maximum and initial heap size, respectively.

Configure garbage collection( -XX:+UseG1GC )

The garbage collection process can be tuned to optimize performance. The -XX:+UseG1GC flag can be used to enable the G1 garbage collector, which provides better performance than the default garbage collector in most cases. Other flags, such as -XX:MaxGCPauseMillis, can be used to adjust the maximum pause time for garbage collection.

Get Brij’s stories in your inbox

Join Medium for free to get updates from this writer.

If parallel garbage collection is used then -XX:ParallelThreads flag can be used to adjust the no. of thread used for GC.

Operating System Tuning

Open Files

The maximum number of open files that can be handled by a Linux server can be configured through the file “/etc/security/limits.conf”

sudo vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535

Note: The asterisk (*) indicates that the settings apply to all users on the server.

Increase Backlog Count

This parameter controls the maximum size of the listen queue, which is the queue of incoming connections waiting to be accepted by the server.

sudo vi /etc/sysctl.conf

Add the following line at the end of the file

net.core.somaxconn = 2000

Memory Mapping limit

If the process consumes a significant amount of memory, typically exceeding 50GB, you may receive a warning from the JVM. In such cases, the process can fail abruptly if the mappings exceed the limit.

‘*** WARNING! INCORRECT SYSTEM CONFIGURATION DETECTED! ***’
Please adjust /proc/sys/vm/max_map_count

sudo vi /etc/sysctl.conf

Add the following line at the end of the file:

vm.max_map_count = 200000

Swappiness

vm.swappiness is a kernel parameter in Linux that controls the tendency of the kernel to swap out inactive memory pages to the swap space on disk. Swapping is the process of moving some parts of the memory to the swap space when the physical memory (RAM) is full. This parameter determines the threshold at which the kernel starts swapping out pages from memory to the swap space.

vm.swappiness parameter has a value between 0 and 100.
The default value of vm.swappiness is usually set to 60.

low vm.swappiness value (0–10) can be useful in systems with low RAM or when running applications that require large amounts of memory. However, setting vm.swappiness too low can cause a buildup of inactive memory pages that are not swapped out to the swap space, leading to out-of-memory errors or system freezes. On the other hand, a high vm.swappiness value (60–100) can be useful on systems with a large amount of RAM, as it can help the system to make better use of the available memory.

sudo sysctl vm.swappiness=10

I will continue to update the list whenever a configuration or setting is utilized on my production servers.

--

--

Brij

Written by Brij

Engineer | High Performance Computeting(HPC) | Real-Time Solutioning | Investor | Learner