Closed CavidH closed 5 months ago
- Why does the async implementation perform better than the sync implementation for network calls but not for ODP Oracle connections? In your ODP.NET connection scenario, you create a command object and set the command text. Those are fast operations for .NET to perform and will execute quickly. Thus, you will not see much difference vs. the longer time spent creating a connection and the connection pool, which is what ODP.NET does upon the first
Open()
call.
You can try the sample code here to ensure a more time consuming operation occurs between the open and execute operations: https://github.com/oracle/dotnet-db-samples/blob/master/samples/async/async.cs
- Are there any best practices or considerations I should be aware of when deciding between async and sync for database operations in ASP.NET Web API?
MS has some general advice here: https://learn.microsoft.com/en-us/dotnet/csharp/asynchronous-programming/async-scenarios
If you extrapolate to ODP.NET and DB scenarios, async is useful for long running operations when don't need the DB results to continue your other .NET operations. For example, you could have the DB execute a long running query or stored procedure. Or you could create a connection pool with a large minimum pool size. While the app is waiting, it could perform other operations on the client side.
- Could there be specific configurations or optimizations in ODP.NET that I might be missing to leverage async operations effectively?
Programmatically, you're using async correctly. It's just the benefits can vary depending on the situation. Besides using async for long running operations that are IO and/or CPU bound, you can see increasing async benefits as load increases on your app. With more load, async better ensures fewer operations are blocked by long running operations, which tend to get longer as the load increases.
I believe this issue is resolved via the answers to the questions. Closing the issue.
I'm working on an ASP.NET Web API project and recently performed some performance tests comparing asynchronous (async) and synchronous (sync) calls in two scenarios:
Here's what I observed:
For network calls, the async implementation showed better performance compared to the sync implementation. For ODP Oracle connections, both async and sync implementations exhibited similar performance.
Additional Information
As we know, ODP.NET has added new async methods to improve performance. You can find more details about these async methods in the ODP.NET documentation.
Questions:
Any insights or advice would be greatly appreciated. Thank you!