Redis, the high-performance data structure server comes along with its own benchmarking tool. The tool is similar to Apache Bench (ab). I decided to benchmark Redis on Google Compute Engine VM instance and see what it looks like.
I decided to set up 2 Compute Engine instances. One instance will run the Redis Server and the other instance will run the Redis benchmarking tool.
Setting up Google Compute Engine Instances
You can use the gcloud tools to create instances or use the Web console (ofcourse there is an API option too, but we will leave that for now) to create the Compute Engine instances.
I used the Web console to create the 2 Compute Engine instances (redis-instance-1) and (redis-client-1) as given below:
- Assuming that you are in the Developers console and your project, Go to Compute –> Compute Engine –> VM Instances.
- Click on New Instance.
- In the name field, provide the names i.e. redis-instance-1 and redis-client-1
- In the zone, I chose us-central1-a
- In Machine Type, I went with the n1-standard-1 type (1 vCPU, 3.75 GB Memory). You can experiment with other machine types.
- I went with debian-wheezy for the OS image.
- Left the other values as defaults.
- Click on Create instance.
This will get 2 Compute Engine instances for you (redis-instance-1) and (redis-client-1). All we need to do now is to get Redis setup on both of them and that is the next step.
Setting up Redis on the Compute Engine Instances
The next step was to setup Redis on both redis-instance-1 and redis-client-1 instances. The steps below need to be repeated for each of the instances:
- SSH into the instance.
- The best way to setup Redis is the build from the sources. To do that, first update and install the necessary toolset on your Compute Engine instance.
sudo apt-get update sudo apt-get install build-essential
- Once we are done with that, we can get the latest 3.0 Release of Redis and expand that as shown below:
wget http://download.redis.io/redis-stable.tar.gz tar xvzfredis-stable.tar.gz cd redis-stable
- Now, let us build the software:
- Finally, let us install it :
sudo make install
The above steps will get your instance setup with Redis and the all the applications i.e. redis-server, redis-cli, redis-benchmark, etc will be available.
Starting Redis on Compute Engine Instance
All we need to do now is to SSH into redis-instance-1 and start the Redis server (default) on that instance. The steps are straightforward:
- SSH into redis-instance-1 using gcloud command or the SSH button next to the instance in the VM Instances list. I like the later.
- Once you are into the session, simply give redis-server command as shown below:
- The server starts on port 6379 (default)
Allow Traffic on port 6379
In case you do not want to run the Redis benchmarking tool on another Compute Engine instance and instead want to do it from your local network, then you need to allow traffic on port 6379 i.e. the default Redis port.
To do that with the following steps:
- Assuming that you are in the Developers console and your project, Go to Compute –> Compute Engine –> Networks.
- Click on the default network.
- You will see a default-allow-http rule. Click that and add a tcp:6379 value to the Allowed protocols and ports field as shown below:
- Click on Save.
Running the Benchmark tool from another Compute Engine instance
The last step was to SSH into the other Compute Engine instance (redis-client-1) and fire the following command:
redis-benchmark -h <IPAddress_RedisServerInstance> -n 100000 -q
This is a simple Redis benchmark test that simulates 100000 operations. Note that I need to provide the IP Address of the redis-instance-1 VM. The -q parameter is the quiet mode.
Note: From your Developer console, you can get the External IP Addresses from the Compute Engine –> VM Instances list. To get the internal IP Address, click on any of the Instances and the detail page should show you the Internal IP Address.
Refer to the Redis benchmarking tool page for more information.
We know that to talk from one Compute Engine instance to another, we can use either the Internal IP Addresses or External IP Addresses.
The results shown below is from a sample run when I use the Internal IP Address for the redis-instance-1.
PING_INLINE: 44722.72 requests per second PING_BULK: 45871.56 requests per second SET: 42753.31 requests per second GET: 44111.16 requests per second INCR: 44702.73 requests per second LPUSH: 40535.06 requests per second LPOP: 44543.43 requests per second SADD: 45850.53 requests per second SPOP: 42662.11 requests per second LPUSH (needed to benchmark LRANGE): 46317.74 requests per second LRANGE_100 (first 100 elements): 26539.28 requests per second LRANGE_300 (first 300 elements): 13592.50 requests per second LRANGE_500 (first 450 elements): 12081.67 requests per second LRANGE_600 (first 600 elements): 9387.91 requests per second MSET (10 keys): 37921.88 requests per second
The next set of results are when I use the External IP Address for the redis-instance-1.
<pre>PING_INLINE: 37285.61 requests per second PING_BULK: 38431.98 requests per second SET: 36968.58 requests per second GET: 37425.15 requests per second INCR: 37608.12 requests per second LPUSH: 37064.49 requests per second LPOP: 37299.52 requests per second SADD: 36982.25 requests per second SPOP: 36643.46 requests per second LPUSH (needed to benchmark LRANGE): 35435.86 requests per second LRANGE_100 (first 100 elements): 26329.65 requests per second LRANGE_300 (first 300 elements): 12909.89 requests per second LRANGE_500 (first 450 elements): 10563.01 requests per second LRANGE_600 (first 600 elements): 8646.03 requests per second MSET (10 keys): 33189.51 requests per second
Of course, I should do a few runs of the above test and then average things out, but you get the point. It should be straightforward now for you to probably extend these to across compute zones/regions and do a bench mark test from your local machine.