Conversation
…Asynchronously in TcsMetricsRequestResultHandler for netstandard
|
This will only be an issue if the application has a If your app is a ASP NET Core app for example then by default there is no This PR would make it so that the driver is more "defensive" to handle cases where users don't correctly use At this time I don't see a strong case to accept this change. |
Look at the test (especially Thread.Sleep after ExecuteAsync), it uses You can run the test from this pull request with the net8 target framework and see that with the fix it passes in 9 seconds, but without the fix it often fails after about 30 seconds.
In case of possible throughput issues, you can add a setting that will allow you to change the driver's behavior. |
There was a problem hiding this comment.
Hmm using synchronous blocking code on the test is a classic example of bad application behaviour but it does show that if the application just does some amount of CPU bound work after executing a request it will cause issues. I still have some concern that this might be detrimental for applications that don't do this but there is definitely a stronger case to merge this.
Unfortunately this fix will not be applied for applications that use any version of .NET Framework because the net452 target will be chosen in those scenarios but I don't want to change or add a new target framework in this PR.
I'm not sure when I will be able to get out a C# driver release but I'll merge this after CI passes.
There is an option here to invoke callbacks this way but this requires a refactoring related to reading data from MemoryStream, for example, you can parse the responses before invoking callbacks.
Ok, thank you! |
When I have a bit more time to do some larger development on this driver I think we will just bump the targets to |
|
The test is failing in CI, the test needs to be a bit more tolerant to slower machines |
|
Can you also add a |
…elAndSlowResponseProcessingInUserThread
It would be nice.
Support for .NET 8 will end on November 10, 2026. Therefore, if netstandard2.0 does not have some features, it is better to focus on .NET 10.
Fixed - the test requires threadpool configuration.
Done. |
Issue
Here, the driver invokes read callbacks sequentially. When the driver invokes a callback, the thread implicitly invokes user code outside the driver. If you need to invoke multiple callbacks and the first one is slow, the others will wait. This may cause performance issues with the user application.
Possible solution
In the TcsMetricsRequestResultHandler we can create a TaskCompletionSource with the TaskCreationOptions.RunContinuationsAsynchronously option. This will cause the user code to run on a different thread. I fixed the issue in this PR, but the TaskCompletionSource is still used in other places without the TaskCreationOptions.RunContinuationsAsynchronously option.
Should this issue be fixed in the driver or is it a user application issue?