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.
January 26th, 2009 at 8:10 pm - Edit
Thank you so much for tips.
The instuuction are very clear and I manage to install litespeed on dreamhost PS. But, I am not sure how to tune the CPU Memory setting. Currently, My PS service has 304 MB guaranteed memory (Burstable to 608 MB). Do I need to set litespeed Memory I/O Buffer to 304MB?
January 26th, 2009 at 11:28 pm - Edit
Hello, me again.
Does anyone can help me?
I am having difficuilties to make the proper setting.
I tried to adjust the Litespeed Memory I/O buffer from 120m to 304M. It seems to be no different. the following is the data captured from litespeed admin console and data captured from dreamhost PS command line. Based on number of connection 52 and total memory been used on PS server(362M), the memory used per connection is about 9.2MB instead of 6MB per connection.
*************************************
System
Uptime: 03:20:01 Load Average: 0.49, 0.49, 0.34
mpstat 19:01:27 CPU %user %nice %sys %iowait %irq %soft %steal %idle intr/s
19:01:27 all 31.70 0.21 6.09 4.71 0.11 0.86 0.00 56.31 2565.57
vmstat procs ———–memory———- —swap– —–io—- -system– —-cpu—-
r b swpd free buff cache si so bi bo in cs us sy id wa
Process
PID Nice Priority %CPU %Mem RSS(KB) VM(KB) Accu. CPU
26301 0 24 0.1 0.6 1916 5584 00:00:20
Network
Plain SSL
In Out In Out
0KB 1,541KB 0KB 0KB
Connection
Max Idle Plain SSL
150 2 Used Free Used Free
54 96 0 150
Request
Scope Requests in Processing Request/Second
_AdminVHost 0 1
_Server 52 1
domain.com 52 0
*******************************************
The follwoing information is captured from dreamhost PS command line interface using putty and “top” command.
top – 18:54:11 up 3:37, 1 user, load average: 0.03, 0.23, 0.23
Tasks: 79 total, 1 running, 78 sleeping, 0 stopped, 0 zombie
Cpu(s): 29.5%us, 3.8%sy, 0.0%ni, 65.1%id, 0.3%wa, 0.1%hi, 1.2%si, 0.0%st
Mem: 311296k total, 311296k used, 0k free, 0k buffers
Swap: 311296k total, 53944k used, 257352k free, 0k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23356 dhapache 15 0 123m 5556 1508 S 1 1.8 0:00.41 apache2-ps5905-
26308 kl 15 0 7736 5484 1564 S 1 1.8 0:32.44 admin_php
8596 kl 15 0 10592 1284 956 R 0 0.4 0:00.06 top
23379 dhapache 15 0 123m 5328 1444 S 0 1.7 0:00.23 apache2-ps5905-
1 root 18 0 6120 692 568 S 0 0.2 0:08.21 init
2071 dhapache 15 0 123m 5568 1504 S 0 1.8 0:01.39 apache2-ps5905-
3663 postfix 15 0 20652 2060 1616 S 0 0.7 0:00.00 pickup
4940 dhapache 15 0 123m 5548 1512 S 0 1.8 0:01.49 apache2-ps5905-
5019 root 15 0 10112 1420 540 S 0 0.5 0:00.80 syslog-ng
5037 root 20 0 3872 420 332 S 0 0.1 0:00.00 courierlogger
5038 root 18 0 12252 672 528 S 0 0.2 0:00.00 authdaemond
5040 root 18 0 12252 264 120 S 0 0.1 0:00.00 authdaemond
5091 root 18 0 123m 7956 4132 S 0 2.6 0:00.09 apache2-ps5905-
5094 dhapache 18 0 123m 4384 568 S 0 1.4 0:00.00 apache2-ps5905-
5100 dhapache 18 0 123m 4416 596 S 0 1.4 0:00.00 apache2-ps5905-
5104 dhapache 15 0 123m 5556 1508 S 0 1.8 0:01.00 apache2-ps5905-
5109 dhapache 15 0 123m 5620 1592 S 0 1.8 0:01.56 apache2-ps5905-
February 11th, 2009 at 9:57 pm - Edit
@KL
5104 dhapache 15 0 123m 5556 1508 S 0 1.8 0:01.00 apache2-ps5905-
5109 dhapache 15 0 123m 5620 1592 S 0 1.8 0:01.56 apache2-ps5905-
You can see from the 5556 and 5620 that each apache2 is using less than 6MB of memory now. The rest of the memory is used mostly by PHP threads. Tune your PHP_LSAPI_CHILDREN and also your PHP accelerator (eAccelerator?) memory cache size to optimize memory usage.