Wednesday, July 18, 2007

How to survive digg/reddit/delicous effect

There have been multiple occasions where I am trying to read an article and the website is down. I have encountered this multiple times where people say something like: “I got around 13,000 hits and server couldn’t handle it”. There are even websites that become popular by making the content of the popular article available. One of these cases is DuggMirror, a service that mirrors Digg articles and makes them available in case the source is unavailable. If you are running a blog and you have your own server, here are a few tips to easily handle at least half a million hits per day.
Install Linux in your server. Linux runs pretty good and there are a lot of tools to support the server administration.
You will need a web server. A lot of users install Apache but I strongly suggest to use Lighttpd. Your blog will usually have images, CSS files, and Javascript files. Apache usually in general doesn’t handle static files as well as Lighttpd. Lighttpd is an event-driven web server that minimizes the blocking waiting for IO.
Your blog will need PHP and MySQL. Make sure you have those running.
Install eAccelerator- By default, every time a PHP script is accessed, the web server must compile the script then execute the compiled code. This task is not needed if the PHP script doesn’t change. What a eAccelerator does is it optimizes the scripts, compiles them, then caches them in a compiled state.
Install Wordpress - This blogging software a lot or all of the features you need. It also scales well when having a lot of traffic.
Install the WP-Cache plugin - Your requests will live in a database and every time you get a new visitor, WordPress will have to retrieve this content from the database. If you get 30,000 visitors, your blogging software will have to do the same query that many times. WP-Cache prevents by caching to disk whatever is in your database so that it can eliminate the need to query the database that many times.
Create a memory file system - WP-Cache caches its files on disk. We know that memory access is much faster than disk access. Creating a memory file system (tmpfs) and putting WP-Cache files in it, will tremendously increase the speed of retrieving cache files.
If you installed WordPress on something like /var/www/myblog and wanted to have a memory file system of 100MB you can execute the following command to mount a tmpfs file system where the cache directory resides: mount -osize=100m -t tmpfs tmpfs /var/www/myblog/wp-content/cache
You can also do this from /etc/fstab with the following line: tmpfs /var/www/myblog/wp-content/cache tmpfs defaults,size=100m 0 0

No comments: