PHP FasgCGI High memory usage

Hello everyone, I don’t know if ‘Server Management’ is the right place to post this question:

Tonight, I switched from suPHP to FastCGI because I needed an opcode caching system, I had a site before where the PHP Memory usage was 69% (out of 64MB) on a wordpress site… After installing FastCGI it dropped to 34% which is very nice. I checked every website I had, and yeah, the memory usage was dropped on all sites.

The problem is, before I did use around 500-600mb of 4gigs ram… Now I’m using around 1.2gigs, for the same sites.

Can anybody tell me, why I’m using double ram?

And, is there any way to fix it? or optimize the memory usage

Best regards,
Lucas Rolff

Why do you need to fix it? RAM is meant to be used. If you are not using near 100% of RAM or any of the resources on the server you are wasting money. 1.2 GB from 4 GB is nothing, absolutely nothing. First off you are using an opcode cache now, where do you think it stores that cache? On the HDD? Nope.

The bottom line. Usage RAM is not a sign their is a problem or something to be optimized, using RAM speeds things up. You should only be concerned with RAM usage once you start to have a lot of hard faults (paging to HDD). The same applies to the CPU, if you are not getting close to 100% you are under utilizing your hardware, aka., wasting money.

Raymond Chen always has a good way of explaining these things: ZOMG! This program is using 100% CPU!1! Think of the puppies!!11!!1!1!eleven

Haha Logic_earth you made laughing, thank you lol,

But yeah, I think ur right, but still opcodecaching, for some reason, I only allowed 32mb to be cached… When I have ram free, should I then just let the APC get more ram to cache in?.

Anyways thank you, I’ll go repost this thread when I’m on 100% of ram lol, but yeah, as above… Should I give APC more ram when I’m able to do it or?

Best regards,
Lucas Rolff

You most certainly should, give APC/PHP as much RAM as it can handle. If you are barely hitting 100% of RAM usage on average you should try and maximize as much of the resources (CPU, RAM, I/O (HDD)) as you can. Otherwise you are just wasting money, like I said previously. This is one reason while I like the cloud services like Amazon EC2 and Windows Azure, you pay only for the hardware you need at that time. When demand grows so does the hardware, dynamically and scalable. Fear of being Slashdotted or Digged…if those are still a threat I don’t keep up with the latest bandwidth-stealing trend sites.

The moment you should start worrying about RAM usage is when the server is having excessive amounts of hard faults (paging). Now this of course can just mean the server is under a high-traffic load which means nothing to optimize, just overloaded with people.

I was looking into EC2 etc before I did buy this server, but I heard something about some people had maximized the prices for EC2 so it did cost like 999.99$ or so for 1 hour?

But yeah, do you know how to like configure APC, in a good way, I can just give it more ram, but then again, there must be some settings that can give even better performance, I can disable the apc.stat, but then when a file changes, server needs to be restarted.

Best regards,
Lucas

You can give APC more ram to by editing /etc/php5/conf.d/apc.ini (or wherever your config is stored) and setting apc.shm_size and apc.shm_segments to increase memory avaliable.

Better performance? Is your site actually performing badly? Or is it just the memory usage? If it’s just the mem usage, then there’s nothing wrong as Logic pointed out.

it’s the memory usage that is a little high after switched from suPHP to fastCGI, but yeah my sites are loading blazing fast :stuck_out_tongue:

Yes and while you’re at it (presuming you’re using it) bump up the cache sizes on mysql

How can I do that? :open_mouth:

suPHP starts and runs PHP as its needed, on demand. When PHP isn’t running, its not in memory. As FastCGI it WILL keep it in memory, increasing your requirements for resources. This, I believe we went through in another thread as to why APC wasn’t working properly. Now PHP stays running, you can use APC.

Ohh thank you Timlgoe

Edit your my.cnf and restart mysqld. The default parameters are fairly conservative, you might want to run mysqltuner.pl for some pointers on what my.cnf parameters to adjust.

Thank you for the answer, but I’m not very used to ssh stuff, and don’t want to break something :open_mouth:

Edit: Lol thank you! It was pretty easy!