Hi, everyone
We have recently upgraded a mission-crition application to v3.3.6 SDK version and we noticed a considerable performance loss, around -50%.
We have done some profiling and we noticed that the SDK is throwing some exception for the case of DocumentNotExist server response and we are worried if this is causing the performance loss we’ve detected.
Here is the Benchmark we did. In the benchmark report you will notice a “TryGetAsync” which is a test I’ve being doing refactoring some points of the SDK, avoiding the exception throwing, for comparison.
Is it possible to provide the TryGetAsync method? Something like:
Task<(bool, IGetResult)> TryGetAsync(string id, GetOptions? options = null);
Additional reading: Exceptions and Performance - Framework Design Guidelines | Microsoft Learn
[Benchmark(Baseline = true)]
public void GetAsync()
{
var tasks = new Task[GetPerOperation];
for (var i = 0; i < GetPerOperation; i++)
tasks[i] = Task.Run(async () => {
try
{
await _couchbaseCollection.GetAsync("my-document-key");
}
catch (Exception e)
{
}
});
Task.WaitAll(tasks);
}
[Benchmark]
public void TryGetAsync()
{
var tasks = new Task[GetPerOperation];
for (var i = 0; i < GetPerOperation; i++)
tasks[i] = Task.Run(async () => {
try
{
await _couchbaseCollection.TryGetAsync("my-document-key");
}
catch (Exception e)
{
}
});
Task.WaitAll(tasks);
}
Profiling with Jetbrains DotTrace (Ocurrencies of DocumentNotFoundException in only 1 request):
Seems that with TryGetAsync approach we recover some performance, mainly in more concurrency scenarios.