forked from KNEMC/KLALB
KLALB V3.4
This commit is contained in:
@@ -32,7 +32,7 @@ import org.kne.cloud.network.monitor.QueueingMonitorDataImpl;
|
||||
|
||||
public class Kperf implements Runnable{
|
||||
|
||||
|
||||
private KperfReports reports;
|
||||
|
||||
private ConcurrentLinkedQueue<KLALBPacket> IsendDequeList = new ConcurrentLinkedQueue<KLALBPacket>();
|
||||
|
||||
@@ -70,6 +70,18 @@ public class Kperf implements Runnable{
|
||||
|
||||
|
||||
|
||||
public KperfReports getReports() {
|
||||
return reports;
|
||||
}
|
||||
public void setReports(KperfReports reports) {
|
||||
this.reports = reports;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private SpeedLimiter test = new SpeedLimiter(MIN_SPEED,10000000L);
|
||||
|
||||
private static long MIN_SPEED=64*1024L;
|
||||
@@ -77,54 +89,72 @@ public class Kperf implements Runnable{
|
||||
private long congressSpeed = 0;
|
||||
private double loadPercent = 1.01;
|
||||
|
||||
|
||||
|
||||
KLALBPacket testPacket=null;
|
||||
|
||||
private long starttime=System.nanoTime();
|
||||
long totaltime=1000;
|
||||
long usedtime=0;
|
||||
//kperf {KLALB_Stream}[2486:1:f189:7589:f1f7:6f5e:b2eb:1]:4564
|
||||
//kperf {KLALB_Stream}[2486:1::8888]:4564
|
||||
@Override
|
||||
public void run() {
|
||||
Thread tc = ThreadTool.makeVDaemonThreadIfSupport("测速控制线程", () -> {
|
||||
final int wtimes=5;
|
||||
totaltime=(20*1000*1+20*1000*4+wtimes*1000*5)*1000000L;
|
||||
starttime=System.nanoTime();
|
||||
System.out.println("测速开始!");
|
||||
try {
|
||||
long startTime;
|
||||
|
||||
/*System.out.println("测试1/4:延迟测试");
|
||||
System.out.println("测试1/5:延迟测试");
|
||||
test.setLimitspeed(0);
|
||||
startTime=System.nanoTime();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("上传延迟:%.3fms 下载延迟:%.3fms\n", monitor.getOutDelay()/1000000.0,monitor.getInDelay()/1000000.0);
|
||||
Thread.sleep(1000);
|
||||
updateUsedTime();
|
||||
}
|
||||
System.out.printf("上传延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms\n",monitor.getOutDelayMin()/1000000.0,monitor.getOutDelayAvg()/1000000.0,monitor.getOutJitter()/1000000.0);
|
||||
System.out.printf("下载延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms\n",monitor.getInDelayMin()/1000000.0,monitor.getInDelayAvg()/1000000.0,monitor.getInJitter()/1000000.0);
|
||||
|
||||
if(reports!=null) {
|
||||
monitor.setOutDelay(monitor.getOutDelayAvg());
|
||||
monitor.setInDelay(monitor.getInDelayAvg());
|
||||
}
|
||||
System.out.println("等待时间"+wtimes+"s");
|
||||
Thread.sleep(wtimes*1000);
|
||||
Thread.sleep(wtimes*1000);
|
||||
|
||||
|
||||
*/
|
||||
startTime=System.nanoTime();
|
||||
if(targetAddress!=null) {
|
||||
System.out.println("测试2/4:下载带宽测试");
|
||||
System.out.println("测试2/5:下载带宽测试");
|
||||
test.setLimitspeed(0);
|
||||
testPacket=new TESTNPacket(60000);
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("下载带宽:%s/s\n", KLALBUtils.bytesUnit(monitor.getInSpeedAvg()));
|
||||
System.out.printf("下载带宽:%s/s\n", KLALBUtils.convertIBUint(monitor.getInSpeedAvg()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
System.out.printf("下载带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.bytesUnit(monitor.getInSpeedAvg2()),KLALBUtils.bytesUnit(monitor.getInSpeedMax2()));
|
||||
System.out.printf("下载带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.convertIBUint(monitor.getInSpeedAvg2()),KLALBUtils.convertIBUint(monitor.getInSpeedMax2()));
|
||||
if(reports!=null) {
|
||||
reports.downloadSpeedFinish(monitor.getInSpeedAvg2());
|
||||
}
|
||||
}else {
|
||||
System.out.println("测试2/4:上传带宽测试");
|
||||
System.out.println("测试2/5:上传带宽测试");
|
||||
test.setLimitspeed(1000L*1024L*1024L*1024L);
|
||||
testPacket=new TESTNPacket(60000);
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("上传带宽:%s/s\n", KLALBUtils.bytesUnit(monitor.getOutSpeedAvg()));
|
||||
System.out.printf("上传带宽:%s/s\n", KLALBUtils.convertIBUint(monitor.getOutSpeedAvg()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
System.out.printf("上传带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.bytesUnit(monitor.getOutSpeedAvg2()),KLALBUtils.bytesUnit(monitor.getOutSpeedMax2()));
|
||||
System.out.printf("上传带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.convertIBUint(monitor.getOutSpeedAvg2()),KLALBUtils.convertIBUint(monitor.getOutSpeedMax2()));
|
||||
if(reports!=null) {
|
||||
reports.uploadSpeedFinish(monitor.getOutSpeedAvg2());
|
||||
}
|
||||
}
|
||||
System.out.println("等待时间"+wtimes+"s");
|
||||
Thread.sleep(wtimes*1000);
|
||||
@@ -133,26 +163,31 @@ public class Kperf implements Runnable{
|
||||
|
||||
startTime=System.nanoTime();
|
||||
if(targetAddress!=null) {
|
||||
System.out.println("测试3/4:上传带宽测试");
|
||||
System.out.println("测试3/5:上传带宽测试");
|
||||
test.setLimitspeed(1000L*1024L*1024L*1024L);
|
||||
testPacket=new TESTNPacket(60000);
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("上传带宽:%s/s\n", KLALBUtils.bytesUnit(monitor.getOutSpeedAvg()));
|
||||
System.out.printf("上传带宽:%s/s\n", KLALBUtils.convertIBUint(monitor.getOutSpeedAvg()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
System.out.printf("上传带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.bytesUnit(monitor.getOutSpeedAvg2()),KLALBUtils.bytesUnit(monitor.getOutSpeedMax2()));
|
||||
|
||||
System.out.printf("上传带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.convertIBUint(monitor.getOutSpeedAvg2()),KLALBUtils.convertIBUint(monitor.getOutSpeedMax2()));
|
||||
if(reports!=null) {
|
||||
reports.uploadSpeedFinish(monitor.getOutSpeedAvg2());
|
||||
}
|
||||
}else {
|
||||
System.out.println("测试3/4:下载带宽测试");
|
||||
System.out.println("测试3/5:下载带宽测试");
|
||||
test.setLimitspeed(0);
|
||||
testPacket=new TESTNPacket(60000);
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("下载带宽:%s/s\n", KLALBUtils.bytesUnit(monitor.getInSpeedAvg()));
|
||||
System.out.printf("下载带宽:%s/s\n", KLALBUtils.convertIBUint(monitor.getInSpeedAvg()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
System.out.printf("下载带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.bytesUnit(monitor.getInSpeedAvg2()),KLALBUtils.bytesUnit(monitor.getInSpeedMax2()));
|
||||
System.out.printf("下载带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.convertIBUint(monitor.getInSpeedAvg2()),KLALBUtils.convertIBUint(monitor.getInSpeedMax2()));
|
||||
if(reports!=null) {
|
||||
reports.downloadSpeedFinish(monitor.getInSpeedAvg2());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("等待时间"+wtimes+"s");
|
||||
@@ -160,59 +195,72 @@ public class Kperf implements Runnable{
|
||||
|
||||
startTime=System.nanoTime();
|
||||
if(targetAddress!=null) {
|
||||
System.out.println("测试2/4:下载包转发率测试");
|
||||
System.out.println("测试4/5:下载包转发率测试");
|
||||
test.setLimitspeed(0);
|
||||
testPacket=new TEST1Packet();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("下载包转发率:%sPPS\n", KLALBUtils.defaultUnit(monitor.getInPPS()));
|
||||
System.out.printf("下载包转发率:%sPPS\n", KLALBUtils.convertUintDefalut(monitor.getInPPS()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
if(reports!=null) {
|
||||
reports.downloadPPSFinish(monitor.getInPPSAvg());
|
||||
}
|
||||
}else {
|
||||
System.out.println("测试2/4:上传包转发率测试");
|
||||
System.out.println("测试4/5:上传包转发率测试");
|
||||
test.setLimitspeed(1000L*1024L*1024L*1024L);
|
||||
testPacket=new TEST1Packet();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("上传包转发率:%sPPS\n", KLALBUtils.defaultUnit(monitor.getOutPPS()));
|
||||
System.out.printf("上传包转发率:%sPPS\n", KLALBUtils.convertUintDefalut(monitor.getOutPPS()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
//System.out.printf("上传带宽 平均:%s/s 最大:%s/s\n",KLALBUtils.bytesUnit(monitor.getOutSpeedAvg2()),KLALBUtils.bytesUnit(monitor.getOutSpeedMax2()));
|
||||
if(reports!=null) {
|
||||
reports.uploadPPSFinish(monitor.getOutPPSAvg());
|
||||
}
|
||||
}
|
||||
System.out.println("等待时间"+wtimes+"s");
|
||||
Thread.sleep(wtimes*1000);
|
||||
|
||||
startTime=System.nanoTime();
|
||||
if(targetAddress!=null) {
|
||||
System.out.println("测试3/4:上传包转发率测试");
|
||||
System.out.println("测试5/5:上传包转发率测试");
|
||||
test.setLimitspeed(1000L*1024L*1024L*1024L);
|
||||
testPacket=new TEST1Packet();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("上传包转发率:%sPPS\n", KLALBUtils.defaultUnit(monitor.getOutPPS()));
|
||||
System.out.printf("上传包转发率:%sPPS\n", KLALBUtils.convertUintDefalut(monitor.getOutPPS()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
if(reports!=null) {
|
||||
reports.uploadPPSFinish(monitor.getOutPPSAvg());
|
||||
}
|
||||
}else {
|
||||
System.out.println("测试3/4:下载包转发率测试");
|
||||
System.out.println("测试5/5:下载包转发率测试");
|
||||
test.setLimitspeed(0);
|
||||
testPacket=new TEST1Packet();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf("%.2fs\t", (System.nanoTime()- startTime)/1000000000.0);
|
||||
System.out.printf("下载包转发率:%sPPS\n", KLALBUtils.defaultUnit(monitor.getInPPS()));
|
||||
System.out.printf("下载包转发率:%sPPS\n", KLALBUtils.convertUintDefalut(monitor.getInPPS()));
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
if(reports!=null) {
|
||||
reports.downloadPPSFinish(monitor.getInPPSAvg());
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println("等待时间"+wtimes+"s");
|
||||
Thread.sleep(wtimes*1000);
|
||||
|
||||
System.out.println("测速结束!");
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("测速被中断!");
|
||||
//System.out.println("测速被中断!");
|
||||
}finally {
|
||||
close();
|
||||
if(reports!=null)
|
||||
reports.testFinish();
|
||||
System.out.println("测速结束!");
|
||||
}
|
||||
});
|
||||
try {
|
||||
@@ -233,7 +281,7 @@ public class Kperf implements Runnable{
|
||||
// TimeDebugger tdb=new TimeDebugger();
|
||||
// tdb.putTime("start");
|
||||
if(checkBandwidthReportTime()) {
|
||||
writePacketToKPL(new BWINFPacket(monitor.getOutSpeedAvg2(), monitor.getInSpeedAvg2()));
|
||||
writePacketToKPL(new BWINFPacket(monitor.getOutSpeedAvg(), monitor.getInSpeedAvg()));
|
||||
}
|
||||
if (checkPingTimeSleep()) {
|
||||
writePacketToKPL(new PINGPacket(System.nanoTime()));
|
||||
@@ -246,7 +294,7 @@ public class Kperf implements Runnable{
|
||||
}else {
|
||||
|
||||
KLALBPacket testp=testPacket;
|
||||
if (testp!=null&&test.checkTransmit(testp.getLength())) {
|
||||
if (testp!=null&&test.checkTransmit(testp.getTotalLength())) {
|
||||
writePacketToKPL(testp);
|
||||
|
||||
|
||||
@@ -339,8 +387,11 @@ public class Kperf implements Runnable{
|
||||
//double load = 1 - monitor.getOutDelayMin() / (double) monitor.getOutDelay();
|
||||
loadPercent =Math.max( 1.2,0.4);
|
||||
}
|
||||
|
||||
|
||||
LockSupport.unpark(tlock);
|
||||
updateUsedTime() ;
|
||||
if(reports!=null)
|
||||
reports.updateDial(monitor);
|
||||
break;
|
||||
case KLALBPacket.BWINF:
|
||||
BWINFPacket bwi = (BWINFPacket) kpp;
|
||||
@@ -375,6 +426,18 @@ public class Kperf implements Runnable{
|
||||
tc.interrupt();
|
||||
}
|
||||
}
|
||||
private void updateUsedTime() {
|
||||
usedtime=System.nanoTime()-starttime;
|
||||
//System.out.println(usedtime+" "+totaltime);
|
||||
if(reports!=null)
|
||||
reports.testProcess(usedtime/(double)totaltime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private volatile long time = System.nanoTime();
|
||||
private volatile long pingInterval = 10000000L;
|
||||
private volatile long pingIntervalSleep = 200000000L;
|
||||
@@ -450,17 +513,17 @@ public class Kperf implements Runnable{
|
||||
}
|
||||
if (packet != null) {
|
||||
packet.putTimePassport("received");
|
||||
long length=packet.getLength();
|
||||
monitor.getInTrafficAL().addAndGet(length);
|
||||
monitor.getInPacketCounterAL().incrementAndGet();
|
||||
long length=packet.getTotalLength();
|
||||
monitor.getInTrafficAL().add(length);
|
||||
monitor.getInPacketCounterAL().add(1);
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
private void writePacketToKPL(KLALBPacket packet) throws IOException {
|
||||
long length=packet.getLength();
|
||||
monitor.getOutTrafficAL().addAndGet(length);
|
||||
monitor.getOutPacketCounterAL().incrementAndGet();
|
||||
long length=packet.getTotalLength();
|
||||
monitor.getOutTrafficAL().add(length);
|
||||
monitor.getOutPacketCounterAL().add(1);
|
||||
link.writeKLALBPacket(packet);
|
||||
link.flush();
|
||||
packet.putTimePassport("sended");
|
||||
|
||||
Reference in New Issue
Block a user