异步操作的性能性能、操作

2023-09-05 22:59:04 作者:暮春之初

一个异步编程在.NET中长时间运行的操作执行过程中节省的线程。该的FileStream 类可以设置为允许异步操作,即可以在不使用几乎任何线程中运行(例如)复制操作。令我惊讶的是,我发现,运行异步流副本执行,不仅速度慢,而且还采用了比同步复制流相当于更强的处理能力。

One of the features of asynchronous programming in .NET is saving threads during long running operation execution. The FileStream class can be setup to allow asynchronous operations, that allows running (e.g.) a copy operation without virtually using any threads. To my surprise, I found that running asynchronous stream copy performs not only slower, but also uses more processing power than synchronous stream copy equivalent.

时有任何基准测试都比较同步VS异步操作执行(文件,网络等)?它是否真的有意义执行异步操作,而不是跨越单独的线程,并在服务器环境中执行同步操作,如果异步操作倍同步1慢?

Is there any benchmark tests were done to compare a synchronous vs asynchronous operation execution (file, network, etc.)? Does it really make sense to perform an asynchronous operation instead of spanning separate thread and perform synchronous operation in server environment if the asynchronous operation is times slower than the synchronous one?

推荐答案

其实,在何种条件下文件I / O会的实际上的是异步是相当具体,甚至在本地的Win32水平。请参见这篇文章了解更多详情。

Actually, the conditions under which file i/o will be actually be asynchronous are rather specific, even at the native Win32 level. See this article for more details.