Skip to content

Instantly share code, notes, and snippets.

@linuxmalaysia
Last active March 17, 2024 20:44
Show Gist options
  • Save linuxmalaysia/0cc0d6218fefb045f867c17eed3af7f8 to your computer and use it in GitHub Desktop.
Save linuxmalaysia/0cc0d6218fefb045f867c17eed3af7f8 to your computer and use it in GitHub Desktop.
Sysctl setting that may suitable for MariaDB

This /etc/sysctl.conf settings are generally suitable for a MariaDB Galera Cluster. Use this wisely. Execute command sysctl -p after editing /etc/sysctl.conf.

# Increase the maximum number of memory map areas a process may have
# This can help prevent out-of-memory errors in large applications
vm.max_map_count=262144

# Increase the maximum number of file handles and inode cache for large file transfers
# This can improve performance when dealing with a large number of files
fs.file-max = 3261780

# Increase the maximum buffer size for TCP
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

# Increase Linux autotuning TCP buffer limits
net.ipv4.tcp_rmem = 4096 12582912 16777216
net.ipv4.tcp_wmem = 4096 12582912 16777216

# Disable caching of ssthresh from previous TCP connection
net.ipv4.tcp_no_metrics_save = 1

# Reduce the kernel's tendency to swap
vm.swappiness = 1

# Set the default queueing discipline for network devices
net.core.default_qdisc = fq_codel

# Enable TCP BBR congestion control
net.ipv4.tcp_congestion_control=bbr

# Enable TCP MTU probing
net.ipv4.tcp_mtu_probing=1

# Increase the maximum input queue length of a network device
net.core.netdev_max_backlog = 32768

# Increase the maximum accept queue limit
net.core.somaxconn = 65535

# Reduce the number of SYN and SYN+ACK retries before packet expires
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1

# Reduce the timeout to close client connections in TIME_WAIT state
net.ipv4.tcp_fin_timeout = 30

# Disable SYN cookie flood protection
net.ipv4.tcp_syncookies = 0

# Increase the local port range used by TCP and UDP
net.ipv4.ip_local_port_range = 1024 65535

# Additional Galera Cluster optimizations
# Increase the number of allowed open files per process for MariaDB
####fs.file-max = 3261780

# Increase the number of file handles specifically for MariaDB
# Adjust according to the needs of your Galera Cluster
fs.aio-max-nr = 1048576

# https://www.suse.com/support/kb/doc/?id=000017857
# Flushing a large cache can take extensive time and force many things to wait.
# In contrast, flushing a small cache (even multiple times)  is far less disruptive.
# Good performance (for both slow storage and quick storage, and for both low RAM systems vs high RAM systems)
# does not usually require more than a few hundred megabytes of memory in dirty cache.

vm.dirty_bytes = 629145600
vm.dirty_background_bytes = 314572800
@linuxmalaysia
Copy link
Author

root@myserver:/etc/sysctl.d# cat README.sysctl
Kernel system variables configuration files

Files found under the /etc/sysctl.d directory that end with .conf are
parsed within sysctl(8) at boot time. If you want to set kernel variables
you can either edit /etc/sysctl.conf or make a new file.

The filename isn't important, but don't make it a package name as it may clash
with something the package builder needs later. It must end with .conf though.

My personal preference would be for local system settings to go into
/etc/sysctl.d/local.conf but as long as you follow the rules for the names
of the file, anything will work. See sysctl.conf(8) man page for details
of the format.

After making any changes, please run "service procps force-reload" (or, from
a Debian package maintainer script "deb-systemd-invoke restart procps.service").

===

To check status:

systemctl status systemd-sysctl.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment