I have made a simple benchmark test, where I compare inserting and fetching data from Couchbase and Redis. The scenario:
- Insert 100 000 JSON documents in Couchbase as well as to Redis
- Randomly fetching documents using KeyValue operations for Couchbase and the standard way in Redis
Results:
-
Inserting 100 000 objects into Couchbase (code below), takes 60 seconds flat
-
Inserting 100 000 objects into Redis (code below), takes about 8 seconds
-
Randomly fetching a document/KeyValue (average times of 1000 GETs):
** Couchbase: about 0.55 ms to 1 ms using KeyValue operations (500 - 600 ms for 1000 GETs)
** Redis: about 0.055 ms (50-60 ms for 1000 GETs)
Note: I am using ServiceStack Redis lib to interact with Redis.
INSERT code:
// I create a List<JObject> jsonObjects above, to not have that measured in the bench
// ....
IBucket bucket = await cluster.BucketAsync("myBucket");
IScope scope = bucket.Scope("myScope");
var collection = scope.Collection("myCollection");
List<Task> insertTasks = new List<Task>();
Stopwatch sw = Stopwatch.StartNew();
foreach (JObject temp in jsonObjects)
{
await collection.InsertAsync(temp.GetValue("JobId").ToString(), temp);
}
sw.Stop();
Console.WriteLine($"Adding {nbr} to Couchbase took {sw.ElapsedMilliseconds} ms"); // <-- 60 seconds
// Note: I tried to collect all tasks and do a Task.WhenAll(taskList), but it didnt make much of a difference
sw.Restart();
using (var client = redisManager.GetClient())
{
foreach (JObject temp in jsonObjects)
{
client.Set($"jobId:{temp.GetValue("JobId")}", temp.ToString());
}
}
sw.Stop();
Console.WriteLine($"Adding {nbr} to Redis took {sw.ElapsedMilliseconds} ms"); // <-- 8 seconds
GET code:
// COUCHBASE
int lim = 10;
for (int q = 0; q < lim; q++)
{
List<Task> tasks = new List<Task>();
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < nbr; i++)
{
string key = $"{r.Next(1, 100000)}";
await collection.GetAsync(key);
}
// Note: also tried collecting all tasks and do Task.WhenAll(taskList); no relevant time was saved
sw.Stop();
Console.WriteLine($"Couchbase Q: {q}\t{sw.ElapsedMilliseconds}"); // <-- about 600 ms
}
// REDIS:
for (int q = 0; q < 10; q++)
{
Stopwatch sw = Stopwatch.StartNew();
using (var client = redisManager.GetClient())
{
for (int i = 0; i < nbr; i++)
{
client.Get<string>($"jobId:{r.Next(1, 100000)}");
}
}
sw.Stop();
Console.WriteLine($"Redis Q: {q}\t{sw.ElapsedMilliseconds}"); // <-- about 60 ms
}
Redis is 10 times faster for both Insert and Gets (Gets using KeyValue operations). Ig I use Couchbase Query API, it takes 1500 ms approximately.
I can understand that a Query takes longer; its much more advanced functionality and much more powerful, but, I dont really understand why it has to take 10 times longer when using the KeyValue operations. I would expect Couchbase to be much closer to Redis regarding the executio times.
Can someone shed some light here? Do these numbers seem legit, correct, valid?
Regards,
Ted