This setup is fine if you don't get much traffic. I would guesstimate that it would work for about 500 visitors/day.
Our first step to increase performance was to remove the images from the web server and host them on a separate machine (files). We also moved the servers to a co-located ISP.
This really doesn't help things from a dynamic point of view, but it offloaded some work from the main web server so things did speed up a bit. As traffic increases, so does the load on the database. We were still doing everything dynamically.
Next step we offloaded the database to a separate machine. This was a huge performance increase - probably the biggest we ever got. The database ran on a server with 2GB RAM for many years. Once the database started getting overloaded, we had to look for other improvements.
I added in the caching subsystem to offload work from the database. Instead of generating everything dynamically on every page request, we saved off a version of the page on the local web server's disk. If you were looking at page "X", the system would check for that page locally first. If it wasn't there then we would dynamically generate it, and save it off so that the next person to look at it would find it on the disk.
This is a huge savings in processing power. Many parts of the site don't change much, so storing these off helps a lot. Eventually I modularized each page so that instead of having 1 big file, it would be several files - each file being 1 part of an entire page. This let me selectively update parts of the site without wrecking the global cache of all the other stuff.
The problem we're running into now is load on the web server. Each server can only serve so many pages per day based on its capacity.
So, let's add another web server! However, we run into the problem of cache synchronization.... ugh.
Here's the problem in a nutshell:
Say you are surfing BGG on the 'wallace' server and post a reply to a thread. Everything on 'wallace' is updated fine and dandy with the current cache system. We just purge the cache file, and the next time someone looks at the thread we regenerate the file and show that to them. If someone else is over on the other server - 'kramer' they have no knowledge of the new post and it would just keep on showing the stale version of the thread (that doesn't have the post you just made).
Some kind of synchronization is necessary to keep all the servers up to date as much as possible.
The first method I tried was a centralized cache. I set up a directory on the file server which would serve as a centralized cache storage area. Each other web server mounted this directory using NFS (Network File System). Files are read from and written to the cache over the network. Unless your network is very high speed, this can cause a bottleneck. It did with us, it caused a major bottleneck which forced web server processes to stall (waiting on files to be loaded from the NFS cache) before it could continue on. This just caused a downward cycle which resulted in the web server getting more and more overloaded.
So we scratched the NFS server method.
Here's our new method - let's call it the DB Sync method:
- Each web server keeps its own cached files on the local disk.
- A centralized database of cache status is kept. It has an entry for every file in the cache and also whether the file is fresh or stale for each server.
- The web server checks the central database to see if the file has become stale before delivering it to a user.
- If it's stale, we regenerate the cache and update the database status to being fresh - yum!
- Any web server can mark a cache as stale. Say someone replies to a thread, the server that took the process can mark the cache stale for all other servers.
This could potentially cause a bottleneck on the database (each file needs to be looked up). If we keep a good index for fast access, the look up is constant time and should be quick.
We'll see how it goes...
Last edited on 2006-09-06 19:19:27 CST (Total Number of Edits: 5)














































































