本文介绍了我在哪里/如何才能找到一个.NET类是否使用IOCP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新

我问错了问题,改写(基于答案和注释伟大的信息):

I asked the wrong question, rephrased (based on the great info on answers and comments):

是否有.NET的异步操作的任何良好的来源是真实的异步,因此无论是IOCP或异步(重叠)?有没有快速的方法来找出是否几个类都是这样做的?

Is there any good source on .net's async operations being real async, thus either IOCP or async(overlapped)? Is there any quick way to find out if several classes are doing so?

Example不信任框架的开发盲目

自然的起点,创建一个FileStream是静态的File.open方法()方法,该文档其中没有提及所创建的的FileStream的同步!也不允许您提供FileOptions(这是用来指定魔FileOptions.Asynchronous标志)。

相反,因此FileStream与FileOptions.None创建。任何异步操作都是由乐于助人实现流的基类,它仅仅是包装了相应的同步方法在一个委托,并调用它使用的BeginInvoke()方法的线程池静静地伪造。

Instead, the FileStream is created with FileOptions.None. Any asynchronous operations are quietly faked by the obliging implementation of the Stream base class, which merely wraps the corresponding synchronous method in a delegate and invokes it on the thread pool using the BeginInvoke() method.

这是从平时的坑成功的设计理念,这里的一切在.NET中似乎你认为它会工作的偏差,没有必要过分仔细阅读文档和/或逐步探索晦涩的渔获物和陷阱时间。

This is a deviation from the usual ‘pit of success’ design philosophy, where everything in .NET seems to work as you think it would, without a need to closely read the documentation and/or gradually discover obscure catches and gotchas over time.

我一直试图找到使用 IO完成端口信息 .NET


I've been trying to find information on the use of IO Completion Ports in .NET.

有没有知道一个给定的.NET类是否正在使用的 IO完成端口的什么好办法? (而不必每次使用一个新的类时运行一些测试。

Is there any good way to know whether a given .NET class is using IO Completion Ports? (without having to run some tests every time you use a new class.

我试过MSDN文档的一些类和方法,我无法找到任何东西。

I tried the msdn docs for some classes and methods, and I couldn't find anything on it.

更妙的是,是,如果有一些名单在那里与使用完成端口类的列表。

Even better, would be if there is some list out there with a list of classes using IOCP.

推荐答案

一般情况下,首创置业仅提供了异步的API,如果他们使用的是异步IO的Windows内核的支持来实现。曝光不使用异步内核IO将是众所周知的异步区切换同步反模式其中BCL设计师都可靠地意识到异步方法。这不仅是无用的,但对于性能和误导性有害。他们不这样做。

Generally, the BCL only offers async APIs if they are implemented using async IO backed by the Windows kernel. Exposing async methods that do not use async kernel-IO would be the well-known async-over-sync anti-pattern which the BCL designers are surely aware of. This would not only be useless, but harmful for performance and misleading. They don't do that.

Windows可以异步IO操作使用完成端口或使用常规的重叠IO。两者都是有效的,异步的,因此比阻塞IO扩展性更强。

Windows can do async IO using IOCP or using regular overlapped IO. Both are efficient, asynchronous and therefore more scalable than blocking IO.

这一切都是透明的你。依靠异步是真正的异步和同步是真正同步。

All of this is transparent to you. Rely on async being truly async, and sync being truly sync.

如果有疑问,PEEK,带反射罩下。每当我这样做,我发现证实了我刚才所说的。我还没有看到一个偏离情况。

If in doubt, peek under the hood with Reflector. Whenever I have done this I have found confirmed what I just stated. I have yet to see a deviating case.

您与反射器看到的是,首创置业正在调用相关的Win32 API的异步版本。举个例子,我将讨论文件和套接字:

What you see with Reflector is that the BCL is calling the async versions of the relevant Win32 APIs. As an example, I'll examine files and sockets:

  • FileStream.BeginRead 间接调用 Win32Native.ReadFileNative 用指针 NativeOverlapped 结构。通过调用 Overlapped.Pack 获得的指针。在完成回调存储的方式。这是不可能来跟踪回调被调用,反射器,因为该部分存在于CLR的本地部分。我不能告诉IOCP是否在使用,但我可以告诉大家,异步IO正在使用中。
  • Socket.BeginRead 间接调用的WSARecv 。在code是相当复杂的。首创置业似乎能够使用重叠的IO以及IOCP取决于操作系统。该检查是在 Socket.InitializeSockets 。用什么样的IO的决定,存储在 Socket.UseOverlappedIO 。如果该变量是假的, Socket.BindToCompletionPort 最终调用。
  • FileStream.BeginRead indirectly calls Win32Native.ReadFileNative with a pointer to a NativeOverlapped structure. The pointer is obtained by calling Overlapped.Pack. The completion callback is stored that way. It is impossible to track how the callback is called with Reflector because that part exists in the native part of the CLR. I cannot tell whether IOCP is in use but I can tell that async IO is in use.
  • Socket.BeginRead indirectly calls WSARecv. The code is quite complex. The BCL seems to be able to use overlapped IO as well as IOCP depending on the OS. The check is made in Socket.InitializeSockets. The decision what kind of IO to use is stored in Socket.UseOverlappedIO. If that variable is false, Socket.BindToCompletionPort is eventually called.

因此​​,对于接这显然是IOCP现代OS'es。对于文件,我不能告诉。

So for Sockets it is clearly IOCP on modern OS'es. For files I cannot tell.

我个人不是特别感兴趣的是什么样异步IO的使用,只要它是非阻塞的。是这种情况。

I personally am not particularly interested in what kind of async IO is used as long as it is non-blocking. This is the case.

这篇关于我在哪里/如何才能找到一个.NET类是否使用IOCP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 02:59