Tuning my server. NC manual says 'always prevent swap usage'. What does this mean?

I’m trying to tune the performance of my Nextcloud server.
In the Nextcloud manual, there is a recommendation I feel I need to understand better. It says:

"First you should make sure that you installed/assigned enough RAM. Swap usage should be prevented by all means. " (https://docs.nextcloud.com/server/latest/admin_manual/installation/server_tuning.html)

My server is for up to 5 people simultaneous use, on a 250Mbit connection. It’s running Ubuntu Server 22.10, with 16GB RAM and a Quad core 2.5ghz I5 CPU. Ubuntu Server with Nextcloud fully installed consumes about 700mb of RAM on my machine, when idle. Nextcloud is allowed to use up to 12GB of the 16GB (set in php.ini)

What is “Swap Usage”, as referred to in the manual?
Does it refer to that I should prevent Ubuntu Server from utilizing any form of a harddrive Swap file?
I’m not even sure Ubuntu Server utilizes a swap file?
And if so still, is it realistic to suspect that my machine and NC usage will ever require more than the 12GB of RAM I’ve assigned to it?

Is someone would care to clarify a bit more, I’m sure I could take it from there and tune it up as best as possible according to the manual.
Thanks

You don’t have to worry about swaping with your configuration with 16GB of ram. I have more users and half of the ram, and I don’t have any overflow either.
The biggest users of ram are mysql and clamd (if in use).

Yes, of course, Ubuntu uses swap, either as swap files or as a separate partition. You can find out the size of your swap space with free

If you don’t have any swap space, you should, for the sake of security create some.

Here is, how you create a swapfile from 8Gb of size:

sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
sudo chmod 0600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

You can, at any time see how much swap space is in use either with free or in realtime live with top.

If you want to “cleanup” swap space, you can do it with

sudo swapoff -va && sudo swapon -va

but be carefull, only do that, with enough free ram (but ram is not your problem anyway).

Happy hacking

1 Like

Is there something specific you are tuning/improving performance for, or is this preventative/preemptive? Take a few measurements if you haven’t already. Time some web responses, running a few commands on the server. Measure whatever is meaningful to your users/workloads and is repeatable.

In case this helps: when I set up Nextcloud I used mostly defaults, set up an RDBMS (MariaDB), and Redis for caching. It feels fast enough. It runs in Docker on a server with lots of RAM and CPU and spinning hard drives.

When the Nextcloud admin manual author says “swap usage” they are warning us against thrashing.

It is good to have swap space set up and you can check your swap situation with free as @ernolf mentioned or with swapon --show. I’ve no experience with the “cleanup” procedure they mention.

If performance is poor (say, you try ls /tmp and it hangs, or Nextcloud web responses take many seconds), the OS may be thrashing. Diagnosing this precisely can be tricky, and probably unnecessary. You’re good with 16 GB physical RAM if it feels responsive.

That said, I just learned about PSI - pressure stall information. If you’re curious, check out PSI numbers in atop or tail /proc/pressure/*. i see almost all zeros on a laptop and some 1s for io pressure values on a presumably healthy server running Nextcloud (and a bunch of other stuff).

Tough to say for sure. Roughly: if you keep to 5 users with the same usage patterns you should be good until the disk fills up.

If you measure Nextcloud web responses, you might try timing (1) how long it takes until https://NEXTCLOUD/apps/files/ loads, and then (2) navigate through a few folders. I get (1) from the Firefox developer tools “Network” tab: it shows up as load in a status line at the bottom. I’m seeing about 1.4 sec for this value on that same “healthy” server I mentioned above. For (2) I just click a couple folders and it feels almost instant. If navigating folders feels slow at all I start worrying. The Talk and Photos apps always feel slow to me so I mainly try to avoid them (for timing and in general). Maybe I could do something to speed those up.