1

I read about the Apache mpm-prefork configuration and I tried to tune the MaxRequestWorkers parameter. My settings before the change were as follows:

<IfModule mpm_prefork_module>
        StartServers            10
        MinSpareServers           10
        MaxSpareServers          64
        ServerLimit           512
        MaxRequestWorkers         500
        MaxConnectionsPerChild   0 
 </IfModule>

Then, because of increasing the concurrent users in my app, I decided to increase the MaxRequestWorkers from 500 to 670 and also ServerLimit from 512 to 700. Fortunately, the problem of slow connection was solved using these changes. But considering the reports from Apache2buddy, the average process memory is 16MB which means apache potentially needs at least 670*16 ~= 10GB of RAM. While my server has only 4GB of RAM. Now, using htop the usage of RAM is about 2.3GB and 400MB swap (from 1GB available)

  1. Why apache does not use more memory actually?
  2. What is the best config in my case? (using about 600 process count)
  3. Does my config has some bad consequences?

So what

s.abbaasi
  • 111
  • 2

1 Answers1

0

Apache will use 1 worker for each request. Setting MaxRequestWorkers to 500 means the server will be able to serve at most 500 requests at the same time. Each worker is a process that consumes memory and your calculations seem fine, but that doesn't mean that there are 500 processes waiting without doing anything; apache creates and deletes processes as needed.

More specifically, Apache will maintain at least MinSpareServers processes idling ready to serve requests and at most MaxSpareServers processes idling. It will create/delete idle processes as needed to satisfy these numbers. So if you don't have enough traffic, proccesses will be deleted freeing up the memory they consume, that's why you see 2.3GB used.

As for bad consequences, well, if your server gets high enough traffic to require enough processes that will use more than 4GB it will start using the swap on the disk and slow down considerably. Think about reducing MaxRequestWorkers to a number closer to what your memory can fit.

Babis
  • 1
  • 3