Nextcloud extremly slow

I have been using nextcloud in its current configuration for several years. I’m up to date with system updates and nextcloud.
Nextcloud was never a speed demon, but now it’s just a disaster. Opening the page takes up to 1 minute.
Previously slow operation, I had the impression that it was due to the hardware. However, I installed PhotoPrism, which uses the directory where nextcloud stores photos. Photoprism has no performance problems, entire albums load very quickly, without delays.
After recent system updates (docker, docker-copose), nextcloud’s performance is unacceptable. I have done all mariadb and mysql updates. Did not help. I downgraded docker-ce because portainer had trouble opening the bash console.

I checked everything I could. Previously, when using nextcloud, the CPU load reached 100%. Currently it uses a maximum of 15%.

<?php
$CONFIG = array (
  'instanceid' => '***',
  'passwordsalt' => '*******',
  'secret' => '*******',
  'trusted_domains' =>.
  array (
    0 => '***.duckdns.org',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '28.0.3.2',
  'overwrite.cli.url' => '***.duckdns.org',
  'overwritehost' => '***.duckdns.org',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '*****',
  'installed' => true,
  'default_phone_region' => 'ISO 3166-2:PL',
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' =>.
  array (
    0 =>.
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 =>.
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'maintenance' => false,
  'theme' => '',
  'debug' => true,
  'loglevel' => 1,
  'categoryList' => '',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'gmail.com',
  'mail_smtpport' => '587',
  'mail_from_address' => '****',
  'mail_smtphost' => 'smtp.gmail.com',
  'mail_smtpauthtype' => 'LOGIN',
  'enable_previews' => true,
  'enabledPreviewProviders' =>.
  array (
    0 => 'OC\\Preview\\Movie',
    1 => 'OC\\Preview\\PNG',
    2 => 'OC\\Preview\\JPEG',
    3 => 'OC\\Preview\\GIF',
    4 => 'OC\\Preview\\BMP',
    5 => 'OC\\Preview\\XBitmap',
    6 => 'OC\\Preview\\MP3',
    7 => 'OC\\Preview\\MP4',
    8 => 'OC\\Preview\\AVI',
    9 => 'OC\\Preview\\MKV',
    10 => 'OC\\Preview\\TXT',
    11 => 'OC\\Preview\\MarkDown',
    12 => 'OC\\Preview\\PDF',
    13 => 'OC\\Preview\\HEIC',
    14 => 'OC\\Preview\\HEVC',
  ),
  'updater.release.channel' => 'stable',
  0 => 'opcache.save_comments = 1',
  1 => 'opcache.revalidate_freq = 60',
  2 => 'opcache.validate_timestamps = 0',
  3 => 'php_memory_limit=1G',
  4 => 'upload_max_filesize=16G',
  5 => 'php_upload_limit=16G',
  'memories.exiftool' => '/var/www/html/custom_apps/memories/bin-ext/exiftool-amd64-glibc',
  'memories.ffmpeg_path' => 'ffmpeg',
  'memories.ffprobe_path' => 'ffprobe',
  'mail_smtpdebug' => false,
  'memories.vod.path' => '/var/www/html/custom_apps/memories/bin-ext/go-vod-amd64',
  'memories.vod.ffmpeg' => '/usr/bin/ffmpeg',
  'memories.vod.ffprobe' => '/usr/bin/ffprobe',
  'filelocking.enabled' => true,
  'trusted_proxies' =>.
  array (
    0 => '127.0.0.1',
    1 => '192.168.1.25',
  ),
  'mail_smtpauth' => 1,
  'mail_smtpname' => '**********************',
  'mail_smtppassword' => '*******************',
  'maintenance_window_start' => 1,
  'preview_max_memory' => 512,
  'app_install_overwrite' =>.
  array (
    0 => 'metadata',
  ),
);

I also have errors (example):

 Error   cron   Doctrine\DBAL\Exception:                                             2024-03-22T23:10:01+00:00
                 Failed to connect to
                 the database: An
                 exception occurred in
                 the driver:
                 SQLSTATE[HY000] [2002]
                 Connection refused at
                 lib/private/DB/Connection.php
                 line 139

                  0. .../Connection.php line 1654
                     OC\DB\Connection->connect(

                     )
                  1. .../Connection.php line 1081
                     Doctrine\DBAL\Connection->getWrappedConnection(

                     )
                  2. .../Connection.php line 261
                     Doctrine\DBAL\Connection->executeQuery(
                       ... `",
                       ... [],
                       ... [],
                       ... ll
                     )
                  3. .../QueryBuilder.php line 337
                     OC\DB\Connection->executeQuery(
                       "SELECT ... `",
                       ... [],
                       ... [],
                       ... ll
                     )
                  4. .../QueryBuilder.php line 377
                     Doctrine\DBAL\Query\QueryBuilder->executeQuery(

                     )
                  5. .../QueryBuilder.php line 280
                     Doctrine\DBAL\Query\QueryBuilder->execute(

                     )
                  6. .../AppConfig.php line 421
                     OC\DB\QueryBuilder\QueryBuilder->execute(

                     )
                  7. .../AppConfig.php line 187
                     OC\AppConfig->loadConfigValues(

                     )
                  8. .../AppConfig.php line 377
                     OC\AppConfig->getApps(

                     )
                  9. .../AppManager.php line 128
                     OC\AppConfig->getValues(
                       ... se,
                       ... d"
                     )
                 10. .../AppManager.php line 149
                     OC\App\AppManager->getInstalledAppsValues(

                     )
                 11. .../OC_App.php line 231
                     OC\App\AppManager->getInstalledApps(

                     )
                 12. .../Coordinator.php line 90
                     OC_App::getEnabledApps(

                     )
                 13. .../base.php line 700
                     OC\AppFramework\Bootstrap\Coordinator->runInitialRegistration(

                     )
                 14. .../base.php line 1200
                     OC::init(

                     )
                 15. cron.php line 43
                     require_once(
                       "\/var\/www\/html\/lib\/base ... p"
                     )

  Error   PHP    Error: Class                                                         2024-03-24T10:58:56+00:00
                 "OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin"
                 not found at
                 /var/www/html/remote.php#62

I have no idea what else I can do.

For your last error i found this old issue. Do you have apcu correct installed? With linux version do you use? Maybe you can upgrade and use newer php packages.

Can you deactivate this line in config.php for a test?

memcache.local' => '\\OC\\Memcache\\APCu',

Memory caching

Please post also some information from your CRON. How do you execute it? Excute it manually and post logs.

I have deactivated this line. Nothing has changed.

memcache.local' => '\\OC\\Memcache\\APCu',

I will attach my docker-compose.yml file:

version: '3'
services:
  proxy:
    image: jwilder/nginx-proxy:alpine
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
    container_name: nextcloud-proxy
    networks:
      - nextcloud_network
    ports:
      - 8080:80
      - 450:443
    volumes:
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/proxy/conf.d:/etc/nginx/conf.d:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/proxy/vhost.d:/etc/nginx/vhost.d:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/proxy/html:/usr/share/nginx/html:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5//docker_apps/proxy/certs:/etc/nginx/certs:ro
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: unless-stopped
  letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nextcloud-letsencrypt
    depends_on:
      - proxy
    networks:
      - nextcloud_network
    volumes:
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/proxy/certs:/etc/nginx/certs:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/proxy/vhost.d:/etc/nginx/vhost.d:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5//docker_apps/proxy/html:/usr/share/nginx/html:rw
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    restart: unless-stopped

  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    container_name: nextcloud-mariadb
    networks:
      - nextcloud_network
    volumes:
      - /srv/dev-disk-by-uuid-a6ae5cf3-5903-42a6-a048-c2ef5bf9b047/docker_sys/nextcloud-db:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_ROOT_PASSWORD=*****
      - MYSQL_PASSWORD=*****
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - PUID=1000
      - PGID=100
    restart: unless-stopped
  cache:
    image: redis:latest
    container_name: nextcloud-cache
    restart: always
    networks:
      - nextcloud_network
    ports:
      - 6379:6379
    command: redis-server --save 20 1 --loglevel warning --requirepass eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81
    volumes:.
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_data/redis:/data
  app:
    image: nextcloud:latest
    container_name: nextcloud-app
    networks:
      - nextcloud_network
    depends_on:
      - letsencrypt
      - proxy
      - db.
      - cache
    volumes:
      - nextcloud:/var/www/html
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/nextcloud2/config:/var/www/html/config:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/nextcloud2/custom_apps:/var/www/html/custom_apps:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_data/nextcloud:/var/www/html/data:rw
      - /srv/dev-disk-by-uuid-ae454b77-822f-45bc-95cd-6bae521e2cf5/docker_apps/nextcloud2/themes:/var/www/html/themes:rw
      - /etc/localtime:/etc/localtime:ro
    environment:
      - VIRTUAL_HOST=******.duckdns.org
      - LETSENCRYPT_HOST=*****.duckdns.org
      - LETSENCRYPT_EMAIL=****
      - TZ=Europe/Warsaw
    restart: unless-stopped
volumes:
  nextcloud:
  db:
  cache:
    driver: local
networks:
  nextcloud_network:

nextcloud-app:

php --version
PHP 8.2.17 (cli) (built: Mar 16 2024 01:08:19) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.17, Copyright (c) Zend Technologies

Debian GNU/Linux 12 (bookworm)
5.10.0-0.bpo.9-amd64

Did you check hardware issues through dmesg? Once my nextcloudpi has become very slow because of cache errors on external hdd with btrfs.
Also once there was an performance issue after enabling nextcloud office app.

I don’t see anything in dmesg. Is it possible that updating docker-ce and docker-compose broke something?
Someone once mentioned performance and docker version issues, but that was with version 25…

  'debug' => true,

Turn off debugging. It’ll slow down all sorts of things. It even messes with the front-end code bundles. It should not be enabled unless you’re doing development and certainly not on a production server.

These above lines are bogus. They don’t belong in the config.php. They’re PHP configuration parameters.

1 Like

@jtr1: thank you.
I turned off debugging and removed the entries from the config. It helped, nextcloud sped up, but I turned on debugging earlier to check what could have slowed down nextcloud.

Only cron remains. I run it from outside the container every 5 minutes.

*/5 * * * * docker exec -u www-data nextcloud-app php -f /var/www/html/cron.php

When I call it from bash, it shows no response. however, there are errors in the logs.

Error	cron	
Exception
Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Connection refused
Exception thrown: Doctrine\DBAL\Exception

Do I need to do any mariadb tuning?

The problem returned after a few days. I didn’t change anything during this time. Currently it is not possible to use nextcloud. I turned off all applications, the only problem in the logs is the connection to SQL. However, not every time. Cron doesn’t throw errors, nextcloud says cron hasn’t been run for a month.
If it weren’t for the fact that I have a lot of organized photos there, I would have tried to redo everything a long time ago. I set up a similar configuration experimentally on another very weak computer and it works quite decently.

@andy1970 I didn’t see redis memcache on your config.php. Though i see service name cache with redis image. Maybe try adding that to config.php?

Don’t deactivate memcache.local instead add redis cache.

Maybe try add/edit your config.php

‘memcache.local’ => ‘\OC\Memcache\APCu’,
‘memcache.distributed’ => ‘\OC\Memcache\Redis’,
‘filelocking.enabled’ => true,
‘memcache.locking’ => ‘\OC\Memcache\Redis’,
‘redis’ =>
array (
‘host’ => ‘cache’, # Your redis service name
‘password’ => ‘eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81’, # Your redis password
‘port’ => 6379, # Your redis port

But also check your log about redis connection. If you can’t connect nextcloud and redis inside docker network, try with your host ip on the ‘host’ section

My redis doesn’t really want to work. From the container I have this error:

WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect

I couldn’t fix it. After the changes you suggested, it doesn’t work, perhaps because of the above error. Or maybe I should choose another docker redis?

@andy1970 Have you try add this to your sysctl host? You can change or add this to /etc/sysctl.conf in your host system. After add or change, run

sudo sysctl -p

to reload values from your sysctl.conf and restart or redeploy your redis