0

I'm trying to configure a LAMP server. Actually I opted for Nginx but I guess it's irrelevant to the topic. The server is to be used as a wordpress host. I'm planning to use APC to fully cache pages (APC Object Cache Backend and Batcache plugins).

My question is not about the amount of RAM installed into a machine but about the proportion of RAM allocated to each component of the LAMP (or LEMP) server. I'm asking this because every article that I've found on memory configuration says the same:

  • allocate all available memory to <put the name of the component here>

I have the following components that compete for RAM:

  • Nginx
  • php-fpm
  • Percona MySQL
  • APC

Something tells me letting these processes compete for the memory is a bad idea. They need to know their limits.

I understand that the actual memory allocation may depend on the website usage but is there a proportion for starters? For example, allocate 20% to MySQL, 40% to APC, 20% to php-fpm, leave the rest to the system?

2
  • There is no specific answer here. Sep 23, 2013 at 20:59
  • How would you configure memory allocation on a machine like that, Michael? Isn't there a rule of thumb to start with? Give most to the caching engine, less to MySQL, the rest to php-fpm?
    – Dmitry
    Sep 23, 2013 at 21:07

1 Answer 1

0

OK, well first off you don't generally "allocate" RAM to components. Processes REQUEST RAM (typically through malloc() or similar means), and the operating system's kernel either grants or denies the request depending on available resources.
The kernel also does things like figure out if you don't have enough RAM and need to use swap space to fake it, or if a program requested a whole bunch of RAM it's not actively using (which can be dumped into swap to free up more of the real physical RAM).

Now some programs - like database servers, caching servers, etc. - allow you to take a guess at how much RAM they should request. If that's what you're asking about the correct answer is "As much RAM as they need to achieve optimal performance on your workload".

How do you know how much RAM each component needs to achieve optimum performance?
Load Testing And Capacity Planning! -- You test your environment on your workload, and determine where it's bottlenecking, then you tweak things until the performance is where you want it.

The only rule of thumb is "start with the default configuration and modify as needed".

3
  • I should have been more specific in my question. The task that I'm trying to solve is this. I want LAMP components to use RAM, not swap. Each of them comes with a configuration file where I can tune the amount of RAM they will use. Consider Percona MySQL. It doesn't have any default my.cnf. I am encouraged to create one and limit Percona's use of memory. P.S. I seem to have found a piece of advice telling me to dedicate the size of my db x 1.5 to MySQL. I wonder what parameters to use for determining the amount of memory for the other components. I have a feeling I'm missing something :(
    – Dmitry
    Sep 24, 2013 at 18:09
  • @Dmitry performance is what matters, not parameters - Apply settings, observe performance and bottlenecks, change settings. Repeat until performance is acceptable or you need to buy beefier hardware. You'll find advice on performance-tuning each component you've mentioned in great abundance around the internet - Google is an excellent tool.
    – voretaq7
    Sep 24, 2013 at 18:51
  • Thanks again! I think I can see what you mean now, voretaq7. It seems that my mistake was that I expected to find some exact steps that would bring me to a happy configuration. I will consider your advice now.
    – Dmitry
    Sep 24, 2013 at 20:12

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