How to calculate bandwidth using c#

牧云@^-^@ 提交于 2019-12-22 18:48:14

问题


I want to measure bandwidh using c#. Here what I did. Comments and suggestions are welcome.

  1. Find maximum udp payload(on my test bed, its 1472 byte)
  2. Create non compressible data with 1472 byte size
  3. Send this data from a server to a client multiple times(on my test, its 5000 packets)
  4. Client start stopwatch at the time the first packet arrive
  5. When all data has been sent, send notification to client stating all data has been sent
  6. Client stop stopwatch
  7. I calculate bandwidth as (total packet sent(5000) * MTU(1500bytes)) / time lapse
  8. I notice that some packets are loss. a best, 20% loss. at worst 40% loss. I did not account this when calculating the bandwidth. I suspect client network device experience buffer overrun. Do I need to take account this factor?

If you guys have any suggestion or comment, feel free to do so.

Thanks.


回答1:


To calculate bandwith, I would use TCP instead of UDP. When you use UDP all the datagrams may get out really fast through your network card (at 100mbps) and get queued at the "slowest link" of the chain (e.g. a 512kbps cable modem/router). If the queue buffer gets full, its likely that datagrams will be discarded. So your test is not very reliable.

I would use TCP and make some math to transform tcp speed (KB/s) to throughput (Mbps) (I think TCP overhead is around 8%)



来源:https://stackoverflow.com/questions/4167278/how-to-calculate-bandwidth-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!