I have been developing a MySQL database that makes some use of BLObs. This has now been transferred on to a virtual machine (VM) in preparation for going fully into the 'cloud'. However some of the larger and more complex queries have caused MySQL to drop out! These were not a problem on my laptop. Investigating this it seems to occur when RAM usage in approaching max and Swap is maxing out. Looking at the configuration my humble laptop has twice as much RAM and fives times more Swap. The perceived wisdom seems to be that for servers the ratio of Swap to RAM is lower than for PCs. The question is how do I go about calculatng the RAM/Swap requirements?

Thank you...


There's not really any meaningful formula here; there's just arbitrary rules of thumb that get thrown around. E.g.,

"The perceived wisdom seems to be that for servers the ratio of Swap to RAM is lower than for PCs."

Perhaps that assumes a gargantuan amount of RAM, as servers are more likely to have. But this is still mostly meaningless. It says nothing about how much swap you actually need.

Swap is compensation for not having enough RAM. Ideally, you have enough RAM, so you don't use any swap at all. Meaning, you don't need any, but if you want some "just in case", you might as well go with RAM * 2 or some other arbitrary figure. Since storage is much cheaper than RAM, allocating 25 or 50 or 100 MB to swap doesn't matter -- even if it is never used.

But if you do not have enough RAM, then your swap usage is not theoretical. In this case, you are not just dealing with some arbitrary number to cover some abstract general use case. You have an actual requirement. If you aren't sure what that is and RAM * 2 turns out to be not enough, double it again until you are happy with the outcome.

| improve this answer | |
  • In the end I did some estimates allowing for the OS, some minor apps and MySQL (allowing for reading a dozen or so rows with BLObs) and came up with 6GB. The server has now been upped to 8GB (2^3) and so far everything is fine... – MichaelJohn Mar 10 '15 at 12:31
  • Ideally you do have some "free" RAM for the page cache (this is the "buffers/cache" figure reported by free). I.e., allocating 100% of the RAM will hamper performance in the sense that you won't have the benefit of the in-memory cache. Generally unless there's a huge proportion of unused RAM, the system will occupy all/most of it with cache after a period of activity. – goldilocks Mar 10 '15 at 12:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.