2

Is there any issue with having a high number of spare httpd processes always running? I ran a test where I increased StartServers and MinSpareServers by 1,000 and measured the increase in memory usage and it was only 500MB.

In light of this I was thinking that since we have a lot of RAM, to get optimal performance during bursty traffic periods, we might as well have StartServers and MinSpareServers set to around 1,000 and of course set ServerLimit and MaxRequestWorkers (formerly MaxClients) to something higher.

Are there any drawbacks of doing this that I'm not aware of assuming our server is capable of handling that many requests at once and we use MaxConnectionsPerChild as a precaution against memory leaks?

As a side note for anyone thinking 0.5MB per httpd process is incorrect, from what I've read the reason why Apache memory usage is way less than what's reported for an individual process by top is that it uses shared libraries.

2
  • Did you serve 1000 requests in parallel, or just spawned the processes? Are you using mod_php or something similar?
    – Fox
    Aug 15, 2015 at 23:07
  • @Fox Just spawned the processes. We're using mod_lsapi which is similar to how LiteSpeed does PHP. I understand more memory could be used when there are requests where scripts are being run, but I'm wondering if there's any drawback to having a lot of spare servers workers that aren't serving requests. Thx
    – sa289
    Aug 16, 2015 at 0:59

3 Answers 3

1

I'm concerned about your testing methodology. It appears you're just spawning a whole bunch of processes then looking at their memory usage. The problem is that when they're first spawned, they're sharing a maximal amount of memory, and don't have any local, per-process data stored.

When you start actually using them, you'll find that those processes start to need more memory. That is true even in the absence of memory leaks, but if you're using any extensions that are leaky, the problem gets real bad, real quick.

I'd recommend doing a lot of realistic load testing, under a variety of conditions, before leaving a configuration like this to run without close supervision.

1
  • Ah I thought there might be some catch =). Thanks for the heads up.
    – sa289
    Aug 16, 2015 at 1:46
1

What your trying to avoid is incoming requests causing new processes to be forked at a rate higher than older processes can service the older connections. This risk is causing a situation where the system keeps creating new processes that consume the available memory and starts to increase the frequency in which the operating system uses swap. Which in turn causes a large increase in disk I/O where the system is just swapping pages from physical memory to virtual memory (on disk), and vice versa, without any real benefit to the workload.

The general formula to start with is:

(Total Memory - Operating System Memory - database memory) / Size Per Apache process.

The formula is only part of the equation. The more you give the system and MySQL memory, the more caching of the file system they do for you and avoid hitting disk which is very expensive. If the database is not on the same system then this is less of a issue.

The other scenario that happens if you do not tune Apache properly and the frequency of swapping increases is the users start hit stop and reload, artificially increasing the load on the server. You can control the MaxRequestWorkers setting so that your server does not spawn so many children that it starts swapping. It seems straightforward in that you just determine the size of your average Apache process, by looking at your process list via a tool such as top, or smem and then divide this into your total available memory, while leaving sufficient memory for other processes you will get a more accurate picture.

The other, key parameter in this scenario is ServerLimit. If ServerLimit is set to a value much higher than necessary, extra, unused shared memory will be allocated. If both ServerLimit and MaxRequestWorkers are set to high. Apache httpd performance and overall general stability of Apache httpd may start to become an issue.

2
  • I'm pretty sure you can't use top to determine the average size of your Apache process because it will be artificially high due to shared libraries not being subtracted out. Yeah, definitely wouldn't want to get to a point of swapping - we have 32GB and 1000 spare workers uses 0.5GB though, so I don't think that's too much of a concern, but I'm wondering if there's some other drawback about having so many spare workers forked and waiting for requests.
    – sa289
    Aug 16, 2015 at 1:02
  • You can use top. $ top Or alternatively: hit Shift + f , then choose the display to order by memory usage by hitting key n then press Enter. You will see active process ordered by memory usage I woud follow up top with SMEM. The biggest downside i see is not having enough memory for linux to cache the file system. Aug 16, 2015 at 21:39
1

There is no issue with having a high number of spare httpd processes always running. It's actually a good idea.

The main point is : if you want httpd to reach that number of process, you'd better reach if right from the start and be sure it works. In other words, don't auto-scale, simply pre-scale. Less surprise.

The seconday point is : if you don't need to share ressources (mostly RAM in this case) or adapt to different services running at different times on your server, there is no point in changing the number of process over time. Allocate a RAM budget to your httpd and spawn the instances you need to handle that many concurrent requests.

15 years ago people would share lots of things on a single server and that made sense to adapt the number of httpds to the workload. Nowadays most people use one server per app : most of the time does not use all of its ressources, but performance is more predictable, and performance analysis and tuning is much easier.

Although there's a gotcha in a specific situation which is actually so common : Apache + mod_php (or whatever interpreter embedded in whatever httpd). Here mod_php totally changes the deal because it then becomes a question of app scaling and not httpd scaling, which is another (lenghty) subject, and requires a different approach (a 1000 preforked worker won't work).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .