20 Jun
Posted by: Brandon Harper in: Linux, Operating Systems, Tips, Hacks, & Tricks
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:
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.
10 Responses
linuxchic
21|Jun|2007 1Works great at VPSlink.com hosting.
kman
22|Jun|2007 2Works for eapps too
v
27|Jun|2007 3works very well for me.
Linux2.6.9-023stab040.1-enterprise #1 SMP i686 i686 i386 GNU/Linux
Kevin Wilde
07|Aug|2007 4Works on spry.com vps running CentOS.
Thanks for the great script.
Angie
25|Sep|2007 5I 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;
}
Hubert
04|Oct|2007 6Works well for me, and Angie's mod works even better, thanks.
Fedora Core release 2 (Tettnang)
Pete Freitag
12|Oct|2007 7Handy script thanks Brandon!
Brandon Harper
31|Oct|2007 8No problem Pete-- good to hear from you again. Glad you found it useful!
Goran
17|Nov|2007 9Worked 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.
Totonet
02|Jul|2008 10Thanks for sharing with us, works great for me.
Leave a reply
Search
Categories
Archives
Links
Calendar
A design creation of Design Disease
devnulled is a personal blog and reflects the ideas and opinions of brandon harper and not his employer, dog, shoes, or stapler.
All content copyright © 2002-9002 brandon harper. All rights reserved.
devnulled is powered by FreeBSD, WordPress and the combustion of dead dinosaurs. It has also been made magically delicious by the pfm module.