133
submitted 10 months ago* (last edited 10 months ago) by tofubl@discuss.tchncs.de to c/selfhosted@lemmy.world

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

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.

you are viewing a single comment's thread
view the rest of the comments
[-] morethanevil@lemmy.fedifriends.social 17 points 10 months ago

"Way faster" came from me :D

It is the complete package which makes it way faster...

Postgres, Redis, PHP Opcache, general PHP tweaks ( PHP.ini, child processes etc, use calculator ), HTTP-2 instead of 1.1

For HTTP-2, you can add this for Apache in your vhost:

Protocols h2 h2c http/1.1

For example:

<VirtualHost *.80>
ServerAdmin admin@server.com
DocumentRoot /var/www/html/nextcloud/
ServerName my.domai.com
Protocols h2 h2c http/1.1

....

In NGNIX add this in a new line:

http2 on;

For example:

server {
  listen 80;
  listen [::]:80;
  server_name my.domain.com;
  http2 on;

....

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.

This is just my personal setup.

Maybe it can help someone :)

[-] tofubl@discuss.tchncs.de 5 points 10 months ago

That makes sense. If you start out without any of those I'm sure it's night and day.

Thanks for the additional input!

There are no slow nextclouds, only wrong configured ones ☝🏻😁

this post was submitted on 31 Dec 2023
133 points (99.3% liked)

Selfhosted

39683 readers
540 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS