Thanks everyone for your answers! Following your suggestions I've been able to reduce my memory usage to 195M SWAP and 108M RSS, without touching my code (I'll definitely optimize it soon, but this was supposed to be a solution to get me out of trouble fast).
Here's the list of things I did:
Got rid of the wildcard used in VirtualHost entries. Instead of *:80 and *:443, I used the real IP of my server.
Changed Apache's prefork MPM. These are the values I ended up using:
StartServers 1
MinSpareServers 1
MaxSpareServers 5
ServerLimit 16
MaxClients 16
MaxRequestsPerChild 0
ListenBacklog 100
These are by no means magical numbers. I've spent some time trying different values and combination, and then testing them against the real usage of my server and everyone should do the same in their enviroment. For the record, my server receives close to 2M pvs/month, serving both dynamic pages and assets at a regular rate - no digg effect. The intention, again, was to reduce the memory footprint, not to improve performance or HA.
Reference:
Tunned down Apache's KeepAlive. By setting KeepAliveTimeout
to a lower value (2 in my case) I can expect less server processes just waiting on connections with idle clients that may not request any more content.
Reference: http://httpd.apache.org/docs/2.0/mod/core.html#keepalivetimeout
Removed MySQL's unused module. I added skip-innodb
to MySQL's my.cnf. Massive memory consumption reduction.
There are also some remarkable good suggestions that I couldn't personally do:
- Remove PHP modules you do not need. The PHP on my server has most mods already compiled, I'll probably try my own minimal PHP on other VPS.
- Switch to nginx with php-fastcgi. That's another good advice that I'll be trying soon, but right now I can't risk the downtime.
Try using screen. http://www.gnu.org/software/screen
You can switch to another shell and continue working on something else while the output completes and has the added advantage that the output will not be sent to your remote link if you are not watching it.
There is also support for buffer scrollback in screen, so you can page or search through the output when it is done.
If you are not using screen, ^C is not responding and you really need to terminate the job, you may want to try '~.' (the default ssh interrupt) to terminate the ssh session. You may need to hit enter before typing '~.'
Best Answer
I'm sure someone else has a better answer, but
With "less" after you've opened the file:
As you said, you can open the file with +G and then use ? and ^b to scroll up. There are likely clever awk things you can do to achieve the same thing in a script.