我正在尝试构建一个带宽测试工具,有点像IPerf,但是在java中,我的丢包似乎比预期的要多,但是带宽稍微高一些(从30-40 me /s开始),我希望有人能指出一些优化或者我做错了什么事情,这会导致我丢失数据包。
这是接收代码,它将大小为2000的队列传递给另一个收集度量的类,它只从数据包传递相关信息。使用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();}
发布于 2013-01-05 22:06:54
UDP不是很好。也许你可以使用TCP &检查S.O.的tcp状态来查看重传.
netstat -s
您可以使用CharacterGenerator,将BufferedOutputStream更改为64 to并删除os.flush();以加速和测试.
发布于 2016-08-07 11:36:09
这还不能让我发表评论,我来了。
你不应该看到掉落的数据包,直到线路限制被击中。我建议在花费大量时间查看代码之前,隔离掉数据包的问题,并使用工具来确定是否存在硬件/环境问题。
iperf吗?然后检查丢弃的数据包统计信息??https://iperf.fr/iperf-doc.phpbmon是一个简洁的工具,它将显示carrier error、dropped、fifo error的统计信息。https://stackoverflow.com/questions/13770553
复制相似问题