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.

  • The Great King Virtue Is Dead!@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    11 months ago

    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

      • 4am@lemm.ee
        link
        fedilink
        English
        arrow-up
        2
        ·
        11 months ago

        It is, in fact, the only Snap I’ve ever used which worked without issues

        That being said, it’s kinda slow in some cases, but perfectly useable nonetheless

        • cybersandwich@lemmy.world
          link
          fedilink
          English
          arrow-up
          1
          ·
          11 months ago

          I know snap isn’t popular among Linux nerds, but I was really having issues with the AIO docker setup and at the time I didn’t have the time to troubleshoot/fight it. I needed to give my family a file drop link to share photos for a memorial service.

          I figured, the snap package was recommended on their site, maybe it won’t be horrible. To my surprise it was incredibly easy, has been rock solid, never had performance issues, and it’s always up-to-date.

          Snap may suck for some use-cases but this one seems to be right in it’s wheel house.

          It also has an export/backup capability built in.

      • The Great King Virtue Is Dead!@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        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.

    • ikidd@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 months ago

      Have you tried the AIO method that’s now the primary supported docker install?

      It’s really good, and I’ve set up and used NC in a variety of ways since about version 7.

      • The Great King Virtue Is Dead!@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        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

        • ikidd@lemmy.world
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          11 months ago

          I use NPM and all I think I had to add to it was

          client_body_buffer_size 512k;
          proxy_read_timeout 86400s;
          client_max_body_size 0;
          

          in the Advanced config. I’d love to move to Traefik but I could not figure out how to make that work.

          There were some other gotchas. If you run into something, ping me, I might remember if I encountered it and what I did.