Memory optimizaton tips?

11 posts / 0 new
Last post
#1 Mon, 02/03/2014 - 14:06
rallisf1

Memory optimizaton tips?

First of all hi to everyone and grats for this great free platform.

I have a vps of latest CentOS 64bit, latest virtualmin, 3-core XEON 3,2GHz, 1GB RAM, 1GB swap, 80gb hdd used to host php websites along with their dns, mysql db and email.

All those websites are of low load but most of them use joomla/wordpress/opencart and only 3 out of 24 are static.

I have stopped & disabled MailMan and PostgreSQL as i don't use them and i have also changed my apache MPM configuration to:

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       150
MaxRequestsPerChild  1000
</IfModule>

which i am not sure it is 100% correct for my case. All the rest configurations are pretty much default except i was disabling unwanted features to virtual servers individually.

Attached is a screenshot of the system information which shows a low-to-none CPU usage, above 70% RAM usage and about 30% swap file usage. What tweaks could i do to reduce the memory usage? Will increasing the swap file help? Is it safe to disable ipV6 service and will i gain any ram from that?

All the domains hosted have maximum 20 simultaneous clients with the likelihood of reaching 50 simultaneous clients and i opt for hosting about 50 domains by this summer. The most memory consuming proccesses are apache (i see many instances of that and i don't know if they are needed or not each for about 30mb ram) and mysql (about 60mb ram)

Any tips to the new guy (me) would be greatly appreciated! Thanks

Mon, 02/03/2014 - 15:11
rallisf1

after restarting the apache (httpd) service the used memory went under 40% so it is for sure something wrong with my apache configuration, which is all default except the MPM part i posted.

Tue, 02/04/2014 - 07:24
lp86

Assuming you are using the default fcgid PHP, the php processes will stick around for a little while in case they are needed again.

It doesn't take much to make Apache use memory.

Are you running this on a physical server, or a virtual machine?

Tue, 02/04/2014 - 08:16
rallisf1

yes i use fastCGI and i am running a virtual machine.

more screenshots from the active processes attached

somehow i believe there shouldn't be so many apache instances running. i can control that through the prefork module but i don't know what numbers to put there in order to get a lighter but stable environment.

Also if i need to tweak any other settings please let me know.

Tue, 02/04/2014 - 08:43
lp86

That doesn't look too bad, I don't know the amount of activity on your server however. You could set the "StartServers" to 1 and "MinSpareServers" to 1 as well. This will keep apache memory usage low at idle, at the cost of a slight delay spawning new processes when requests come in.

This is the default, with 1GB of memory you shouldn't have much problem with it.

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

Also Wordpress is murder on most servers, there are a few ways to optimize things, but it is a killer. I see a lot of people use Buttflare, it is free, a caching proxy service.

I didn't see ClamAV in there, if you haven't already disabled it, it uses quite a bit of memory. But you lose your AV scanner if your disable it.

I don't know how familiar you are with Linux, but don't freak out when you see most of your memory used, Linux uses a lot of it for caching data, which is more useful then just sitting there being wasted. If a process needs the memory it is released immediately.

Tue, 02/04/2014 - 09:46
rallisf1

i changed StartServers and MinSpareServers to 2. There is little traffic on those websites anyway and the cpu is free all the time so spawning proccesses shouldn't be a problem when needed. ClamAV is disabled, all my clients have paid antivirus software on their computers; there is no need to scan emails twice.

Although i am familiar with most linux shell commands and how to configure most of its applications i haven't used it much so no that thing about caching stuff in RAM i first heard it from you.

I'll look into the buttflare proxy you mentioned.

One last question: Assuming this is the image of my server now with 24 online websites how many more can it handle? Is 50 doable? Upgrading RAM would cost more than renting a second virtual machine on my current host but it was really cheap (160$/year)

Thanks for everything.

Tue, 02/04/2014 - 10:03
lp86

There is no correlation between number of websites and memory/cpu usage. You could put 5000 websites on the server and if they were idle, it would be no different then a few high traffic sites.

It also depends on the content of the sites as well. Static HTML pages will be less resource intensive then something like Wordpress.

What are the specifications of your server? The kind of CPU can have a big impact on performance. A Pentium 4 wouldn't take much to get overloaded versus a newer Xeon or Opteron, or even a Core 2 Duo.

Tue, 02/04/2014 - 10:16
rallisf1

It is a new xeon and i get 3 cores out of it on this virtual machine.

I could not find anything about buttflare but i installed a caching plugin on all my wordpress websites and also enabled caching in the joomla ones too.

Tue, 02/04/2014 - 10:30
lp86

Sounds like a decent machine then. I consider a machine overloaded when the load on the machine is causing a delay in sites responding.

Here is their website https://www.cloudflare.com/

You sign up, switch your DNS over, and you are done.

Tue, 02/04/2014 - 11:20
rallisf1

Ok, i just read a little about cloudflare. do people actually use that? I mean passing my DNS to some community...i'd rather hire an ex-convict for babysitter or something.

I don't say it doesn't work, i just say i can't trust it. Anyway thanks for all the help.

Tue, 02/04/2014 - 11:27
Locutus

Like lp86 already said, the biggest memory hogs usually are the virus and spam scanner, followed by your PHP processes and the MySQL database.

You'll want to keep a decent amount of Apache processes lying around, since each one can only handle one request (or rather, one connection), you need as many running concurrently to serve each request coming in concurrently. It won't make much difference if you have 1 or 2 idle workers.

You'll want to look into optimizing memory usage of your PHP processes, especially if you have about 20 sites using it concurrently. 1 GB is a bit few for that. You shouldn't use any PHP caching then and see if you can optimize Wordpress to use as little memory as possible.

Apache will serve a good deal of static sites concurrently with 1 GB of RAM, but PHP is a killer.

Topic locked