The meaning of life, according to me

May 17th, 2008

Eating under the dinner table is something I hope to experience

Yesterday, I watched Memoirs of a Geisha, and decided that life is art. Graduation is in a week, and the time for highbrow philosophizing is over. I’m not going to rant anymore about freedom or human zombies or personality change… well, maybe just a little bit. Heading into the real world with unrealistic expectations, my only thoughts now are “go to Japan” and “my bank accounts can only hemorrhage for two more years.”

I was never one to believe in work-life balance. Life is art; risking it all, I’ll be a full-time artist. This is vague, but it is enough to act on. This is a proper course of action for a self-serving child born from a generation of self-sacrificing parents. This is the right path for yuppies with broken dreams.

Litespeed on Dreamhost PS: Final Optimizations for Stability and Lowest Cost

February 20th, 2008

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

Shigofumi 06 - he’s a criminal for that scum

February 19th, 2008

Humans are called social animals. An eye for an eye? Then he’s just a caveman.

snapshot20080219095408.jpg
snapshot20080219095130.jpg
snapshot20080219095831.jpg

Socially, he died.
However, as an animal, he lives.

snapshot20080219095427.jpg

Compiling PHP5 and eAccelerator for Litespeed on Dreamhost PS

February 17th, 2008

The standard PHP4 installation that comes with Litespeed may be missing important libraries that you require for your PHP applications. Also, the bundled APC accelerator is not always enabled. Chances are that you will want to compile PHP5 and eAccelerator yourself for maximum compatibility and performance. Luckily, Litespeed has a built-in PHP compiler that simplifies this process.

First, make sure that your Dreamhost PS is temporarily set to at least 600MHz/600MB. Compiling is a CPU intensive task, and without sufficient CPU power, it will take far too long.

Next, connect to your shell account via SSH.

Download, extract, and compile autoconf and automake:
wget ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/autoconf-2.61.tar.gz
wget ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/distfiles/automake-1.10.1.tar.bz2
tar xzf autoconf-2.61.tar.gz
tar xjf automake-1.10.1.tar.bz2
cd autoconf-2.61
./configure --prefix=$HOME
make
make install
export PATH=$PATH:$HOME/bin
cd $HOME/automake-1.10.1
./configure --prefix=$HOME
make
make install

Compile PHP5 from the Litespeed web administration interface. Note that the compile options and file paths in the below image differ from the defaults. Replace username with your user name. gettext is important for international language support, mysql is important for Wordpress, jpeg is important for image manipulation, and PEAR is not used very often. Each PHP web application has different PHP requirements, and not everything was included here, so please make sure to include the compile options that you need. If you are unsure, take a look at Dreamhost’s default compile options to see many other possibilities. In the interest of keeping a small PHP memory footprint, include only necessary compile options.
Litespeed PHP5 compile wizard
Next, we must compile eAccelerator manually. If you are compiling PHP 5.2.5, you can skip this and download the binary here.
wget http://bart.eaccelerator.net/source/0.9.5.2/eaccelerator-0.9.5.2.tar.bz2
tar -xjf eaccelerator-0.9.5.2.tar.bz2
cd eaccelerator-0.9.5.2
export PHP_PREFIX=$HOME/lsws/lsphp5/bin
export PATH=$PATH:$HOME/bin
$PHP_PREFIX/phpize
./configure --prefix=$HOME --enable-eaccelerator-shared --with-php-config=$PHP_PREFIX/php-config
make
cp modules/eaccelerator.so $HOME

After the compile is complete and eaccelerator.so is in your /home/username/ folder, change the Command setting in Server/External App/phpLsapi from $SERVER_ROOT/fcgi-bin/lsphp to $SERVER_ROOT/fcgi-bin/lsphp5
Make a file called php.ini in your $HOME/lsws/fcgi-bin/ directory. Add these lines to enable eAccelerator.
extension_dir = "/home/username"
extension="eaccelerator.so"
eaccelerator.allowed_admin_path="/home/username"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/home/username/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="0"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="1"
eaccelerator.compress="0"
eaccelerator.compress_level="1"
eaccelerator.keys = "shm_only"
eaccelerator.sessions = "shm_only"
eaccelerator.content = "shm_only"
output_buffering = On
memory_limit = 32M

Make a directory /home/username/tmp/eaccelerator and chmod those directories 777. Keep the shm_size as large as your memory will allow. Dreamhost’s NFS file mounts are slow, and we want to avoid putting cache files there. Using /tmp as the cache_dir is faster and allows a smaller shm_size to be used, but it has a capacity of only 128MB, and the server will crash if that directory runs out of space.

Now perform a graceful restart of Litespeed. That’s it! To check if everything is running as it should, create and browse to a file called phpinfo.php with these lines of code:
< ?php
phpinfo();
?>

If all is well, you should see a page titled PHP 5.2.5 that contains this line: “with eAccelerator v0.9.5.2, Copyright (c) 2004-2006 eAccelerator, by eAccelerator.”

With the installation of PHP5 and eAccelerator, most of our speed optimizations for Litespeed are complete. Next time: final tuning of Litespeed and Dreamhost settings for lowest cost and highest stability.

Optimizing Dreamhost PS CPU and Memory Usage by Installing Litespeed Web Server

February 12th, 2008

Dreamhost PS

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. Read the rest of this entry »