Hello,
After upgrading to the 3.x SDK the performance testing shows that there is some performance degradation comparing to the results we have for 2.7.26. Probably I do something wrong (e.g. initialize SDK), therefore I prepared two simple projects which just query the cluster.
I query the cluster concurrently by 5 threads.
The cluster initialization for 2.x:
var clientDef = new CouchbaseClientDefinition
{
Servers = [...],
Buckets = new List<BucketDefinition>
{
new BucketDefinition
{
Name = "bucket-name",
Password = "password",
UseSsl = true,
ConnectionPool = new ConnectionPoolDefinition
{
MinSize = 1,
MaxSize = 3
}
}
}
};
var clusterConfiguration = new ClientConfiguration(clientDef);
var serializationSettings = new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
TypeNameHandling = TypeNameHandling.All
};
clusterConfiguration.Transcoder = () => new DefaultTranscoder(new DefaultConverter(), new DefaultSerializer(serializationSettings, serializationSettings));
clusterConfiguration.Serializer = () => new DefaultSerializer(serializationSettings, serializationSettings);
ClusterHelper.Initialize(clusterConfiguration);
and the cluster initialization for SDK 3.x:
var clusterOptions = new ClusterOptions()
.WithConnectionString("connection-string")
.WithCredentials("username", "password");
clusterOptions.EnableDnsSrvResolution = true;
clusterOptions.ForceIpAsTargetHost = false;
clusterOptions.EnableTls = true;
var cluster = await Cluster.ConnectAsync(clusterOptions);
The code for testing is almost the same for both. The only difference is in the QueryItem
method and how the cluster is queried (with bucket in 2.x and with collection in 3.x).
var bucket = ClusterHelper.Get().OpenBucket("bucket-name");
...
Task QueryItem(string key)
{
var result = await bucket.GetAsync<string>(key);
if (!result.Success)
throw new Exception("Error");
var doc = JObject.Parse(result.Value);
}
and for 3.x
var bucket = await cluster.BucketAsync("bucket-name");
var collection = await bucket.DefaultCollectionAsync();
Task QueryItem(string key)
{
var result = await collection.GetAsync(request);
var content = result.ContentAs<JObject>();
}
And the general code for the testing:
var requests = new ConcurrentQueue<string>();
for (int req = 0; req < numOfRequests; req++)
// Fill the queue with the requests
var stopwatch = Stopwatch.StartNew();
var tasks = Enumerable.Range(0, 5).Select(async _ =>
{
while (requests.TryDequeue(out string request))
{
await QueryItem(request);
}
});
await Task.WhenAll(tasks);
stopwatch.Stop();
So this is what reports stopwatch.ElapsedMilliseconds
:
NumOfRequests | Old SDK | New SDK |
---|---|---|
10000 | 3246 | 4017 |
50000 | 15025 | 18903 |
30084 | 30084 | 37723 |
Could someone please take a look and see if there is something wrong in the way I initialize the cluster? Seems like the results are slower by more than 20%