Edit: Dreamhost PS has a new “Lighttpd” server configuration that reduces CPU and memory usage. However, it is not compatible with .htaccess URL rewrites which are used by many PHP scripts. Even so, this configuration can be used as a base for the Litespeed install to reduce memory usage past the Apache-as-proxy configuration.

1. Change to lighttpd in https://panel.dreamhost.com/?tree=vserver.settings

2. Edit the lighttpd configuration file in /home/username/lighttpd with server.port = 3000

3. Restart the VPS to unbind lighttpd from port 80

4. Install litespeed as below, ignoring the proxy step.


Dreamhost 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 Panel memory usage

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.

beautiful interior design

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.

23 Responses to “Optimizing Dreamhost PS CPU and Memory Usage by Installing Litespeed Web Server”
  1. Derek says:

    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

  2. hl says:

    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.

  3. Decio says:

    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.

  4. hl says:

    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.

  5. Nestor says:

    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?

  6. hl says:

    @Nestor,

    Right!

  7. JR says:

    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

  8. SovietNinja says:

    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

  9. hl says:

    @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.

  10. JR says:

    @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!!!

  11. Bill says:

    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… :[

  12. hl says:

    @Bill,

    Hi, Litespeed 32-bit is able to run on 64-bit servers if the servers have ia32 32-bit extensions installed, but I’m not sure whether Dreamhost has them. Check: http://www.linux.com/feature/142075

  13. ronnie says:

    It looks like I have LiteSpeed running okay, but the dhapache’s are still taking 8 instead of 6. Any ideas?

    3720 dhapache 15 0 161m 8376 1688 S 0 2.7 0:00.33 apache2-ps7113-
    4943 dhapache 15 0 161m 8344 1520 S 0 2.7 0:00.03 apache2-ps7113-
    6373 dhapache 15 0 161m 8348 1520 S 0 2.7 0:00.02 apache2-ps7113-

  14. hl says:

    @ronnie,

    Have you set up lsphp5? Is “Extra Web Security” turned off?

  15. ronnie says:

    Yeah, web security in dh panel is unchecked.

    8614 user 17 1 51528 21m 14m S 9 6.2 5:13.11 lsphp5
    9354 user 16 1 50536 18m 13m S 3 5.5 0:39.52 lsphp5
    674 user 16 1 50500 18m 13m S 0 5.4 0:13.74 lsphp5

  16. hl says:

    @ronnie,

    The pmap command should be able to look inside a process and see where the memory is allocated. Can you use the pmap command on an apache process and post the results? Thanks.

  17. ronnie says:

    doesn’t tell me much, but perhaps I’m not doing it right…

    [ps7113]$ pmap -x 3789
    3789: /dh/apache2/apache2-ps7113/apache2-ps7113-httpd -DModSSL -d /dh/apache2/apache2-ps7113
    Address Kbytes RSS Anon Locked Mode Mapping
    —————- —— —— —— ——
    total kB 0 – – -

  18. hl says:

    @ronnie,

    You’re doing it right, but I think the information is hidden due to user permissions. Other than making sure the VPS was restarted at least once after the Litespeed install, I do not have any more troubleshooting ideas…

  19. ronnie says:

    Thanks for your time. It’s a bit weird because I’m pretty sure I’ve seen the apache processes take 6M instead at some point.
    Anyway, it’s worth for me having Litespeed anyway since I have better control of my server now. Thanks a lot for getting me on the right track.

  20. ronnie says:

    Oh one more thing. You mentioned you had set up phpmyadmin on your server. I was looking into that, but I can’t seem to figure out the correct settings to connect to the dreamhost server. Could you tell me how you did it? (perhaps send me an email if that’s easier).
    Thx!

  21. hl says:

    @ronnie,

    I set it up after migrating to a non-dreamhost server. For dreamhost see this: http://wiki.dreamhost.com/PhpMyAdmin

  22. chris says:

    Looks like they’ve since removed access to sudo

    or maybe i just dont know what account would actually work for sudoing commands on the DH VPS

  23. hl says:

    @chris,

    Sorry, I messed up the instructions. Restarting the VPS with the new settings should unbind the lighttpd from port 80.

Leave a Reply