3

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.

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. using 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();

}

  • do you have anything to compare? UDP is lossy. Mini optimization: don't use LinkedList, you know the size already. You could also try to replace `new Stuff` with a pool of reusable objects. Might be worth it for `PacketInfoContainer` – zapl Dec 07 '12 at 22:20
  • I ran my test, and also iperf using udp with same packet size, at the same speeds, my test gets more packet loss than iperf does on a fairly consistent basis. – user1886543 Dec 08 '12 at 04:54

2 Answers2

1

UDP is not very well... may be you can use TCP & check tcp stats of S.O. to see retransmissions...

netstat -s

you can use CharacterGenerator, change BufferedOutputStream to 64KB and removing os.flush(); to speedup and test...

ggrandes
  • 2,067
  • 22
  • 16
1

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.

Community
  • 1
  • 1
Johnny V
  • 795
  • 5
  • 14