Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


SOLVED Memory graph for Services, 50% RAM and 50% Swap.


  • I think I know the answer here but would just like to double-check because it's one of things I think I'm overthinking, lol...

    In this image below, if it's 4 GB assigned and 50% of that is actual RAM and 50% is swap, does this graph mean that it's been dipping into swap and I've reached 100% of the RAM side of things for this particular service?

    a9c1585b-3179-442f-a99f-6c0df4dbfe6d-image.png

    Just looking into fine-tuning my server, specifically for WordPress, and I knew I had plenty of memory assigned to MySQL, but the more I looked at it, it looks around 60-70% used, and if it's only 50% to RAM, then does this mean 10-20% is dipping from the slower swap memory location? This would be a small performance bottleneck for any database lookups, right?


  • @d19dotca never thought of that, but certainly curious too.

    WP certainly doesn't do well when queries hammer the disk, but that's usually doe to poor query coding. https://www.wpintense.com/ has a lot more on that subject.


  • @marcusquinn Totally. I've always considered performance when designing my client's websites so they all load pretty well, in about 2 seconds or less, sometimes as low as around 1.2 seconds, but I've never spent a ton of time really optimizing all the nitty gritty stuff, and that's what I believe my next "project" will be for my clients.

    Though WordPress optimizations is more of a different topic haha so I'll likely create a dedicated post in the WordPress app category to collect and share some resources for people to use when it comes to fine-tuning the performance of WordPress itself. I believe you're a guru on that yourself, so hopefully you won't mind contributing to it. 🙂


  • @d19dotca Sure, our main weapon is plugin unloading (our own plugin I can share privately but it's hazardous in the wrong hands) and fragment caching (WP Super Cache - tried all the rest but WPSC is the best coded for hooks & filters).

  • Staff

    @d19dotca said in Memory graph for Services, 50% RAM and 50% Swap.:

    In this image below, if it's 4 GB assigned and 50% of that is actual RAM and 50% is swap, does this graph mean that it's been dipping into swap and I've reached 100% of the RAM side of things for this particular service?

    The algorithm is not like "RAM gets first priority. When it's over, look into swap". RAM gets allocated but that RAM can get swapped out any time depending on the requirements of other processes in the system. For example, mysql could be using say only 8MB to start with. But 4MB can get swapped out if something else needs it (they are some system calls like mlock which can prevent swapping out). In the graph above, it will show 8MB as green bar.

    IIRC, we can get this information of exactly how much swap and memory is used by a cgroup but this requires the kernel to have memory accounting enabled (which you have no control over in most VPS).

    There's more info at https://docs.docker.com/config/containers/runmetrics/ and https://www.mjmwired.net/kernel/Documentation/cgroups/memory.txt if you want dig deeper.


  • @girish Ah interesting, so then from the sounds of it, memory is a bit random in terms of whether it's using RAM or swap, right? So I guess then I'll leave it at 4 GB as-is since it's using about 3 GB right now, if that. Is there any possibility / does it even make sense to look at it where RAM is used first and then swap? I.e. does it make sense to sort of set a preference on this at all? Or is this not really possible to do / wouldn't matter anyways?


  • @d19dotca I guess it would make sense for the total RAM allocation across all apps not to exceed the total physical RAM available to avoid the disk-swap.

    I defer to the experts but with WP I find the CPU would max-out before RAM in our typical config ratios.

    I did a bunch of research on this a while back for MySQL my.cnf settings best-practice for optimal RAM usage, and wrote up here for reference:

    @girish Not sure if you optimise my.cnf settings for server specs like this? ^

  • Staff

    @d19dotca There is a thing called swappiness which controls when the kernel decides to swap things out - https://linuxhint.com/understanding_vm_swappiness/ . This value can be set a per-container level but we have never experimented with this. It can always be changed at the VM level though using sysctl calls. But like other things, fine tuning these things requires significant time investment to actually understand what they mean and most of the time they don't behave like we expect them to (especially these kernel configs) 🙂


  • @girish That's fair. Thanks for the detailed responses, always learning something new, which I love! 🙂 It's probably not necessary for a while yet then if at all, but would be interested in testing that out sometime (I can be a guinea pig if needed) in the future in case that allows for better performance.


  • @girish if we change the vm.swappiness on the host, will that persist to the containers?

    If not, where do we set the Cloudron default?

  • Staff

    @robi That's my understanding, yes. That it will persist to containers. The article I liked in the earlier comment has the sysctl command to set vm swappiness. But as mentioned earlier, fine tuning these things should be done after investigating and understanding those settings because they usually end up having unexpected side effects.