In my experience, the hardest thing to work around when using a VPS for hosting is limited memory. It’s definitely a challenge to try and tune a database, web server, and application server for load under the constraints of a VPS plan (typically 512 MB or less of RAM). The best solution I came-up with was to use a baseline of about 70% of my guaranteed memory quota when the various servers started up, with 30% of my guaranteed memory free for high traffic situations. This seems to be working for me pretty well so far, especially considering that my memory usage can theoretically temporarily burst to 300% of my guaranteed memory quota.
However hosting in a VPS can present some challenges when trying to determine load and memory usage for your VPS. For instance, when using top, the memory statistics displayed represent the whole server and not your VPS. That said, I’ve only found one way to get an idea of what my memory usage is, how much I have reserved, and how much my VPS is allowed to burst to via command line is this script:
- #!/bin/bash
- bean=`cat /proc/user_beancounters`
- guar=`echo “$bean” | grep vmguar | awk ‘{ print $4;}’`
- burst=`echo “$bean” | grep privvm | awk ‘{ print $5;}’`
- priv=`echo “$bean” | grep privvm | awk ‘{ print $2;}’`
- let total=guar/256
- let used=priv/256
- let burst=burst/256
- echo “VPS memory usage:”
- echo “Used: $used MB”
- echo “Total: $total MB”
- echo “Burstable to: $burst MB”
As far as I know this should work under any Virtuozzo Linux based virtual private server, but let everyone know in the comments whether or not it works for you on your given platform.










By linuxchic June 21, 2007 - 1:26 pm
Works great at VPSlink.com hosting.
By kman June 22, 2007 - 7:11 am
Works for eapps too
By v June 27, 2007 - 3:19 pm
works very well for me.
Linux2.6.9-023stab040.1-enterprise #1 SMP i686 i686 i386 GNU/Linux
By Kevin Wilde August 7, 2007 - 9:37 pm
Works on spry.com vps running CentOS.
Thanks for the great script.
By Angie September 25, 2007 - 10:58 am
I had to tweak it a little bit. This was for CentOS running version 2.5 of Virtuozzo. However, without this as a start I'd still be guessing. I also do the highly explicate math for the pages to Megs conversion. Also, be sure to verify that your system uses a 4kB page when using the script above (that setting can be configured by your SysAdmin). Here is my script:
#!/bin/bash
bean=`cat /proc/user_beancounters`
guar=`echo "$bean" | grep vmguar | awk '{ print $4;}'`
burst=`echo "$bean" | grep privvm | awk '{ print $5;}'`
alloca=`echo "$bean" | grep privvmpages | awk '{ print $2;}'`
priv=`echo "$bean" | grep physpages | awk '{ print $2;}'`
let guarenteed=guar*4096/1048576
let allocated=alloca*4096/1048576
let used=priv*4096/1048576
let burst=burst*4096/1048576
echo "VPS memory usage:"
echo "Allocated: $allocated MB"
echo "Used: $used MB"
echo "Guarenteed: $guarenteed MB"
echo "Burstable to: $burst MB"
Here is the code I used (I forget where I grabbed it from but I found it on the web) to verify the page size:
#include
#include // sysconf(3)
int main()
{
printf("The page size for this system is %ld bytes\n", sysconf(_SC_PAGESIZE)); //_SC_PAGE_SIZE is OK too.
return 0;
}
By Hubert October 4, 2007 - 3:37 am
Works well for me, and Angie's mod works even better, thanks.
Fedora Core release 2 (Tettnang)
By Pete Freitag October 12, 2007 - 12:11 pm
Handy script thanks Brandon!
By Brandon Harper October 31, 2007 - 12:38 am
No problem Pete-- good to hear from you again. Glad you found it useful!
By Goran November 17, 2007 - 6:44 pm
Worked for me, great scripts.
I just want to add a link for page size verifying code, because I had a little problem with that (incomplete code).
It is not Angie's mistake, problem was with tag parsing.
By Totonet July 2, 2008 - 1:23 am
Thanks for sharing with us, works great for me.
By omaniyat June 22, 2009 - 2:05 am
Hi,
Can You tell me why is the System Usage reach 100% while the CPU Usage not above 17% and Memory Used between 15% to 30%?
Great subject.
Thank you.
By Utnnyan March 4, 2010 - 9:02 am
Hello,
Sorry for the noob question but I'm not sure what to do with that pagesize code. I put it in as an .sh file but all I get is errors.
When I run Angie's version could someone explain what exactly is meant by each result?
VPS memory usage:
Allocated: 366 MB
Used: 162 MB
Guarenteed: 256 MB
Burstable to: 384 MB
Thank you