简体   繁体   English

Windows(最好是C#)-如何确定我们不是从套接字快速读取数据

[英]Windows (C# preferably) - How to find out that we are not reading data from socket fast enaugh

If I am not reading data from socket fast enough, the TCP protocol will decrease sliding windows size and sender might get blocked during sending (as discussed here what happens when I don't manage to call `recv` fast enough? ). 如果我没有足够快地从套接字读取数据,则TCP协议将减小滑动窗口的大小,并且发送方可能在发送期间被阻塞(如此处所讨论的, 当我无法足够快地调用`recv`时会发生什么? )。

How do I detect this situation on receiver side on Windows - preferably directly in C# code and without impacting the performance of reading from socket? 如何在Windows的接收器端检测这种情况-最好直接在C#代码中而不影响从套接字读取的性能? Other monitoring solution (perfmon, wireshark) is also acceptable but far less optimal for my scenario. 其他监视解决方案(perfmon,wireshark)也是可以接受的,但对于我的方案而言,并不是最佳选择。

What is the exact scenario? 确切的情况是什么? Let's say the server app can transmit data with speed up to 1Mbps, however my client app is able to receive the data only with the speed of 0.5Mbps. 假设服务器应用程序可以以高达1Mbps的速度传输数据,但是我的客户端应用程序只能以0.5Mbps的速度接收数据。 How do I find out in the client application that TCP flow control is kicking in and decreasing the transmit speed? 如何在客户端应用程序中发现TCP流控制正在起作用并降低传输速度?

I came over Socket.Available property http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.available.aspx and was wondering if that might be recomendable way of querying this information? 我遇到了Socket.Available属性http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.available.aspx ,想知道这是否可能是查询此信息的推荐方法?

You would be better off reading as fast as you possibly can, rather than wasting time trying to have the system tell you you're not reading fast enough, which can only slow down your reading even further. 您最好以尽可能快的速度阅读,而不是浪费时间尝试让系统告诉您阅读速度不够快,这只会进一步降低阅读速度。 If you're reading at maximum speed and the sender is still getting blocked, TCP is working correctly and there is nothing you can do about it, except maybe look into a faster machine. 如果您以最大速度阅读,并且发送方仍被阻止,则说明TCP正常工作,您无能为力,除非您考虑使用速度更快的计算机。

The TCP Window is handled by the Kernel and won't be available to you. TCP窗口由内核处理,将无法使用。 I guess you could possibly compare the ReceiveBufferSize with number of bytes Received. 我想您可以将ReceiveBufferSize与接收的字节数进行比较。 If this buffer isn't full, then you are waiting. 如果此缓冲区未满,则您正在等待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM