Recommended production settings

Recommended settings for Linux platforms on the DataStax Distribution of Apache Cassandra 3.11.

Use the latest Java Virtual Machine

Configure your operating system to use the latest build of a Technology Compatibility Kit (TCK) Certified OpenJDK version 8. For example, OpenJDK 8 (1.8.0_151 minimum).
Tip: Although Oracle JRE/JDK 8 is supported, DataStax does more extensive testing on OpenJDK 8. This change is due to the end of public updates for Oracle JRE/JDK 8.
Java 9 is not supported.

Synchronize clocks

Synchronize the clocks on all nodes and application servers. Use NTP (Network Time Protocol) or other methods.

This is required because DataStax Distribution of Apache Cassandra™ (DDAC) overwrites a column only if there is another version whose timestamp is more recent, which can happen when machines in are different locations.

Cassandra timestamps are encoded as microseconds since UNIX epoch without timezone information. The timestamp for all writes in Cassandra is UTC (Universal Time Coordinated). DataStax recommends converting to local time only when generating output to be read by humans.

TCP settings

During low traffic intervals, a firewall configured with an idle connection timeout can close connections to local nodes and nodes in other data centers. To prevent connections between nodes from timing out, set the following network kernel settings:

sudo sysctl -w \
net.ipv4.tcp_keepalive_time=60 \
net.ipv4.tcp_keepalive_probes=3 \

These values set the TCP keepalive timeout to 60 seconds with 3 probes, 10 seconds gap between each. The settings detect dead TCP connections after 90 seconds (60 + 10 + 10 + 10). There is no need to be concerned about the additional traffic as it’s negligible; permanently leaving these settings isn’t an issue. See Firewall idle connection timeout causing nodes to lose communication during low traffic times on Linux .

To the handle thousands of concurrent connections used by the database, change these Linux kernel settings:

sudo sysctl -w \
net.core.rmem_max=16777216 \
net.core.wmem_max=16777216 \
net.core.rmem_default=16777216 \
net.core.wmem_default=16777216 \
net.core.optmem_max=40960 \
net.ipv4.tcp_rmem=4096 87380 16777216 \
net.ipv4.tcp_wmem=4096 65536 16777216
To persist the TCP settings:
  1. Add the following to the /etc/sysctl.conf file:
    net.ipv4.tcp_rmem=4096 87380 16777216
    net.ipv4.tcp_wmem=4096 65536 16777216
  2. Load the settings using one of the following commands:
sudo sysctl -p /etc/sysctl.conf
sudo sysctl -p /etc/sysctl.d/filename.conf

Disable CPU frequency scaling

Recent Linux systems include a feature called CPU frequency scaling or CPU speed scaling. It allows a server's clock speed to be dynamically adjusted so that the server can run at lower clock speeds when the demand or load is low. This reduces the server's power consumption and heat output (which significantly impacts cooling costs). Unfortunately, this behavior has a detrimental effect on servers running Cassandra because throughput can get capped at a lower rate.

On most Linux systems, a CPUfreq governor manages the scaling of frequencies based on defined rules and the default ondemand governor switches the clock frequency to maximum when the demand is high and switches to the lowest frequency when the system is idle.

Do not use governors that lower the CPU frequency. To ensure optimal performance, reconfigure all CPUs to use the performance governor, which locks the frequency at maximum. This governor will not switch frequencies, which means there will be no power savings but the servers will always run at maximum throughput. On most systems, set the governor as follows:
for CPUFREQ in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
    [ -f $CPUFREQ ] || continue
    echo -n performance > $CPUFREQ

For more information, see High server load and latency when CPU frequency scaling is enabled in the DataStax Help Center.

Make sure that new settings persist after reboot

CAUTION: Depending on your environment, some of the following settings may not be persisted after reboot. Check with your system administrator to ensure they are viable for your environment.

Optimize SSDs

The default SSD configurations on most Linux distributions are not optimal. Follow these steps to ensure the best settings for SSDs:

  1. Ensure that the SysFS rotational flag is set to false (zero).

    This overrides any detection by the operating system to ensure the drive is considered an SSD.

  2. Apply the same rotational flag setting for any block devices created from SSD storage, such as mdarrays.
  3. Set the IO scheduler to either deadline or noop:
    • The noop scheduler is the right choice when the target block device is an array of SSDs behind a high-end IO controller that performs IO optimization.
    • The deadline scheduler optimizes requests to minimize IO latency. If in doubt, use the deadline scheduler.
  4. Set the readahead value for the block device to 8 KB.

    This setting tells the operating system not to read extra bytes, which can increase IO time and pollute the cache with bytes that weren’t requested by the user.

    For example, if the SSD is /dev/sda, in /etc/rc.local:

    echo deadline > /sys/block/sda/queue/scheduler
    #echo noop > /sys/block/sda/queue/scheduler
    touch /var/lock/subsys/local
    echo 0 > /sys/class/block/sda/queue/rotational
    echo 8 > /sys/class/block/sda/queue/read_ahead_kb

Use the optimum --setra setting for RAID on SSD

The optimum readahead setting for RAID on SSDs (in Amazon EC2) is 8KB, the same as it is for non-RAID SSDs. For details, see Optimizing SSDs.

Disable zone_reclaim_mode on NUMA systems

The Linux kernel can be inconsistent in enabling/disabling zone_reclaim_mode. This can result in odd performance problems

To ensure that zone_reclaim_mode is disabled:
echo 0 > /proc/sys/vm/zone_reclaim_mode

For more information, see Peculiar Linux kernel performance problem on NUMA systems.

Set user resource limits

Use the ulimit -a command to view the current limits. Although limits can also be temporarily set using this command, DataStax recommends making the changes permanent:

If you run Cassandra as root, some Linux distributions such as Ubuntu, require setting the limits for root explicitly instead of using cassandra_user:
root - memlock unlimited
root - nofile 1048576
root - nproc 32768
root - as unlimited
For RHEL 6.x-based systems, also set the nproc limits in /etc/security/limits.d/90-nproc.conf:
cassandra_user - nproc 32768
For all installations, add the following line to /etc/sysctl.conf:
vm.max_map_count = 1048575
For installations on Debian and Ubuntu operating systems, the module is not enabled by default. Edit the /etc/pam.d/su file and uncomment this line:
session    required
This change to the PAM configuration file ensures that the system reads the files in the /etc/security/limits.d directory.
To make the changes take effect, reboot the server or run the following command:
sudo sysctl -p
To confirm the limits are applied to the Cassandra process, run the following command where pid is the process ID of the currently running Cassandra process:
cat /proc/pid/limits

For more information, see Insufficient user resource limits errors.

Disable swap

Failure to disable swap entirely can severely lower performance. Because the database has multiple replicas and transparent failover, it is preferable for a replica to be killed immediately when memory is low rather than go into swap. This allows traffic to be immediately redirected to a functioning replica instead of continuing to hit the replica that has high latency due to swapping. If your system has a lot of DRAM, swapping still lowers performance significantly because the OS swaps out executable code so that more DRAM is available for caching disks.

If you insist on using swap, you can set vm.swappiness=1. This allows the kernel swap out the absolute least used parts.

sudo swapoff --all

To make this change permanent, remove all swap file entries from /etc/fstab.

For more information, see Nodes seem to freeze after some period of time.

Check the Java Hugepages setting

Many modern Linux distributions ship with Transparent Hugepages enabled by default. When Linux uses Transparent Hugepages, the kernel tries to allocate memory in large chunks (usually 2MB), rather than 4K. This can improve performance by reducing the number of pages the CPU must track. However, some applications still allocate memory based on 4K pages. This can cause noticeable performance problems when Linux tries to defrag 2MB pages. For more information, see the Cassandra Java Huge Pages blog and this RedHat bug report.

To solve this problem, disable defrag for hugepages. Enter:
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag

Set the heap size for optional Java garbage collection in Cassandra

The default JVM garbage collection (GC) for Cassandra is G1.
Note: DataStax does not recommend using G1 when using Java 7. This is due to a problem with class unloading in G1. In Java 7, PermGen fills up indefinitely until a full GC is performed.

Heap size is usually between ¼ and ½ of system memory. Do not devote all memory to heap because it is also used for offheap cache and file system cache.

The easiest way to determine the optimum heap size for your environment is:
  1. Set the MAX_HEAP_SIZE in the file to a high arbitrary value on a single node.
  2. View the heap used by that node:
    • Enable GC logging and check the logs to see trends.
  3. Use the value for setting the heap size in the cluster.
Note: This method decreases performance for the test node, but generally does not significantly reduce cluster performance.

If you don't see improved performance, contact the DataStax Services team for additional help in tuning the JVM.

Determining the heap size when using Concurrent-Mark-Sweep (CMS) garbage collection

There are many nuances for tuning CMS. It requires time, expertise, and repeated testing to get the best results. DataStax recommends contacting the DataStax Services team instead. Tuning Java resources provides the basic information to get you started.

Set the heap size for optimal Java garbage collection

See Tuning Java resources.

Apply optimum blockdev --setra settings for RAID on spinning disks

Typically, a readahead of 128 is recommended.

Check to ensure setra is not set to 65536:

sudo blockdev --report /dev/spinning_disk

To set setra:

sudo blockdev --setra 128 /dev/spinning_disk
Note: The recommended setting for RAID on SSDs is the same as that for SSDs that are not being used in a RAID installation. For details, see Optimizing SSDs.

  • The file is located in the installation_location/conf directory.