Tuning system parameters is used to increase the responsiveness and performance of the server. Do not rush to buy new hardware, maybe the main point is in software. To get started, analyze the load on the server and test your website for the load.

File system

First, make sure that you are using the ext4 file system:

# Will be displayed in the Type column

If the file system is Ext3, then it is recommended to transfer it to Ext4 – a more productive and improved version.

Virtual memory

To perform time-consuming tasks, is used virtual memory (swap) – when RAM is full, part of the program is transferred to the hard drive. Thus, you can use more RAM than there is in the system.

The approach doesn’t make sense in systems with a large amount of RAM, especially since the RAM is faster than constant memory. It is also not recommended to use Swap on a server with SSDs – it significantly reduces the storage life (frequent write and read processes).

Ubuntu by default unloads data when RAM is 40% full.

To configure swap, use the vm.swappiness parameter, the value of which must be entered or edited in the sysctl.conf configuration file:

After that, you need to save the file and reboot the system. To verify that the new parameter is enabled, you need to execute:

# In the first case, it applies displays all the parameters of the file, in the second – selects the desired parameter among all possible variables

Caching can improve system performance. But if the web server performs a large number of read / write operations, then additional caching can slow down I / O.

Caching options can be configured:

# Parameters responsible for dirty pages – data that needs to be written to disk or sent to swap

Parameters mean:

  • dirty_background_ratio – percentage of system memory that dirty pages can fill before background processes pdflush / flush / kdmflush write them to disk;
  • dirty_ratio – the maximum amount of system memory that dirty pages can fill;
  • dirty_background_bytes and vm.dirty_bytes – two previous points, only in bytes; parameters are interchangeable;
  • dirty_expire_centisecs – the time during that data can be stored in the cache, in our case, 30 s;
  • dirty_writeback_centisecs – how often pdflush / flush / kdmflush processes check the cache.

The amount of data that is waiting for recording can be viewed like this:

# 878 dirty pages awaiting recording

To reduce the size of the cache for reducing the possibility of losing important data during a crash and minimize possible write / read delays, you must edit the vm.dirty_background_ratio and vm.dirty_ratio parameters:

# Values ​​are written by sysctl.conf

IPv6

A mixed IPv4 / IPv6 environment can interrupt network-connected programs due to unintended protocol interactions. For example, by failure to connect apt or ssh to an IPv6 network, device incompatibility.

To disable IPv6:

# Temporarily disable IPv6 on all interfaces

And to permanently disable the protocol, you need to edit the /etc/sysctl.conf file:

# To apply the new parameters, just enter sudo sysctl -p /etc/sysctl.conf

Processes

Background processes can seriously load system memory. The sysv-rc-conf utility will help you here:

# Tool installation

sysv-rc-conf allows you to disable unnecessary services to speed up and optimize system resources.

After a clean installation, Ubuntu Server contains a minimum of services, only the most necessary. But if the server is used for a long time, then the list of processes can be extensive and will depend on the programs that you yourself installed.

If the desktop version is used, then here is a small list of services that can be disabled (if the system works as a server):

  • alsa and alsa-utils – sound subsystems;
  • atd – scheduler, not needed if there is a cron;
  • bluez-utiles – Bluetooth service;
  • cupsys – printer management subsystem;
  • dns-clean – DNS cleaning service when using dial-up;
  • fetchmail – email delivery service;
  • gdm – desktop manager (GUI);
  • gdomap – GNUstep support service;
  • hibernate – hibernation service;
  • hotkey-setup – hotkey support;
  • hotplug and hotplug-net – hot-plug devices;
  • ifrename – a network interface naming service;
  • laptop-mode – laptop mode, not needed on the server;
  • ppp and ppp-dns – services for connecting through a modem;
  • winbind, smbd, and nmbd are part of Samba and are needed for sharing with Windows devices.

The main recommendation – do not disable unknown processes, use the manual and Google.

The most important thing

Before starting optimization, you need to diagnose the system and identify weaknesses. Mindless tuning can only exacerbate the situation. Profiling will help to identify problem areas during the operation of the web server. Optimize your web server settings (Nginx and Apache), implement HTTP / 2.