我們有一個生產系統從遠程設備收集遙測數據。這些數據以合理的頻率發送,我們最終在高峯時間每秒接收數千條消息。有效載荷大約爲每條消息80個字節。我開始對各種存儲機制進行一些性能測試,但是我首先想到的是,我會試着看看在沒有涉及任何數據存儲的情況下我能夠多快地推送UDP。我在本地計算機上每秒獲得大約70,000條消息的最大吞吐量(如果使用另一臺計算機發送測試數據,似乎大致相同)。從我的粗略計算來看,由於網絡鏈路容量的原因,這比我預期的要低。發送者坐在發送數據的緊密循環中。我完全知道UDP re的所有問題;丟失數據包等。我只想了解我們的系統薄弱點。C#UDPClient不良吞吐量
由於小包大小,吞吐量如此之低?
馬特
private IPEndPoint _receiveEndpoint = new IPEndPoint(IPAddress.Any, _receivePort);
private Stopwatch sw = new Stopwatch();
private int _recievedCount = 0;
private long _lastCount = 0;
private Thread _receiverThread;
private bool _running = true;
_clientReceive = new UdpClient();
_clientReceive.Client.Bind(_receiveEndpoint);
_receiverThread = new Thread(DoReceive);
_receiverThread.Start();
while (_running)
{
Byte[] receiveBytes = _clientReceive.Receive(ref _receiveEndpoint);
_clientReceive.Receive(ref _receiveEndpoint);
if (!sw.IsRunning)
sw.Start();
string receiveString = Encoding.ASCII.GetString(receiveBytes);
_recievedCount = ++_recievedCount;
long howLong = sw.ElapsedMilliseconds;
if (howLong/1000 > _lastCount)
{
_lastCount = howLong/1000;
Invoke(new MethodInvoker(() => { Text = _recievedCount + " iterations in " + sw.ElapsedMilliseconds + " msecs"; }));
}
}
是的,我們在這個領域有成千上萬的這些設備,雖然我們可以遠程重新編程它,但它在蜂窩通信中的成本非常高,而且還是一本相當手冊處理。我所看到的這種情況發生在我們有一個手機供應商停機時,遙測設備排隊消息,然後當他們看到我們重新聯機時立即將它們全部交付。這是相當罕見的,但是當它發生時,我們很難受到打擊。我們設計了我們自己造成的DOS攻擊! – 2010-08-31 07:23:35