PHP-FPM optimization on Raspberry Pi

Dear all,

can you help me regarding the configuration of php-fpm with a Raspberry Pi 3B?
I’m running fpm with the default configuration and now wanted to know if I can optimize the pm settings.

Nextcloud version: 26.0.0
Operating system and version: Raspberry Pi OS 11
Apache or nginx version: Apache 2.4.56
PHP version: 8.1

Settings in pool.d/www.conf:
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Now I will use this informations I found for FPM:

|max_children|(Total RAM – Memory used for Linux, DB, etc.) / process size
|start_servers|Number of CPU cores x 4
|min_spare_servers|Number of CPU cores x 2
|max_spare_servers|Same as start_servers

and my free -h:

        total        used        free      shared  buff/cache   available
 Mem:   909Mi       235Mi        304Mi        58Mi       368Mi       555Mi
 Swap:   99Mi          0B         99Mi

and the python script

$ sudo python | grep php-fpm8.1
34.2 MiB + 57.3 MiB = 91.5 MiB php-fpm8.1 (4)

So I assume 235 Mi is the used RAM for the system?
Then I have for max_children: 909MB - 235 MB / 91.5 MB = 7,366…

RPi 3B has 4 cores, so my settings would be:

max_children = 7
start_servers = 16
min_spare_servers = 8
max_spare_servers = 16

If I try to restart php-fpm to apply these settings, I get an error saying max_children must not be lower than the servers.

Is there any mistake or isn’t it possible to optimize the settings and I shall stay with the default ones?

It’s just telling you.

and it also has to be adjusted to the webserver settings:

If you have fewer processes, each process can use more memory. What a good balance is, depends on how many clients you want to server and what kind of apps you use. I’d start with some default, then check the logs if there are messages if it’s complaining about too few children, or if php runs out of memory.

I used a RPi3 some time ago, I tried to push the performance. It’s a nice exercise but in the end the hardware is not very powerful. Just to have it a bit easier, I’d use a RPi4.

Okay thanks for your explanation.
RPi4 is difficult to get and I wanted to set up my unused RPi3 :slight_smile:
I also just have 5 users on my cloud and the Apache php module also runs good,
so I will leave it like this.
Just wanted to know if I can get better performance with php-fpm.

Caching does make a huge difference. But therefore you ideally need a lot of RAM.

Yes I already implented almost everything from “Server Tuning” in the admin manual.
I activated opcache and jit buffer, this did also help.
But I’m satisfied with the performance, of course it’s lower than a normal pc or server, but for 5 users and to have my own cloud everything is ok :slight_smile:
Also the talk app incl. videocalls runs perfectly!