Ram usage on a PS

Started by akyhne, August 16, 2009, 07:35:39 AM

Previous topic - Next topic

Akyhne

Short story, I can't run a SMF forum on a 150MB PS at Dreamhost. Idle with no activity, it uses from 115000k to 145000k of ram.
The forum always have 3-15 users online, including guests.

My problem is that I rarely just get a 500 error, but in most cases I just don't get all images loaded from SMG. I use tinyportal along with a script to show the latest 7 images as a block on the frontpage as well as on the forum frontpage. But also when viewing a post, there's almost always a few avatars shown as a red x.

Loading a page, takes btw. 100 and 200Mb of ram. I then tested with a simple HTML page, no php scripts, just a basic page with some tables, some links and roughly 30 images from 2k-4k in size:

Here are some load examples for that particular page:
Idle (no activity for several minutes)
memory: 153600k - 109184k used
Swap 307200k - 0 used

Loading my frontpage
memory: 153600k - 153600k used
Swap 307200k - 105472k used (peak)



Idle (no activity for several minutes)
memory: 153600k - 107840k used
Swap 307200k - 0 used

Loading my frontpage
memory: 153600k - 153600k used
Swap 307200k - 105036k used (peak)



Idle (no activity for several minutes)
memory: 153600k - 128464k used
Swap 307200k - 0 used

Loading my frontpage
memory: 153600k - 153600k used
Swap 307200k - 124792k used (peak)



Idle (no activity for several minutes)
memory: 153600k - 126008k used
Swap 307200k - 0 used

Loading my frontpage
memory: 153600k - 153600k used
Swap 307200k - 134756k used (peak)

So even a simple html page uses up to 200Mb of ram, including swap. MySql runs on a shared server, so it is not part of the PS. I'm sure the php.ini can be optimized to use lesser ram when running idle mode. I'm currently running the standard php.ini file provided by Dreamhost.

What could be wrong? What am I looking for?

Something like that

If you can, run PHP as an external daemon.

And if you can, ditch Apache and run Nginx.

And disable every service/daemon you don't need.

Akyhne

What would that help me? My problem is that loading a single page takes all the ram and a lot of swap file as well. Loading a 200K website shouldn't be using 150MB of ram, should it?

Something like that

No, it shouldn't.

The problem is if you run PHP inside of Apache. I'll explain.

Apache launches a new thread for every incoming connection. So on a reasonably busy site, it'll be handling dozens of connections per second. When you're serving images or other static files, that's not a big deal.

When you start running PHP inside of Apache, each of those threads takes up more memory to handle PHP scripts -- even when they're just serving an image and not running a PHP script. And because Apache is usually tuned by default to handle dozens of requests a second, all those threads eat up all the RAM.

The simplest thing to do tweak Apache to handle fewer connections. However, I am not too familiar with Apache tuning... perhaps someone else can help you there.

Akyhne

We are not talking about a php page, but a simple HTML page.

I just ran a few tests on my current PS. First I increased the ram available to 500MB. That's the first attached image. The PS then used 95000K of ram.

I then loaded my forum frontpage as reference. That's the second image. Note that the server had no activity on the time of the test. i just updated the webpage by pressing F5 in an IE, a FF and a Opera window on the same page. As you can see, the ram usage at the highest peak time of those 3 loaded pages was 350Mb. That's 250MB of ram to load the frontpage only!!!

Second test was the above mentioned webpage - a simple webpage without any use of php scripting, only containing a few tables and 30 images from 2k to 4k in size. That's the third attached window. The usage was 273000K of memory, so that's 170MB of memory, to load a simple HTML page in 3 browser windows at the same time.

Arantor

So, what version of Apache, and how is it configured?

Akyhne

I wouldn't know as a PS at Dreamhost means no root access. All you get is a slider to empty your wallet (available ram), as well as a page to reboot, enable Xcache and a few other options.

青山 素子

It seems a DreamHost Personal Server is kinda in-between shared hosting and a true VPS, but closer to shared hosting. You get to specify what guaranteed resources you would like, and that's about it over the standard shared hosting abilities.

Personally, I think that if you get stuck with 100 meg of used memory out of 150 guaranteed, you're already at a disadvantage. Without much access, there isn't too much you could do to reduce the memory footprint of the system. Since you have custom php.ini abilities, you could try disabling all modules and only enabling the ones you actually use. At most, you might be able to shave 10 meg off the running process this way, but it might help.
Motoko-chan
Director, Simple Machines

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


Akyhne

According to http://www.simplemachines.org/community/index.php?topic=330830.msg2216050#msg2216050 I shouldn't worry. But the fact is that when loading a webpage makes the usage of ram go banana.
I've increased my memory to 188Mb. So far that doesn't run either, but I'll let it stay there for some hours to see what my average usage is.

rsw686

Hopefully you have SSH access to the system and are not getting those memory figures off the control panel. If so you can use ps to help determine how many apache processes are being forked and how much memory is really being used.

ps -AHo pid,vsize,pmem,comm --sort pid

For example on my server I host multiple websites with my forum using PHP with FastCGI and the rest of the sites using PHP with CGI. Look at the output below which shows Apache forking out the threads for the virtual hosts. Each thread is using around 28MB of memory. Under PID 8635 is my site with a CGI PHP request being completed. For each request made through CGI PHP is spawned then shut down, which makes it slower than running PHP as a module or with FastCGI. Under PID 25633 is the FastCGI PHP processes which keeps the PHP parser resident in memory.


  PID    VSZ %MEM COMMAND
7428  26968  1.3   httpd
2082  27236  0.7     httpd
2198  27236  0.7     httpd
3653  27236  0.7     httpd
3710  27236  0.7     httpd
7741  27236  0.7     httpd
8351  27236  0.7     httpd
8352  27236  0.7     httpd
8411  27236  0.7     httpd
8412  27236  0.7     httpd
8417  27236  0.7     httpd
8418  27236  0.8     httpd
8629  27236  0.7     httpd
8635  27236  0.7     httpd
28211      0  0.0       php-cgi <defunct>
8636  27236  0.7     httpd
13255  27236  0.7     httpd
16853  27236  0.7     httpd
16854  27236  0.7     httpd
16855  27236  0.7     httpd
22598  27236  0.7     httpd
23260  27260  0.8     httpd
25633  19588  0.5     httpd
25717  21536  0.8       php-cgi
5202  35432  2.5         php-cgi
5369  35364  2.5         php-cgi
5411  35500  2.5         php-cgi
5441  34312  2.4         php-cgi
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Arantor

Akyhne, do you have any further updates on this?

Akyhne


Arantor

So is there a problem still? If not, can we mark this topic solved?

Advertisement: