Typical web applications require dozens of SQL queries to generate a single page. When your application is serving over 1,000,000 pages per day, you quickly realize that the performance bottleneck is your database. The typical answer to slow database queries is “just use memcached!” Memcached and other data caches can only take you so far. This is where reverse proxies come in. There are a handful of them out there, including Nginx, Perlbal, Squid and Varnish. Which to use is up to you.
Deciding what is best for you
Assuming that you have taken a step back and really analyzed your problem first, the next step is to analyze the possible solutions. For us, Varnish seems like the best option with Squid close behind. To be fair, I’ve set up a test server with both Varnish and Squid running. I’ll use ApacheBench to generate load and requests.
I’ve analyzed our pages to see what the typical page size is and recorded the average page sizes for 5 different page types. They range from around 10KB to 35KB (gzipped). For my test, I’ll be benchmarking with 10KB, 15KB, 20KB, 30KB, 40KB, and 50KB files to get a good range of different size requests.
To test under different load capacities, I’ll use ApacheBench to generate loads with different amounts of concurrent users ranging from 10 to 400.
I’ll be using two identical machines on the same local class C network to eliminate (as much as possible) network latency.
The machines look something like this:
- Pentium 4 3GHz (8KB Level 1, 512KB Level 2)
- 2GB (4x512 DDR 400MHz)
- 120GB ATA Western Digital Caviar WD1200JB
- CentOS 5
(I don't have more information than that. Suffice to say that it is a few years old and not very powerful)
I am using Varnish 2.04 and Squid 2.6.STABLE21. There are newer versions of Squid but i am using this version because the 3.x branch is missing features found in the 2.x branch and I have read several reports of 2.7 crashing, etc.
The command to run the load test looks something like this:
ab –c concurrent_users –n total_requests “url”
This will let you specify how many concurrent users to run and how many requests to make. I have the proxy servers running on ServerA and I run the benchmark from ServerB.
In general, Varnish seems to perform twice as well as Squid does. In every test, Varnish serves nearly 2x more requests per second and has half the average response time.
|File Size||Concurrent Users||(V) Requests per second||(V) Avg across all requests||(V) Average Request (ms)||(S) Requests per second||(S) Avg across all requests||(S) Average Request (ms)|
Here are the graphs of the above data for easier visualization:
Something is wrong here
These are simply benchmarks and are not meant to represent real world scenarios for a few reasons. Most importantly, this test takes place on a local network that goes through one router. Running this test on a local network does not take into consideration the typical network latency you would find across the internet.
Secondly, this test only illustrates the raw speed of serving up cached content which isn’t a typical real world scenario. To really test the overall performance of both of these, we need to simulate the three major steps of a reverse proxy:
- Forwarding a request to a backend server
- Physically caching it (memory or disk)
- Serving the cached data
Testing any of these three steps is good, and shows the raw performance of that function but it doesn’t give us a general overview of the overall performance.
I need to come up with a way to generate load on the server such that it represents the typical flow of requests that we would normally see on a server. I am running this on a test server, not against production data, so if anyone has an idea of how I can do this, please do let me know. The results of this test will be Part 2 of this post.
Additionally, please let me know if you spot inefficiencies in my testing methodology. I don’t claim to be a load testing expert so any advice you can offer is appreciated.