Provide a "true" synchronous API that doesn't wrap around any async methods

Description

We have been doing some 200 concurrency performance test on our ASP.Net Core application which is using synchronous controller actions to read data from Cassandra using the 3.13.0 version of the Datastax C# library. We are finding that calling the synchronous operations of the driver is resulting in client timeouts due to thread starvation.

Within the source code, we see that the synchronous operation is actually performing an async operation and then blocking the thread. This is spawning a huge number of unnecessary threads as the function is expected to execute synchronously on the thread in which the function is called:

 

Here is an example Console application that was put together to test the functionality to be able to reproduce the error at the lowest level. You can imagine that the Task.Run function shown here is similar in functionality to how the IIS/.Net thread pool runs synchronous controller actions where each user would normally be a different user calling our web api.

While we could utilize the work around given in to adjust the minimum threads, we feel like this solution is not optimal as the new threads that are spawned adds additional overhead that should not be required.

 

We do not see the same issue when utilizing other frameworks such as EntityFrameworkCore. If we look at the source code for their synchronous functions then we find that they do not call the async version and block. Instead the synchronous functions call further synchronous functions to perform the operation. For example, you can look at the Find and FindAsync operations:

 

 

Sample EFCore console application invoking Find method:

Please advise if the driver offers true synchronous operation or can the driver only be used for asynchronous operations?

Environment

ASP.Net Core Windows 10

IIS Web Application

Activity

Joao Reis 
January 17, 2022 at 2:46 PM

The synchronous operation of the driver is not suitable for applications with high throughput/concurrency requirements. As you say, it is just an inefficient wrapper around the async API of the driver as the driver is designed completely async from the ground up.

Details

Assignee

Reporter

Labels

Priority

Created January 16, 2022 at 8:04 PM
Updated January 17, 2022 at 2:48 PM