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.
10 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Works great at VPSlink.com hosting.
Works for eapps too
works very well for me.
Linux2.6.9-023stab040.1-enterprise #1 SMP i686 i686 i386 GNU/Linux
Works on spry.com vps running CentOS.
Thanks for the great script.
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;
}
Works well for me, and Angie's mod works even better, thanks.
Fedora Core release 2 (Tettnang)
Handy script thanks Brandon!
No problem Pete-- good to hear from you again. Glad you found it useful!
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.
Thanks for sharing with us, works great for me.