简体   繁体   English

Java高速udp流量包接收带宽测试

[英]Java high speed udp traffic packet receiving for bandwidth testing

I am trying to build a bandwidth testing tool, kind of like IPerf but in java, I seem to be getting more packet loss than expected however at slightly higher bandwidths (starts at about 30-40Mb/s) and I was hoping someone could possibly point out some optimization or something that I am doing wrong that would cause me to be missing packets. 我正在尝试构建带宽测试工具,有点像IPerf,但在java中,我似乎比预期更多的数据包丢失但是在稍高的带宽(开始于大约30-40Mb / s)时我希望有人可能指出一些优化或我做错的事情会导致我丢失数据包。

this is the receiving code, which hands off queues of size 2000 to another class which gathers metrics, it only passes relevant information from the packet. 这是接收代码,它将大小为2000的队列移交给收集指标的另一个类,它只传递来自数据包的相关信息。 using NIO 使用NIO

while (data.isRunning()) 
{
    if(channel.receive(buf) != null)
    {

    int j = buf.array().length;
    //add the packets important information to the queue
    packet_info.add(new PacketInfoContainer(buf.getLong(j-12), System.nanoTime(), buf.getInt(j-4)));

    // if we have 2000 packets worth of information, time to handle it!
    if((packet_info.size() == 2000))
    {
        Runnable r1;
        //if this is running on the client side, do it this way so that we can calculate progress
        if(client_side)
        {
            if(data_con.isUserRequestStop())
            {
                System.out.println("suposed to quit");
                data.stopTest();
                break;
            }
            if(packets_expected > 0)
            {
                total_packets_received+=1000;
                setChanged();
                notifyObservers("update_progress" + Integer.toString( (int) (((double)total_packets_received/(double)packets_expected) * 1000) ) );
            }
            r1 = new PacketHandler(packet_info, results, buffer_size, client);
        }
        //server side, no nonsense
        else
        {
            r1 = new PacketHandler(packet_info, results, buffer_size);
        }
        pool.submit(r1);
        packet_info = new LinkedList<PacketInfoContainer>();
    }

}
buf.clear();

} }

UDP is not very well... may be you can use TCP & check tcp stats of SO to see retransmissions... UDP不是很好......可能你可以使用TCP和检查SO的tcp统计数据来查看重传...

netstat -s netstat -s

you can use CharacterGenerator , change BufferedOutputStream to 64KB and removing os.flush(); 你可以使用CharacterGenerator ,将BufferedOutputStream更改为64KB并删除os.flush(); to speedup and test... 加速和测试......

It won't allow me to comment yet, here I go. 它不允许我发表评论,我走了。

You shouldn't be seeing dropped packets until the wire limit is hit. 在线路限制被击中之前,您不应该看到丢弃的数据包。 I suggest isolating the problem of dropped packets and using tools to figure out if you have a hardware / environment problem before spending lots of time looking at your code. 我建议隔离丢包的问题,​​并使用工具在花费大量时间查看代码之前弄清楚是否存在硬件/环境问题。

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

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