Hi!
I'm trying to write a stress-tester for lan.
Looking at the Network-Load in the Taskmanager it seems i can only transfer about 500MBit/sec on a GBit Networkcard (i checked all the Adapter settings)
Sending from Both Sides gives my a network load of almost 100%.
But sending the received packet back only gives me about 70% network-load.
Why can't I send more packets per second?
The funny thing is, sending from both sides at a packet size of 1024bytes gives me approx 70% load.
Sending a 10240byte (way too big!)Packet Server to client(while sending a 1024byte client to server) gives me almost 100% load.
can anyone explain this?
Best Regards Daniel
Client sending to Server CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Threading;
using System.Timers;
using System.Net;
using System.Diagnostics;
namespace UDP_StressClient
{
class Program
{
private static System.Timers.Timer timer;
private static Receiver rcv;
private static Sender snd;
private const int PACKET = 1024;
public const int OVERHEAD = 28;
private static Stopwatch sw = new Stopwatch();
static void Main(string[] args)
{
Thread supervisor = new Thread(threadSupervisor);
supervisor.Start();
}
public static void threadSupervisor()
{
UdpClient udpClient = new UdpClient(399);
snd = new Sender(udpClient);
Thread threadSender = new Thread(snd.Send);
threadSender.Start();
rcv = new Receiver(udpClient);
Thread threadReceiver = new Thread(rcv.ReceiveData);
timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.AutoReset = true;
timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
timer.Start();
sw.Start();
}
private static void TimerElapsed(object sender, EventArgs e)
{
try
{
long outSpeed = (snd.nPacket * PACKET + OVERHEAD) / 131072;
snd.nPacket = 0;
Console.Clear();
Console.SetCursorPosition(1, 0);
Console.Write("out: " + outSpeed.ToString() + "Mbit/sec");
long inSpeed = (rcv.nPacket * PACKET + OVERHEAD) / 131072;
rcv.nPacket = 0;
Console.SetCursorPosition(1, 1);
Console.Write("in: " + inSpeed.ToString() + "Mbit/sec");
}
catch (Exception ex)
{
}
}
}
class Sender
{
public bool isSending = true;
private UdpClient udpClient;
const int BYTES = 1024;
private static byte[] data = new byte[BYTES];
public long nPacket;
public List<string> chksum = new List<string>();
public Sender(UdpClient udpClient)
{
this.udpClient = udpClient;
}
public void Send()
{
while (isSending)
{
udpClient.Send(data, data.Length, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("192.168.0.3"), 399));
nPacket++;
}
}
private byte[] CreatePacket()
{
byte[] data = new byte[BYTES];
Random rnd = new Random();
rnd.NextBytes(data);
chksum.Add(CalculateChecksum(data));
return data;
}
private string CalculateChecksum(byte[] dataToCalculate)
{
byte[] byteToCalculate = dataToCalculate;
int checksum = 0;
foreach (byte chData in byteToCalculate)
{
checksum += chData;
}
checksum &= 0xff;
return checksum.ToString("X2");
}
}
class Receiver
{
public bool isReceiving = true;
private UdpClient udpClient;
const int BYTES = 2048;
private static byte[] buffer = new byte[BYTES];
public long nPacket;
public List<string> chksum = new List<string>();
public Receiver(UdpClient udpClient)
{
this.udpClient = udpClient;
}
public void ReceiveData()
{
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 399);
while (isReceiving)
{
nPacket++;
byte[] buffer = udpClient.Receive(ref RemoteIpEndPoint);
}
}
}
}
Server sending to Client
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Timers;
namespace UDP_StressServer
{
class Program
{
private static Receiver rcv;
private static System.Timers.Timer timer = new System.Timers.Timer();
private static UdpClient udpClient;
private static IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.2"), 399);
static void Main(string[] args)
{
UdpClient udpClient = new UdpClient(399);
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.2"), 399);
Receiver rcv = new Receiver(udpClient);
Thread threadReceiver = new Thread(rcv.ReceiveData);
Thread threadSender = new Thread(rcv.SendData);
threadReceiver.Start();
threadSender.Start();
}
}
class Receiver
{
public bool isReceiving = true;
UdpClient udpClient;
public List<byte[]> inBuffer= new List<byte[]>();
private byte[] buffer = new byte[1024];
public Receiver(UdpClient udpClient)
{
this.udpClient = udpClient;
}
public void ReceiveData()
{
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.2"), 399);
while (isReceiving)
{
udpClient.Send(buffer, buffer.Length, remoteIPEndPoint);
}
}
public void SendData()
{
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Parse("192.168.0.2"), 399);
while (true)
{
}
}
}
}