4

I've a site running Magento on the following setup:

  • Apache 2.4 with mpm_worker
  • PHP-FPM
  • Total RAM in server: 14GB (10GB avilable to Apache/PHP)

Each PHP-FPM process consumes approximately 80MB of RAM.

I want to fine tune the settings for PHP-FPM and mpm_worker. Reading in the documentation I'm a bit confused about the relation between options in PHP-FPM and mpm_worker.

E.g., PHP-FPM has configurations: pm.min_spare_servers, pm.max_spare_servers, pm.start_servers and max_children. I understand what these options mean with respect to PHP-FPM.

However, mpm_worker has the following configurations: MinSpareThreads, MaxSpareThreads, StartServers and ThreadLimit. Again, isolated to mpm_worker I understand what they do.

My question is: How does these configurations relate to each other? Let's say I set StartServers=2 and ThreadsPerChild=25. This would give me 50 threads to begin with with respect to Apache/mpm_worker. If I then set pm.start_servers = 50, PHP-FPM will spawn 50 processes initially.

So what is the relationship between these 50 "Apache" threads and 50 "PHP-FPM" processes? Does each Apache thread utilize one PHP-FPM process?

I hope someone can give some insight into this.

Thanks!

JanC
  • 153
  • 1
  • 5

2 Answers2

2

Apache serves the requests from the clients using the threads' childs, but it'll only call PHP-FPM for php files - images, css and js should be served directly from Apache, and thus not consume a PHP-FPM thread.

PHP-FPM has multiple threads with no childs - each thread serves a request from Apache.

AFAIK, multiple requests from the same client (loading the page, plus images, css and js) should consume multiple threads if you don't have KeepAlive set in Apache. See this link for more info on KeepAlive.

I've been tuning an Apache server myself recently and found out that if you have multiple cores it's better to increase the number of childs per thread.

Daniel Costa
  • 327
  • 1
  • 4
  • 12
0

The relationship is dynamically mapped. They are separate processes which can also be run under separate servers, thus you have plenty of configuration options.

Apache processes/threads handle initial connections which then use php-fpm processes to parse PHP files for returning requests.

There are a lot of variables in place here to advise you on how to configure which, but generally configure apache so it has enough threads to handle requests real-time and configure php-fpm so your PHP scripts/wensites have enough memory to run. With various possible caching options, this can only be decided by benchmarking a running system.

ek9
  • 2,093
  • 4
  • 19
  • 23
  • 1
    So in my example, if I have 50 active concurrent connections to the webserver, Apache will be serving these connections with 50 threads, right? And each of these connections will require one PHP-FPM process? Thus, if I want to to be able to serve 50 concurrent users I need in total 50 Apache threads and 50 PHP-FPM processes ? – JanC May 14 '14 at 06:16
  • No you do not need a separate thread per user, nor apache threads map 1:1 to PHP-FPM threads. – ek9 May 14 '14 at 07:00
  • 1
    As far as I can tell from the documentation, Apache uses a thread to serve each connection? So if I have 50 concurrent connections to Apache, and I want all of them to be served instantly (without waiting for a thread to become available), I would need 50 threads. Or am I missing something entirely? – JanC May 14 '14 at 09:29