7is7.com > Software > Dreamhost PS Manager
Dreamhost Gears
Host with Dreamhost and get $97 worth of discounts with our Dreamhost Promo Codes.
Donate towards my web hosting bill!

Dreamhost PS Manager

Version 0.2.6b

Dreamhost PS Manager is a tool that dynamically manages the size of the memory of your Dreamhost virtual private server.

Managing the size of your memory dynamically, has a certain number of advantages. The main advantage is that you can continue to serve your visitors during peak traffic periods by temporarily increasing available resources without having to pay the monthly fee for these resources, instead you are only charged for the time the resources were made available to you. Conversely during low traffic periods your resources will be lowered saving you from having to pay for resources that you do not really need all the time. Basically this puts a 4000 MB RAM webserver at your disposal at a fraction of the price.

It also saves you from having to guess how much memory you need and from having to set your server's memory size manually. Dreamhost PS Manager will do that for you based on actual usage.

Installation

You will need an API key for the Dreamhost web panel. You can get one here: https://panel.dreamhost.com/?tree=home.api. This API key needs to be allowed to access dreamhost_ps-set_size.

Proceed to download the PsManager script and the configuration file:

Place both of these files in the same directory, for example in a "bin" directory of any user on the private server you want to manage. Avoid placing this script in your cgi-bin directory or under your site's document root, it should not be accessible via your website.

You can do install PsManager directly from the command line of your VPS:

mkdir ~/bin 2>/dev/null; cd ~/bin
wget http://www.7is7.com/software/dreamhost/download/psmanager.tar.gz
tar -zxvf psmanager.tar.gz

If you did not follow the procedure above, check that the permissions are in order: psmanager.pl must be executable and psmanager.conf only readable by the owner (or type: chmod 700 psmanager.pl; chmod 600 psmanager.conf).

Note: Is it important that your configuration file is not readable by others at it contains your Dreamhost API key and may contain your Twitter or Identi.ca passwords.

Edit the configuration file filling in your Dreamhost webpanel username and API key. Optionally you can also set the userid and password for a Twitter or Identica account (see below for more about that).

Finally to get everything running, you'll need to set up your crontab to run psmanager.pl every minute (this example assumes the program is located in you "bin" directory):

* * * * * $HOME/bin/psmanager.pl > /tmp/psmanager_cron.log 2>&1

After collecting a minimum amount of data, PsManager will start to make decisions about what memory size your system needs.

Upgrading

When upgrading from an older version, one generally only needs to replace psmanager.pl, as the configuration file can stay the same. You can follow the procedure above but without replacing your original psmanager.conf file.

Tweaking

By default Dreamhost Ps Manager will set a memory level between 150 MB and 4000 MB, which are respectively the minimum and maximum allowed by Dreamhost. You can set a higher minimum or lower maximum in the configuration file (the lines are commented out by default).

You can also create more (or less) space by applying a memory factor other than 1. For example if you want to add 10% to the calculated memory, set memory_factor = 1.1. If your memory usage tends to be high (above 1000 MB) it's probably better to add a bit of extra margin.

PsManager should be able to determine the machine you want to manage automatically, if for some reason it doesn't you can manually set the 'ps' variable in the configuration file to indicate the correct machine.

Advanced Tweaking

As of version 0.2.4 you can set complex instructions in the configuration file, for example to increase the minimum required memory at certain times of the day. For example the code below will set the minimum memory to 400MB from 7pm (19:00) to midnight.

{
	my ($sec,$min,$hour) = localtime();
	if ($hour>=19 && $hour<=23) {
		$mem_min = 400;
		$memory_factor = 1;
	}
}

How it works

PsManager monitors memory usage over the last 60 minutes and calculates an optimal memory requirement from that. Technically it takes the average of the 8 highest memory usage peaks (discarding the two highest ones) in the last 60 minutes. Single peaks into swap memory are acceptable, but regular use of swap memory is not advisable as it makes your sites slower and risks them not working at all if all swap memory is also used, so we make an effort to avoid depending on swap memory and keep reserved memory on the high end of actual usage.

Dreamhost limits us to making 30 changes per day to the memory size, as a result we have to be a bit careful with changes. To safeguard this restriction PsManager will never make more than 5 changes in 4 hours. In order to avoid making too many up and down changes, downward changes will occur only if no changes have been made in the previous 120 minutes and the change exceeds 10% of current reserved memory. Upwards however, it's more important to maintain availability of your sites so a change will be made upwards if one hour has passed and it exceeds 10% or if the required increase exceeds 20% already after 10 minutes have passed.

Version 0.2.6 also introduces the usage trend in the calculation, if memory usage is going up over an hour it will reserve a bit more, if it's going down it will reserve a bit less. It also maintains a minimal buffer such that memory and swap must together always have a 30% buffer (this only affects high usage sites as there is enough swap for smaller usage sites to maintain that buffer).

As an active user of the tool myself, I am constantly monitoring how it performs and occasionally make tweaks to improve it. Suggestions based on your own experience are of course welcome.

Tweeting Memory Changes

A really cool feature is undoubtedly that you can follow changes to your Dreamhost PS server via Twitter or Identica. The idea is simple, you create a Twitter or Identi.ca account for your Dreamhost PS and let PsManager update it. You then proceed to follow this account from your own Twitter or Identi.ca account. Each time the memory of your Dreamhost PS changes you'll see a tweet about the change appear in your updates stream.

You can check how PsManager tweets the changes it makes to my Dreamhost PS:

Guaranteed Freedom of Use and Code Transparency

The PsManager program is released under an open source license (GNU-GPL v3), which means that you can use this script for free and make any modifications that you please. You are in no way dependent on the original author of this program for future maintenance and your right to use it never expires. The source code of the script is easily viewable (the script is written in perl), you can scrutinize it or have it scrutinized to convince yourself that it does what it says it does.

Help and Support

There is a Dreamhost forum thread for this application where you can ask questions. If you are using or want to use PsManager feel free to contact me by E-mail about any problems or suggestions. If you are using PsManager and want to be notified of a new release, send me an E-mail to be added to the list.

 

Get Firefox! Use OpenOffice.org Use Fedora