Nextcloud seems to have a bad reputation around here regarding performance. It never really bothered me, but when a comment on a post here yesterday talked about huge speed gains to be had with Postgres, I got curious and spent a few hours researching and tweaking my setup.
I thought I'd write up what I learned and maybe others can jump in with their insights to make this a good general overview.
To note, my installation initially started out with this docker compose stack from the official nextcloud docker images (as opposed to the AIO image or a source installation.) I run this behind an NGINX reverse proxy.
Sources of information
Server tuning on Nextcloud Docs: Most of this are very basic things that are already taken care of in the docker image or in the proxy companion image I'm using. The one thing I haven't tried and that comes up in other places, too, is using Imaginary for image preview generation.
Eking out some Nextcloud Performance mainly talks about using a socket connection for redis, but also mentions logging to syslog (have not found a good source of information for this), using postgres, using imaginary for image previews
Improvements
Migrate DB to Postgres
What I did first is migrate from maridb to postgres, roughly following the blog post I linked above. I didn't do any benchmarking, but page loads felt a little faster after that (but a far cry from the "way way faster" claims I'd read.)
Here's my process
add postgres container to compose file like so. I named mine "postgres", added a "postgres" volume, and added it to depends_on for app and cron
run migration command from nextcloud app container like any other occ command. The migration process stopped with an error for a deactivated app so I completely removed it, dropped the postgres tables and started migration again and it went through. after migration, check admin settings/system to make sure Nextcloud is now using postgres. ./occ db:convert-type --password $POSTGRES_PASSWORD --all-apps pgsql $POSTGRES_USER postgres $POSTGRES_DB
remove old "db" container and volume and all references to it from compose file and run docker compose up -d --remove-orphans
Redis over Sockets
I followed above guide for connecting to Redis with sockets with details as stated below. This improved performance quite significantly. Very fast loads for files, calendar, etc. I haven't yet changed the postgres connection over to sockets since the article spoke about minor improvements, but I might try this next.
Hints
the redis configuration (host, port, password, ...) need to be set in config/config.php, as well as config/redis.config.php
the cron container needs to receive the same /etc/localtime and /etc/timezone volumes the app container did, as well as the volumes_from: tmp
EDIT Postgres over Sockets
I'm now connecting to Postgres over sockets as well, which gave another pretty significant speed bump. When looking at developer tools in Firefox, the dashboard now finishes loading in half the time it did before the change; just over 6s. I followed the same blog article I did for Redis.
Steps
in the compose file, for the db container: add volumes /etc/localtime and /etc/timezone; add user: "70:33"; add command: postgres -c unix_socket_directories='/var/run/postgresql/,/tmp/docker/'; add tmp container to volumes_from and depends_on
in nextcloud config.php, replace 'dbhost' => 'postgres', with 'dbhost' => '/tmp/docker/',
Outlook
What have you done to improve your instance's performance? Do you know good articles to share? I'm happy to edit this post to include any insights and make this a good source of information regarding Nextcloud performance.
Using NGINX over Apache did nothing for me, so I use Apache with PHP-FPM 8.3, because I am using it for Wordpress too, same for Redissockets. I would recommend not to use a docker container for Nextcloud. I don't like it for Nextcloud and I don't use docker for Wordpress. Docker has other use cases in my setup, but not those 2.
Try MySQL instead of MariaDB. They have some performance tweaks in version 10 that aren't present in MariaDB.
Also, tune your MySQL (or MariaDB) server. Make sure all tables use InnoDB. Enable the slow query log and analyze slow queries (there may be missing indices). If there's a lot of unique queries, increase the query cache size.
The easy approach is to run MySQLTuner after the MySQL or MariaDB server has been up for at least a week, and go through its suggestions.
There shouldn't be a significant difference in performance between PostgreSQL and MySQL/MariaDB if both have been optimized. Out-of-the-box config isn't ideal for a production system.
I've been a proponent here for a few months on using postgres/redis every time someone shits on NC for performance. While I agree the database change itself isn't a huge improvement, it pays for itself long term in larger volume installs when you and your organization/group get using it heavily. The redis connected on socket like the AIO mastercontainer sets up is where the real juice comes from, but only on an install that gets used so it caches properly. The first time you fire it up, it's pretty slow but as it gets used, things are much better.
Very anecdotally, I saw a little speed improvement but not all that much. DB size increased a bit. I'll be sticking with it for the time being because why not.
Is there a way to self-host nextcloud by downloading one file, docker container, .nzb, .jpg, ANYTHING that includes all these parts and can just plug in and run? Is that a thing, or do all self-hosters spend every waking hour sudo updating?
Nextcloud AIO or all in one. It works relatively well. I run both my own container and an AIO instance and I've been pretty happy with it, I'll likely migrate to it for my docker only one in the near future. Nextcloud AIO
I didn't think Nextcloud AIO would actually work with existing files on a separate drive. I know it says it will ... but ....
I'm not interested in buying a gigantic new harddrive to clone all my data to just to run one program.
Also, if it's running in WSL or a VirtualBox VM it would be fucking hell to get it to play nice with the network.
ive tried to get nextcloud working several times and it just seems to never work for some reason... maybe i should set it up on a pi ive got laying around instead of my main server lol
im not sure / cannot recall. it's been a few months since i last tried to install it and it kept erroring out. im definitely strongly considering looking back into it though, it's just that reverse proxying to the container was a nightmare... it still haunts my config, lol
that is... surprising. not that i don't believe you, snap just doesn't have a good track record, lol. ill have to research if it's feasible to run a snap package on a debian server, though.
I wonder what performance impact there would be if you were to move pgsql onto bare metal with enough ram dedicated to caching all of the db data (think: i5 or i7 nuc). That's going to be my next step with my homelab; I want to migrate everything to a single db host with a lot of RAM and M2 storage and avoid the db process replication I have going on. I have no performance complaints with NC currently, I'm running PHP cache and redis as well as image preview and imaginary.
I had been running Nextcloud on an old laptop using Ubuntu, but that machine died. I have a Windows PC originally built for gaming that I am considering using for Nextcloud. Anyone have any experience with NC and Windows? Thought on the DB switch on Windows?
100% agree with tofubi, Docker on Windows is a form of self-abuse, like cutting yourself. It's a train wreck for anything other than a little bit of testing for development work. You will come away with a bad taste in your mouth about Docker, I avoided containers for years because I started with them on Windows docker.
I've run a lot of different scenarios with docker, what I've come down to as the cleanest and easiest to maintain is Debian 12 with the Docker convenience script. It's fast, hassle free, and doesn't have a bunch of layers of weirdness like using Ubuntu Server with a docker snap that makes troubleshooting a nightmare.
for anything other than a little bit of testing for development work.
It's really awesome for development work, though. Visual Studio has built-in Docker support, so I can run my app and its unit tests on both Windows and Linux (via Docker) at the same time on the same system during development.
Thanks. I didn't realize syslog would help. Just configured it to send to my grafana/loki server. Not sure if it's really helping, but seems like maybe it's a bit faster. I've long since done everything listed here and more, but in the last couple months my nextcloud has seemed a bit sluggish for some reason.