Does anyone know a good article / link explaining how .NET sockets use I / O completion ports under the hood?
I suspect that the only reference will be the implementation (i.e. the reflector or another assembly compiler). With this, you will find that all asynchronous IOs go through the I / O completion port with callbacks processed in the IO thread pool (which is separate for the regular thread pool).
use 5 completion ports
I would expect to use one completion port that processes all IOs into one thread pool with one thread to complete the pool maintenance (assuming that you are running any other IO, including disk, asynchronously).
Multiple completion ports will make sense if you have some form of prioritization.
My question is this: should I expect the same performance using C ++ sockets and C # sockets?
Yes or no, depending on how narrowly you define the "using ... socket" part. As for operations from the beginning of the asynchronous operation until the completion is sent to the completion port, I would not expect a significant difference (all processing is performed in the Win32 API or the Windows kernel).
However, the security that the .NET runtime provides will add some overhead. For example. the length of the buffers will be checked, delegated, etc. If the limit for the application is the CPU, then this is likely to change the situation, and in a pinch, a small difference can easily add up.
Also, the .NET version is sometimes suspended for GC (.NET 4.5 makes an asynchronous collection, so this will improve in the future). There are methods to minimize garbage accumulation (for example, reuse objects, rather than create them, use structures, while avoiding boxing).
After all, if the C ++ version works and meets your performance needs, why a port?
Richard Dec 11 '11 at 17:04 2011-12-11 17:04
source share