在.NET中分散/收集异步套接字I / O.

时间:2022-12-31 09:40:39

I'm trying to use the Stream.BeginWrite Async I/O API in .NET for a high-throughput situation with many short messages. As such, a scatter/gather API will reduce the number of context switches (and CPU usage) tremendously. Does this API use the LPBUFFERS Win32 API at all? Is there an alternative API for Scatter/Gather I/O?

我正在尝试在.NET中使用Stream.BeginWrite异步I / O API,以获得包含许多短消息的高吞吐量情况。因此,分散/聚集API将极大地减少上下文切换(和CPU使用)的数量。这个API是否完全使用LPBUFFERS Win32 API?是否有Scatter / Gather I / O的替代API?

4 个解决方案

#1


2  

Looking at the .net sources, the accepted answer seems to be wrong.

看看.net来源,接受的答案似乎是错误的。

SocketAsyncEventArgs has a BufferList attribute. When that is used, instead of the Buffer attribute that can only hold a single contiguous block of memory, operations can make use of scatter/gather DMA, as Socket.SendAsync(SocketAsyncEventArgs) uses WSASend internally, that

SocketAsyncEventArgs具有BufferList属性。当使用它时,操作可以使用分散/聚集DMA,而不是只能容纳单个连续内存块的Buffer属性,因为Socket.SendAsync(SocketAsyncEventArgs)在内部使用WSASend,

allows multiple send buffers to be specified making it applicable to the scatter/gather type of I/O

允许指定多个发送缓冲区,使其适用于I / O的分散/聚集类型

and Socket.SendAsync(SocketAsyncEventArgs) uses WSARecv, that

和Socket.SendAsync(SocketAsyncEventArgs)使用WSARecv,即

allows multiple receive buffers to be specified making it applicable to the scatter/gather type of I/O

允许指定多个接收缓冲区,使其适用于I / O的分散/聚集类型

I don't have the .net 3.5 sources handy, but BufferList exists since .net 3.5, so scatter/gather might have been supported since .net 3.5. The minimum OS requirements for WSASend and WSARecv exist are documented as Windows Vista / Server 2003.

我没有.net 3.5源码,但自.net 3.5以来,BufferList一直存在,因此.net 3.5以来可能支持scatter / gather。存在的WSASend和WSARecv的最低操作系统要求记录为Windows Vista / Server 2003。

N.B. I don't know what stream you are using, but NetworkStream.BeginWrite sends a single buffer to the WSASend, so you cannot use that for scatter/gathering.

注:我不知道你正在使用什么流,但是NetworkStream.BeginWrite会向WSASend发送一个缓冲区,因此你不能将它用于分散/收集。

#2


1  

I would be surprised if you could get to the scatter/gather api's from the BCL (it's for the l33t w1n32 haxx0rz, you know?), but there's always P/Invoke (which is suprisingly easy to use, I've found).

如果你能从BCL那里得到分散/聚集api,我会感到惊讶(你知道吗?对于l33t w1n32 haxx0rz,你知道吗?),但总有P / Invoke(我发现它很容易使用)。

#3


0  

If you want to dig into the guts of the framework, there are a few ways to do it:

如果你想深入了解框架的内容,有几种方法可以做到:

1) Reflector

2) MS recently opened up the source for debugging purposes, you can step into it with VS2008 if you enable the option under Debugging/Options/General

2)MS最近打开了源代码进行调试,如果启用Debugging / Options / General下的选项,可以使用VS2008进入它

3) Koders.com seem to be hosting the framework source too:

3)Koders.com似乎也在托管框架源:

http://www.koders.com/csharp/fidCE09E83BE706D0BD370658C3785E82D3A13FC2CE.aspx?s=flush()#L109

#4


-2  

There is no way to do socket scatter/gather I/O in .NET. According to a MSFT blog post, there may be a similar API in .NET 4.5 (whatever that is...)

在.NET中无法进行套接字分散/收集I / O.根据MSFT博客文章,.NET 4.5中可能存在类似的API(不管是什么......)

#1


2  

Looking at the .net sources, the accepted answer seems to be wrong.

看看.net来源,接受的答案似乎是错误的。

SocketAsyncEventArgs has a BufferList attribute. When that is used, instead of the Buffer attribute that can only hold a single contiguous block of memory, operations can make use of scatter/gather DMA, as Socket.SendAsync(SocketAsyncEventArgs) uses WSASend internally, that

SocketAsyncEventArgs具有BufferList属性。当使用它时,操作可以使用分散/聚集DMA,而不是只能容纳单个连续内存块的Buffer属性,因为Socket.SendAsync(SocketAsyncEventArgs)在内部使用WSASend,

allows multiple send buffers to be specified making it applicable to the scatter/gather type of I/O

允许指定多个发送缓冲区,使其适用于I / O的分散/聚集类型

and Socket.SendAsync(SocketAsyncEventArgs) uses WSARecv, that

和Socket.SendAsync(SocketAsyncEventArgs)使用WSARecv,即

allows multiple receive buffers to be specified making it applicable to the scatter/gather type of I/O

允许指定多个接收缓冲区,使其适用于I / O的分散/聚集类型

I don't have the .net 3.5 sources handy, but BufferList exists since .net 3.5, so scatter/gather might have been supported since .net 3.5. The minimum OS requirements for WSASend and WSARecv exist are documented as Windows Vista / Server 2003.

我没有.net 3.5源码,但自.net 3.5以来,BufferList一直存在,因此.net 3.5以来可能支持scatter / gather。存在的WSASend和WSARecv的最低操作系统要求记录为Windows Vista / Server 2003。

N.B. I don't know what stream you are using, but NetworkStream.BeginWrite sends a single buffer to the WSASend, so you cannot use that for scatter/gathering.

注:我不知道你正在使用什么流,但是NetworkStream.BeginWrite会向WSASend发送一个缓冲区,因此你不能将它用于分散/收集。

#2


1  

I would be surprised if you could get to the scatter/gather api's from the BCL (it's for the l33t w1n32 haxx0rz, you know?), but there's always P/Invoke (which is suprisingly easy to use, I've found).

如果你能从BCL那里得到分散/聚集api,我会感到惊讶(你知道吗?对于l33t w1n32 haxx0rz,你知道吗?),但总有P / Invoke(我发现它很容易使用)。

#3


0  

If you want to dig into the guts of the framework, there are a few ways to do it:

如果你想深入了解框架的内容,有几种方法可以做到:

1) Reflector

2) MS recently opened up the source for debugging purposes, you can step into it with VS2008 if you enable the option under Debugging/Options/General

2)MS最近打开了源代码进行调试,如果启用Debugging / Options / General下的选项,可以使用VS2008进入它

3) Koders.com seem to be hosting the framework source too:

3)Koders.com似乎也在托管框架源:

http://www.koders.com/csharp/fidCE09E83BE706D0BD370658C3785E82D3A13FC2CE.aspx?s=flush()#L109

#4


-2  

There is no way to do socket scatter/gather I/O in .NET. According to a MSFT blog post, there may be a similar API in .NET 4.5 (whatever that is...)

在.NET中无法进行套接字分散/收集I / O.根据MSFT博客文章,.NET 4.5中可能存在类似的API(不管是什么......)