Couchbase performance (misconfiguration or something else?)

@jorl17 -

Yes, here is an example of using the TPL and partitioning:

 internal class Program
{
    private static CouchbaseClient Client = new CouchbaseClient();

    private static void Main(string[] args)
    {
        var items = new Dictionary<string, string>();
        for (int i = 0; i < 100000; i++)
        {
            items.Add("key" + i, "value" + i);
        }
        var results = ParallelSet(items, 8, 1000);
        Console.Read();
    }

    private static ConcurrentDictionary<string, IOperationResult> ParallelSet<T>(IDictionary<string, T> items, int maxParallism, int rangeSize)
    {
        var keys = items.Keys.ToList();
        var results = new ConcurrentDictionary<string, IOperationResult>();
        var options = new ParallelOptions {MaxDegreeOfParallelism = maxParallism};
        var partitioner = Partitioner.Create(0, items.Count, rangeSize);
        Parallel.ForEach(partitioner, options, (range, loopstate) =>
        {
            for (var i = range.Item1; i < range.Item2; i++)
            {
                var key = keys[i];
                var value = items[key];
                var result = Client.ExecuteStore(StoreMode.Set, key, value);
                results.TryAdd(key, result);
            }
        });
        return results;
    }
}

Using this I was able to achieve 40K OPS running CB on localhost, which pretty much removes network latency.

You will need to tune the maxParallism and range to your specific machine and needs to get the best performance.

Note that the client also has “Bulk” methods, but I am pretty sure this will give better performance.

-Jeff