Optimizing Dreamhost PS CPU and Memory Usage by Installing Litespeed Web Server
Posted by: hl in survivalgamesDreamhost PS can act as a very cost effective VPS setup if you are able to configure it correctly. For $15.00 a month on top of the generous Dreamhost shared hosting plan, you can move off of the horrendously loaded shared webservers and onto a virtual private server with 150 MB RAM, 150 MB swap memory, and 150 MHz of dedicated CPU. Dreamhost’s MySQL database servers are still shared with others, but they are decent enough for most sites, and the fact that they are off-server means that they don’t use precious VPS memory.
Dreamhost PS’s default configuration was inherited directly from their shared hosting setup. It was slightly fiddled with but never fully optimized for low memory situations, which is what we have with Dreamhost PS. In particular, the Apache prefork threads that manage web connections to clients are compiled with libraries that you probably don’t need for your personal site. Because of this, more than 2MB of RAM are wasted per thread, and a moderately popular website usually has 30 or more threads. Also, the FastCGI settings are crude, leading to out-of-memory errors and debilitating “blocking” load from common FCGI daemons such as PHP, Perl, and Ruby.
There is much instability when running Dreamhost PS at the lowest memory settings. The easiest solution to this problem is to scale up the CPU/Memory of the Dreamhost PS server until it reaches acceptable levels, and pay extra month after month. A more cost-effective solution is to install an alternative web server behind Dreamhost’s Apache mod_proxy setup. The Litespeed web server is fast, stable, and .htaccess rewrite compatible so it’ll work straight out of the box with your Wordpress or Gallery or phpBB.
First, we’ll install the Litespeed Standard Edition web server to our home directory. The free Litespeed Standard Edition has a low connection limit of 150 and is more like trial software. However, since all of our web connections will be routed through Apache’s front-end mod_proxy module, Litespeed will never reach that limit, and we will never have to purchase Litespeed’s Enterprise Edition. Using Litespeed behind a proxy server makes for a slick deal.
Connect to your PS server’s shell account using SSH.
Using the command prompt, download the Litespeed web server:
wget http://www.litespeedtech.com/packages/3.0/lsws-3.3.4-std-i386-linux.tar.gz
Unzip it to a directory in your home:
tar -xzf lsws-3.3.4-std-i386-linux.tar.gz
Run the install, agreeing to the license and following the instructions:
lsws-3.3.4/install.sh
The Litespeed configuration server will automatically start after the install. Load the LiteSpeed Web configuration panel by browsing to domain.com:7080/
The important settings that you’ll need to configure to get started are .htaccess overrides and file paths. Under Server’s htaccess allow override, untick None and set the overrides that you require. FileInfo is important, as it controls permalinks and mod_rewrite ability. In Virtual Host’s general tab, untick all htaccess overrides to inherit the settings from Server. To set up file paths, edit the Virtual Host Root in the Basic tab to /home/YOURUSERNAME/. Edit the Document Root in the General tab to $VH_ROOT/yourdomain.com/
That should be enough to begin! Perform a graceful restart of Litespeed and test your site by browsing to yourdomain.com:8088.
If it works, we move on to Dreamhost’s control panel to finalize the configuration. In the Domains “Mongrel and Proxy” page, proxy your entire domain to port 8088.
In the Goodies “Cron Jobs” page, add a new cron job that initializes Litespeed after every server reboot: /home/yourusername/lsws/bin/lshttpd start
Wait a few minutes, and Litespeed should be serving the site on the default web port of 80. To check if it worked, use curl to grab the web page headers, and it should read “Litespeed” instead of “Apache”:
curl -I yourdomain.com
You’ll notice that all of your Apache threads are now lighter. They only use about 6MB RAM in mod_proxy mode instead of Dreamhost’s normal 8MB.
top
CTRL+C
We’ve taken a big step towards optimizing performance, but we’re not done yet. Litespeed comes standard with PHP4 for your popular web applications such as Wordpress, Gallery2, and phpBB. Next time, we’ll compile Litespeed’s PHP5 LSAPI with eAccelerator for top PHP performance.




March 20th, 2008 at 9:02 pm - Edit
Hello, this sounds great!
i was wondering if you could expand on
” The free Litespeed Standard Edition has a low connection limit of 150 and is more like trial software. However, since all of our web connections will be routed through Apache’s front-end mod_proxy module, Litespeed will never reach that limit”
I dont see how we will never reach that limit
March 20th, 2008 at 10:20 pm - Edit
Hello Derek,
Litespeed seems to use connections that close soon after they are done transferring data. Since this data transfer occurs between the Litespeed and Apache processes on the same server, the connections close as soon as they begin and never seem to accumulate to a dangerous level. My maximum connections ever was 38, reached when there was a site-ripping bot going through the gallery and using a lot of bandwidth.
April 23rd, 2008 at 1:56 pm - Edit
Hi,
I was wondering if there´s some way to change the Apache config in the PS to timeout and close processes in less time. It seems to me that it open a new processes quite fast, and my main problems are memory spikes. So it seems that it would make sense to close thoses processes faster.
May 11th, 2008 at 2:32 pm - Edit
Hi Decio,
The Apache configuration for Dreamhost is not adjustable, but trying lowering the connection timeouts in the Litespeed control panel. I have had these memory spike problems also.
May 20th, 2008 at 2:54 am - Edit
Hm, interesting, I might try this out. And if I run into problems and want to undo this, all I have to do is stop the cronjob and reboot, right?
June 16th, 2008 at 4:11 pm - Edit
@Nestor,
Right!
July 29th, 2008 at 6:41 am - Edit
Hi!
Your article looks promising, and I sure need to optimize my PS on DH.
I run a few heavy sites, usually I have about 250 processes in total and sometimes even 2300MB are not enough for me.
When I reach the top, I get those super annoying 500 Internal Errors
Ok, my questions are:
- Does it messes with PHP? I have and I need PHP 5 compiled with imagemagic and ffmpeg.
- Will Litespeed handle my heavy sites?
Thanks in advance!
Regards,
JR
August 8th, 2008 at 12:23 pm - Edit
JR,
You might want to wait for hl to reply to you, but I’ve personally had no problem with high traffic sites I’ve tested. If you have too many open processes you may need to pay for the full version of LiteSpeed (or possibly consider lighttpd) although as you are using a proxy that should not be a problem ;3
As for PHP, it is very simple to compile it to your requirements. The LiteSpeed admin panel allows you to set any configure parameters you need.
Give it a go in a sandbox and see if you like it ;3
August 10th, 2008 at 8:04 pm - Edit
@JR,
Hi! I do not have experience with very heavy sites, but I know that the Litespeed process will be killed if memory runs out, necessitating a PS reboot, which is even worse than having 500 Internal Errors. The goal is to decrease the memory usage greatly to prevent this from happening, and Litespeed should be able to do this.
You will have to recompile PHP 5 for Litespeed, but if done correctly, imagemagick and ffmpeg will not be a problem.
September 17th, 2008 at 7:30 am - Edit
@hl
Hi, thank you for your reply.
In fact I now believe that litespeed is not good in big sites serving dynamic content.
Fortunately I could decrease my RAM from an overall of 1600MB to 750MB by using XCache opcode cacher.
Yes, almost 50% memory usage decrease! Handsome!!!
October 29th, 2008 at 1:22 pm - Edit
Hi, I’m really interested in setting this up on my dreamhost VPS, but I don’t think I can run the 32bit version on the 64bit DH server I’m on. Can you confirm this? I don’t think litespeed has a 64bit version of the free software… :[