Litespeed on Dreamhost PS: Final Optimizations for Stability and Lowest Cost
Posted by: hl in reveriesSo we’ve already installed Litespeed, PHP5, and eAccelerator. The final step is to optimize our Litespeed and PS settings.
First, make sure that ALL of your domains on the Dreamhost PS are proxied through Litespeed. This allows Dreamhost’s Apache to only use 6MB of RAM per thread, instead of the usual 8MB. This is a huge memory savings. Each domain must be forwarded to a different internal port within Dreamhost’s proxy interface. A new listener with the corresponding port and a new virtual host must be defined within Litespeed’s configuration for each domain.
Next, in Dreamhost’s “Manage Domains,” “Extra Web Security” should be turned off since Apache is no longer used. When it is on, mod_security is loaded, which wastes RAM. Security and request filters can be tuned in the Litespeed web console. This can possibly reduce server load from spam bots. In Server/Request Filter, turn on “Enable Request Filtering” and “Scan Request Body.” Disable the “XSS attack” rule set because it breaks certain applications such as Wordpress.
In Litespeed’s Server/Tuning/GZIP Compression, turn on compression, but leave dynamic compression off. There is insufficient CPU on a downscaled Dreamhost PS to perform dynamic compression for each request, and if it is on, the web server will suffer. If you have a larger Dreamhost PS, you can turn it on, but should leave the compression level at 1 for best performance.
In Litespeed’s Server/Tuning, reduce the Connection Timeout, Keep-Alive Timeout, Max Request URL Length, and Max Request Header Size, using the values in the tooltips as a guide. Again, this may reduce load from spam bots and DOS attacks.
In Litespeed’s Server/General/General settings, turn on “Use Client IP in Header” becaue we are behind a proxy server. This will allow Litespeed to read the HTTP 1.1 X-Forwarded-For header, which contains the actual IP address of the web connection.
In Litespeed’s Server/External App/phpLsapi, set Max Connections to 3, Persistent Connection to Yes, Instances to 1, Max Idle Time to 60, Connection Keepalive Timeout to 60, and use these lines in Environment:
PHP_LSAPI_MAX_REQUESTS=10000
PHP_LSAPI_CHILDREN=3
LSAPI_AVOID_FORK=1
If the server has more than 512MB of RAM, set Max Connections to 5 and PHP_LSAPI_CHILDREN=5. If it has more than 1024MB of RAM, use 10, and so on. This will help the concurrency of busy servers.
In Dreamhost’s Stats/Site Statistics, uncheck the “Run Analog Reports” box for all of your domains. The calculation of the stats uses up a lot of server resources each day, and although you will no longer see useful information about individual requests and bots, a non-server-log-parsing tracker such as Mint or Statcounter is preferable.
Tune Dreamhost PS’s CPU/Memory settings, maintaining at least 200MB free swap memory AND keeping the 15-minute load average below 1. After a short burst of CPU Usage or Memory past your limits, the speed of the CPU or memory will be throttled greatly. If PHP decides to use those slow resources, it can cause a chain reaction that starts too many Apache threads, possibly bringing the server down.
Mem: 307200k total, 253608k used, 53592k free
Swap: 307200k total, 0k used, 307200k free
That’s all! Your Dreamhost PS should now be running in top shape.

February 21st, 2008 at 7:58 am - Edit
Thanks a lot for these cool tips to improve our PS servers
April 4th, 2008 at 6:22 am - Edit
This posts were amazing! Tks for taking the time to guide us rookies!
One question: I have my sites divided among different users, is there a way to give one user the proper access to another’s files so that I can run lightspeed in one users and serve all the other sites as well? Would be some other solution beside moving all sites to one central user?
April 5th, 2008 at 7:35 am - Edit
@Decio,
I’m glad you found them useful! Since Litespeed runs under one user and one group, you can grant file permissions to all the users in a group. Check out the Unix Groups control panel, and use chmod or an FTP client to grant read/write/execute permissions for the group.
Each domain needs it’s own proxy port from the DreamHost Web Panel and a virtual host bound to that port in the Litespeed control panel.
April 6th, 2008 at 7:14 pm - Edit
@hl,
Tks again!
One question: Not knowing this, I configure all domains to port 8088, and configured all of them through only one listener. Should I separate them into different ports and listeners (like 8088, 8089, 8090, …)?
Also I saw 5 domain limit in litespeed website, but I configured more than 10 and they are all working…
October 20th, 2008 at 10:36 am - Edit
Thanks so much for this great information!
I wanted to point out that you can easily configure litespeed’s default listener to use different vhosts based on domain name instead of having multiple listeners and ports, which presumably increases memory requirements. Just add each vhost to the default listener and set the proper domain name instead of “*”.
Thanks again!
December 21st, 2008 at 4:59 am - Edit
I setup all my vhosts using Virtual Host Templates. So i created a template for each user and add their vhosts to the template. Since each template has its own server settings (External App/phpLsapi), is there a way to generalize them, using one in the LiteSpeed’s Server configuration / External App ? If not, should i set each template with the same the values you mentioned above?
Thanks!
December 22nd, 2008 at 7:26 pm - Edit
@Dida,
The phplsapi at the server level will work for all vhosts.