[英]Socket exception on Hyper-V machine
Recently, our entire QA environment moved from VMWare to Hyper-V virtual machines. 最近,我们的整个QA环境从VMWare迁移到Hyper-V虚拟机。
One of our applications sends UDP packets to a multicast cloud by a rate of 20K packets per second. 我们的一个应用程序以每秒20K数据包的速率将UDP数据包发送到多播云。
While that worked perfectly on the VMWare environment, the Hyper-V makes the application to throw the following exception after a couple minutes of work: 虽然这在VMWare环境中运行良好,但Hyper-V使应用程序在几分钟的工作后抛出以下异常:
System.Net.Sockets.SocketException (0x80004005): An invalid argument was supplied
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
I've also managed to mimic this issue instantly when defining the socket's sending buffer size to 1,000,000 bytes. 在将套接字的发送缓冲区大小定义为1,000,000字节时,我还设法立即模仿了这个问题。
How can I resolve this issue? 我该如何解决这个问题?
UPDATE 1 : This is a log entry from the event viewer once the exception happens: 更新1 :一旦发生异常,这是来自事件查看器的日志条目:
Faulting application name: Agent.exe, version: 1.0.12.7366, time stamp: 0x51389f69
Faulting module name: KERNELBASE.dll, version: 6.1.7601.18015, time stamp: 0x50b83c8a
Exception code: 0xe0434352
Fault offset: 0x0000c41f
Faulting process id: 0xaf0
Faulting application start time: 0x01ce1b4ce509dc7a
Faulting application path: C:\Users\DevUser\Desktop\QA\Agent.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: d2b45dce-8740-11e2-86f9-00155d022804
UPDATE 2 : The size of the UDP packet is 100-200 bytes. 更新2 :UDP数据包的大小为100-200字节。
UPDATE 3 : Here is the problematic code: 更新3 :这是有问题的代码:
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
m_socket.Ttl = 1;
if (GetRawParameter("send") != null)
{
Log("Starting sender...");
StartSender();
}
...snip...
private static void StartSender()
{
m_lastPacketNumber = 0;
m_socket.Connect(new IPEndPoint(m_ipAddress, m_port));
if (m_bufferSize > 0)
m_socket.SetSocketOption(
SocketOptionLevel.Socket, SocketOptionName.SendBuffer, m_bufferSize);
byte[] dataPad = null;
if (m_packetSize > 8)
{
dataPad = new byte[m_packetSize - sizeof(long)];
for (int i = 0; i < dataPad.Length; i++)
{
dataPad[i] = 0xFF;
}
}
while (true)
{
Log("Sending data...");
for (int i = 0; i < m_packetsPerSec; i++)
{
var data = BitConverter.GetBytes(m_lastPacketNumber.Value);
if (dataPad != null)
data = data.Concat(dataPad).ToArray();
if (m_packetDump != null)
m_packetDump.Add(m_lastPacketNumber.Value);
m_socket.Send(data);
if (m_usePerformanceCounters)
IncreaseSendCounters(1);
m_lastPacketNumber++;
}
Log(m_lastPacketNumber + " packets sent.");
Thread.Sleep(1000);
}
}
UPDATE 4 : the failed Send() seems to happen on the #14156 or #32485 or #25412 packet (not the first one!) when I try to send 100K of packets per second. 更新4 :当我尝试每秒发送100K数据包时,失败的Send()似乎发生在#14156或#32485或#25412数据包(不是第一个!)上。
Could you "roll up" the packets so that you are sending far less packets of larger size...and then un-roll them on the other side? 你可以“卷起”数据包,以便你发送更少的更大的数据包...然后在另一边解开它们吗? 20k packets/second is a lot of sendto's.
20k包/秒是很多sendto的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.