Nextcloud really slow after installation

I installed Nextcloud using Docker/docker-compose with mariadb. After I finally got the connection to the database working I noticed that the webinterface is really slow, like unusably slow. Its running on a VM with 4GB RAM and 2 virtual CPUs, so that shouldnt be the problem. RAM and CPU usage is also quite low.
I was thinking that this may be an issue with the database as there are also some warnings in the admin panel.

This is my docker-compose.yml

version: '3'

volumes:
  nextcloud:
  db:

services:
  nextcloud_mariadb:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - /home/user/nextcloud/db:/var/lib/mysql
      - /home/user/nextcloud/my.cnf:/etc/mysql/my.cnf
    environment:
      - MYSQL_ROOT_PASSWORD='xxx'
      - MYSQL_PASSWORD='xxx'
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    ports:
      - 3306:3306
    networks:
      - nextcloud

  nextcloud:
    image: nextcloud:fpm
    links:
      - nextcloud_mariadb
    volumes:
      - /home/user/mnt/VM-Data/nextcloud:/var/www/html
    restart: always
    ports:
      -  9000:9000
    networks: 
      - nextcloud 
  nextcloud_nginx:
    image: nginx
    ports:
      - 8082:80
    links:
      - nextcloud
    volumes:
      - /home/user/nextcloud/nginx.conf:/etc/nginx/nginx.conf:ro
      - /home/user/mnt/VM-Data/nextcloud:/var/www/html:ro
    restart: always
    networks:
      - nextcloud
  

And these are the warning in the admin panel:
(Sorry its german I didnt manage to change it. I trnaslated parts of it.

    Some indeces are missing from the databse. They were not added automatically because that takes too much time Run "occ db:add-missing-indices" to add them. After that the database should be faster
        missing index "calendarobject_calid_index" in table "oc_calendarobjects_props".
        missing index "schedulobj_principuri_index" in table "oc_schedulingobjects".

Some colums are missing a conversion to big int. Aufgrund der Tatsache, dass das Ändern von Spaltentypen bei großen Tabellen einige Zeit dauern kann, wurden sie nicht automatisch geändert. Run "occ db:convert-filecache-bigint" können diese ausstehenden Änderungen manuell übernommen werden. Diese Operation muss ausgeführt werden, während die Instanz offline ist. Weitere Einzelheiten findest Du auf der zugehörigen Dokumentationsseite.
        mounts.storage_id
        mounts.root_id
        mounts.mount_id

However I cant run occ because of an issue with the filesystem with docker.

# php occ db:add-missing-indices
Console has to be executed with the user that owns the file config/config.php
Current user: root
Owner of config.php: 
Try adding 'sudo -u  ' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u ' to the docker command (without the single quotes)

The file doesnt seem to have an owner. Thats also why i cant just use sudo -u This is ls inside the container:

# ls -l
total 105
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:09 3rdparty
-rwxrwxrwx 1 899 nogroup 15752 Feb 25 14:08 AUTHORS
-rwxrwxrwx 1 899 nogroup 34520 Feb 25 14:08 COPYING
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:11 apps
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:24 config
-rwxrwxrwx 1 899 nogroup  3910 Feb 25 14:08 console.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:11 core
-rwxrwxrwx 1 899 nogroup  5048 Feb 25 14:08 cron.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:22 custom_apps
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:36 data
-rwxrwxrwx 1 899 nogroup   156 Feb 25 14:08 index.html
-rwxrwxrwx 1 899 nogroup  2976 Feb 25 14:08 index.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 lib
-rwxrwxrwx 1 899 nogroup   283 Feb 25 14:08 occ
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 ocm-provider
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 ocs
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 ocs-provider
-rwxrwxrwx 1 899 nogroup  3056 Feb 25 14:08 public.php
-rwxrwxrwx 1 899 nogroup  5235 Feb 25 14:08 remote.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 resources
-rwxrwxrwx 1 899 nogroup    26 Feb 25 14:08 robots.txt
-rwxrwxrwx 1 899 nogroup  2381 Feb 25 14:08 status.php
drwxrwxrwx 2 899 nogroup     0 Feb 25 14:12 themes
-rwxrwxrwx 1 899 nogroup   362 Feb 25 14:12 version.php

and this is ls on the host where the www folder is mapped using a bind-mount (see docker-compose). The dolder is mounted onto the Host with samba

alpine:~/mnt/VM-Data/nextcloud$ ls -l
total 105
drwxrwxrwx    2 user     users            0 Feb 25 15:09 3rdparty
-rwxrwxrwx    1 user     users        15752 Feb 25 15:08 AUTHORS
-rwxrwxrwx    1 user     users        34520 Feb 25 15:08 COPYING
drwxrwxrwx    2 user     users            0 Feb 25 15:11 apps
drwxrwxrwx    2 user     users            0 Feb 25 15:24 config
-rwxrwxrwx    1 user     users         3910 Feb 25 15:08 console.php
drwxrwxrwx    2 user     users            0 Feb 25 15:11 core
-rwxrwxrwx    1 user     users         5048 Feb 25 15:08 cron.php
drwxrwxrwx    2 user     users            0 Feb 25 15:22 custom_apps
drwxrwxrwx    2 user     users            0 Feb 25 15:36 data
-rwxrwxrwx    1 user     users          156 Feb 25 15:08 index.html
-rwxrwxrwx    1 user     users         2976 Feb 25 15:08 index.php
drwxrwxrwx    2 user     users            0 Feb 25 15:12 lib
-rwxrwxrwx    1 user     users          283 Feb 25 15:08 occ
drwxrwxrwx    2 user     users            0 Feb 25 15:12 ocm-provider
drwxrwxrwx    2 user     users            0 Feb 25 15:12 ocs
drwxrwxrwx    2 user     users            0 Feb 25 15:12 ocs-provider
-rwxrwxrwx    1 user     users         3056 Feb 25 15:08 public.php
-rwxrwxrwx    1 user     users         5235 Feb 25 15:08 remote.php
drwxrwxrwx    2 user     users            0 Feb 25 15:12 resources
-rwxrwxrwx    1 user     users           26 Feb 25 15:08 robots.txt
-rwxrwxrwx    1 user     users         2381 Feb 25 15:08 status.php
drwxrwxrwx    2 user     users            0 Feb 25 15:12 themes
-rwxrwxrwx    1 user     users          362 Feb 25 15:12 version.php

Are the missing indexes really the problem? And if so how can I fix the permissions inside the container? (chown doesnt work)

Have you optimized your configuration in Nextcloud?
https://docs.nextcloud.com/server/18/admin_manual/installation/server_tuning.html

most of the things are already configured. For example http2 or memory caching.
I couldnt find the www.conf file for php-fpm tuning. I looked in the nextcloud app container and the nginx container.

I ran iotop however and it seems that its definatly an issue with a configuration there is no bottleneck on reads/writes or cpu/ram usage.

Do you have an idea on how to fix the permission issue with occ?

You must start “occ” with the webserver/nextcloud-user:

sudo -u www-data occ ...
(i think sudo is correct configured throw nextcloud-installation)

That doesnt work as the www-data user doesnt own occ. Noone owns the file. This is a problem with docker that I couldnt manage to fix so far.

root@780ff3289924:/var/www/html# sudo -u www-data php occ db:add-missing-indices
Console has to be executed with the user that owns the file config/config.php
Current user: www-data
Owner of config.php: 
Try adding 'sudo -u  ' to the beginning of the command (without the single quotes)
If running with 'docker exec' try adding the option '-u ' to the docker command (without the single quotes)
1 Like

Hi I’m running occ scripts with the following command line from the docker host

docker exec -it -u www-data <NAME_OF_NEXTCLOUD_CONTAINER> php occ <OCC_PARAMETER>

i even have a script on my host container for that purpose:

#!/bin/bash
docker exec -i -u www-data ncprod php occ $1

Here you have to take care if the parameter has spaces you have to put the parameter in quotation marks. Example:

./occ "maintenance:mode --on"

Regarding the original topic:
I have the same issue with my docker instance. My web fronted needs around 10-60s to load, depending on the app. I already had a post here in this forum (Why is my Nextcloud frontend so slow?).
But my only conclusion was to disable a few apps. Thus i could push the time to around 4-5s for a load of the frontend, which still feels very slow.

Meanwhile, i made a “bare-metal” test installation on the same host, where my docker container are running. And the bare-metal nextcloud-instance feels lightning fast - sometimes the load times are below 1s. I’m already thinking about moving back to bare-metal or considering the use of VM’s like proxmox. But somehow i still don’t want to give up docker, because i really like the concept.

1 Like

i run Nextcloud on vm for few days and i noticed it was slow ,
so i added more juice to the vm and it didn’t help…
today i installed redis and now nextcloud extremely faster then before

I have an example in my guide for how to run occ.

If the www-data user in the Docker container can’t access OCC, then you have something else going on because in a stock setup this works as documented.

You can add a bash alias outside the container to make life easier.

echo alias occ=\'docker exec -it -u www-data nextcloud php occ\' >> ~/.bashrc

. ~/.bashrc

Then you can simply type occ at the host’s prompt and the command will run as www-data inside the container.

Also, you need to resolve all warnings on your system, and make sure you set up memory caching.

2 Likes

I revisted my Docker nextcloud insallation yesterday after an upgrade to 18.02 (now on 28.03) and now the frontend is totaly reasonable.
Before I also tested a bare metal install like mfreudenberg.Which works about in the same speed.

1 Like

a2enmod expires
then update your nextcloud’s .htaccess file.

<IfModule mod_expires.c>
  ExpiresActive On

  # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>