Mostly slow performance and PHP memory limit obscured

Hello.

I have a fresh Nextcloud installation with 230.829 files (558GB). It’s used in an home environment with aprox. 4 to 6 users. Its running on a Odroid XU4Q with 2GB RAM. OS is Ubuntu 18.04 running Nginx, PHP 7.2 and MariaDB.

I have ‘memcache.local’ => ‘\OC\Memcache\APCu’, in my nextcloud config.php. In my …/fpm/php.ini I have emory_limit = 128M, opcache.memory_consumption=256 and opcache.max_accelerated_files=10000. But on the information tab in my settings menu in Nextcloud there is memory limit of 512MB. And I don’t know where this value is coming from.

The problem is, I’d like to raise this limit, as my installation is often very slow, which means e.g. that when I open the calendar app or the galery app it takes up to 30–60 seconds for everything to load.

When I look at memory consumption with htop it doesn’t exceed 430–480MB RAM. So there should be room upwards. How can I distribute more RAM to Nextcloud? (I tested changing memory_limit in php.ini to 512M, but that doesn’t seem to make any difference, restarting php7.2-fpm service.)
The processes using the most CPU load are 3 x “php-fpm: pool www” and more than 10 x “/usr/sbin/mysqld” (those taking up lots of memory => 695M VIRT / 215M RES / 5680 SHR).

Any suggestions what I could do to get better performance and/or adjust PHP memory limit?

I’d first take a look into your database and the cache settings. Scripts like mysqltuner, tuning-primer will help you to find suitable cache size settings. iotop can also be helpful for further debugging in order to find the limiting process.

You should also think to adjust the number of child-processes and possible connections in nginx, php-fpm and mysql. It wouldn’t make sense to provide only two nginx-connections but 100 mysql connections.

For file transfer speed, you should also consider using redis which handles the file locking cache much more efficiently than mysql (which is used when you don’t have redis).

Thank you for your suggestions. I will look into them and report back how it turned out.

You should check if there is memory_limit=512M in the .user.ini file.

If you installed using snap, then this documentation will help https://github.com/nextcloud/nextcloud-snap.

If you’d like to set the memory limit to a higher value (say, 512M), run:

$ sudo snap set nextcloud php.memory-limit=512M

a few tips as i had same experience: for me it turned out, that memory was not enough, so system began swapping to disk: top left about 60 Mbytes free and buff/cache was down to low values.
For me it helped very much to make the applications smaler (not larger!) in memory consumption, so system doesn’t need to swap any more.

For 4 GB memory I used:

  1. mysql - config: not more than 1/2 of memory at all giving it /etc/my.cnf
    innodb_buffer_pool_size = 768M (max)
  • max_connections = 32
  • join_buffer_size = 6M
    check if that aligns to your system by mysqltuner - script: should have
    [OK] Overall possible memory usage with other process is compatible with memory available
    in output
  1. lower pool of php-fpm at max of 32 processes -> 3x seems a little small, you should raise this according to documentation of nextcloud:
    pm = dynamic
    pm.max_children = 120
    pm.start_servers = 12
    pm.min_spare_servers = 6
    pm.max_spare_servers = 18
    As those processes can use much memory, make php- setting as small as your need are.

  2. make ngix consume only that much memory that is needed for it (i use apache, so don’t know how)

  3. maybe set “sysctl vm.swappiness = 0” for testing and to prevent system swapping if possible
    -> if swap still gets used your config is to much load for you hardware an you need to lower mysql/php

at the end you should have >1 GByte buff/cache in top left for system even on mid load.

Hi, I see this is an old post. I’ve got similar problems. I run a setup with a 2 core HP microserver with 8Gb or RAM and something has happened these last weeks where my CPU usage is 100% for hours and hours with what seems to be more and more spawned php-fpm processes. I am running an installation with snap and I can’t seem to find how to edit the php-fpm pool size. If I restart the php-fpm service with snap restart nextcloud.php-fpm the server runs a little better for a while but quickly the CPU peeks again and nextcloud becomes unresponsive (Clients disconnect and web interface times out). Something must have happened with the latest upgrades as its been running fine for over two years now.