Async I/O intensive code is running slower than non-async, why?

前端 未结 2 1164
醉酒成梦
醉酒成梦 2020-12-06 13:16

I am refactoring an application and trying to add an asynchronous version of an existing function to improve performance times in an ASP.NET MVC application. I understand th

相关标签:
2条回答
  • 2020-12-06 13:52

    Turns out the Oracle Managed Driver is "fake async", which would partially explain why my async code is running slower.

    0 讨论(0)
  • 2020-12-06 13:56

    The asynchronous version will always be slower than the synchronous version when there is no concurrency. It's doing all of the same work as the non-async version, but with a small amount of overhead added to manage the asynchrony.

    Asynchrony is advantageous, with respect to performance, by allowing improved availability. Each individual request will be slower, but if you make 1000 requests at the same time, the asynchronous implementation will be able to handle them all more quickly (at least in certain circumstances).

    This happens because the asynchronous solution allows the thread that was allocated to handle the request to go back to the pool and handle other requests, whereas the synchronous solution forces the thread to sit there and do nothing while it waits for the asynchronous operation to complete. There is overhead in structuring the program in a way that allows the thread to be freed up to do other work, but the advantage is the ability of that thread to go do other work. In your program there is no other work for the thread to go do, so it ends up being a net loss.

    0 讨论(0)
提交回复
热议问题