forked from KNEMC/KLALB
优化代码,性能暴涨
This commit is contained in:
@@ -77,9 +77,9 @@ private TimerTask ptt=new TimerTask() {
|
||||
sb.append(name);
|
||||
sb.append('\n');
|
||||
sb.append(getDsc());
|
||||
sb.append('\t');
|
||||
/*sb.append('\t');
|
||||
sb.append((int)(reliability*100));
|
||||
sb.append('%');
|
||||
sb.append('%');*/
|
||||
return sb.toString();
|
||||
}
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.kne.cloud.network.monitor;
|
||||
|
||||
public class QueueingMonitorDataImpl extends SpeedAndTrafficAndDelayMonitorDataImpl {
|
||||
private long queueingDelay;
|
||||
|
||||
public long getQueueingDelay() {
|
||||
return queueingDelay;
|
||||
}
|
||||
|
||||
public void setQueueingDelay(long queueingDelay) {
|
||||
this.queueingDelay = queueingDelay;
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,24 @@ package org.kne.cloud.network.monitor;
|
||||
public class SpeedAndTrafficAndDelayMonitorDataImpl extends SpeedAndTrafficMonitorDataImpl implements SpeedAndTrafficMonitorData,DelayMonitorData{
|
||||
|
||||
|
||||
@Override
|
||||
protected void createTask() {
|
||||
}
|
||||
public void updateSpeedSync(){
|
||||
tmt.run();
|
||||
}
|
||||
|
||||
private volatile long outDelay;
|
||||
private volatile long outDelayMin=Long.MAX_VALUE;
|
||||
private volatile long outDelayAvg=Long.MAX_VALUE;
|
||||
private long outDelayOld;
|
||||
private volatile long outJitter;
|
||||
|
||||
|
||||
private volatile long inDelay;
|
||||
private volatile long inDelayMin=Long.MAX_VALUE;
|
||||
private volatile long inDelayAvg=Long.MAX_VALUE;
|
||||
private long inDelayOld;
|
||||
private volatile long inJitter;
|
||||
|
||||
|
||||
private volatile long latency;
|
||||
private volatile long latencyMin=Long.MAX_VALUE;
|
||||
private volatile long latencyAvg=Long.MAX_VALUE;
|
||||
private long latencyOld;
|
||||
private volatile long totalJitter;
|
||||
|
||||
@@ -32,6 +29,19 @@ public class SpeedAndTrafficAndDelayMonitorDataImpl extends SpeedAndTrafficMonit
|
||||
|
||||
private volatile long recentPingNanoTime;
|
||||
|
||||
|
||||
|
||||
public long getOutDelayAvg() {
|
||||
return outDelayAvg;
|
||||
}
|
||||
public long getInDelayAvg() {
|
||||
return inDelayAvg;
|
||||
}
|
||||
public long getLatencyAvg() {
|
||||
return latencyAvg;
|
||||
}
|
||||
|
||||
|
||||
public long getRecentPingNanoTime() {
|
||||
return recentPingNanoTime;
|
||||
}
|
||||
@@ -46,18 +56,29 @@ public class SpeedAndTrafficAndDelayMonitorDataImpl extends SpeedAndTrafficMonit
|
||||
@Override
|
||||
public void setOutDelay(long delay) {
|
||||
this.outDelay=delay;
|
||||
if(outDelayAvg==Long.MAX_VALUE) {
|
||||
outDelayAvg=delay;
|
||||
}else {
|
||||
outDelayAvg=(outDelayAvg*9999+delay)/10000;
|
||||
}
|
||||
if(outDelayMin==Long.MAX_VALUE||delay<=outDelayMin) {
|
||||
outDelayMin=delay;
|
||||
}else{
|
||||
outDelayMin=(outDelayMin*9999+delay)/10000;
|
||||
}
|
||||
this.latency=outDelay+inDelay;
|
||||
|
||||
if(latencyAvg==Long.MAX_VALUE) {
|
||||
latencyAvg=latency;
|
||||
}else {
|
||||
latencyAvg=(latencyAvg*9999+latency)/10000;
|
||||
}
|
||||
if(latencyMin==Long.MAX_VALUE||latency<= latencyMin) {
|
||||
latencyMin=latency;
|
||||
}else {
|
||||
latencyMin=(latencyMin*9999+latency)/10000;
|
||||
}
|
||||
outDelayPredicted=outDelay+(outDelay-outDelayOld);
|
||||
outDelayPredicted=outDelay;
|
||||
updateOutJitter();
|
||||
updateTotalJitter();
|
||||
}
|
||||
@@ -70,18 +91,28 @@ public class SpeedAndTrafficAndDelayMonitorDataImpl extends SpeedAndTrafficMonit
|
||||
@Override
|
||||
public void setInDelay(long delay) {
|
||||
this.inDelay=delay;
|
||||
if(inDelayAvg==Long.MAX_VALUE) {
|
||||
inDelayAvg=latency;
|
||||
}else {
|
||||
inDelayAvg=(inDelayAvg*9999+delay)/10000;
|
||||
}
|
||||
if(inDelayMin==Long.MAX_VALUE||delay<=inDelayMin) {
|
||||
inDelayMin=delay;
|
||||
}else{
|
||||
inDelayMin=(inDelayMin*9999+delay)/10000;
|
||||
}
|
||||
this.latency=outDelay+inDelay;
|
||||
if(latencyAvg==Long.MAX_VALUE) {
|
||||
latencyAvg=latency;
|
||||
}else {
|
||||
latencyAvg=(latencyAvg*9999+latency)/10000;
|
||||
}
|
||||
if(latencyMin==Long.MAX_VALUE||latency<= latencyMin) {
|
||||
latencyMin=latency;
|
||||
}else {
|
||||
latencyMin=(latencyMin*9999+latency)/10000;
|
||||
}
|
||||
inDelayPredicted=inDelay+(inDelay-inDelayOld);
|
||||
inDelayPredicted=inDelay;
|
||||
updateInJitter();
|
||||
updateTotalJitter();
|
||||
}
|
||||
@@ -95,6 +126,11 @@ public class SpeedAndTrafficAndDelayMonitorDataImpl extends SpeedAndTrafficMonit
|
||||
@Override
|
||||
public void setLatency(long latency) {
|
||||
this.latency=latency;
|
||||
if(latencyAvg==Long.MAX_VALUE) {
|
||||
latencyAvg=latency;
|
||||
}else {
|
||||
latencyAvg=(latencyAvg*9999+latency)/10000;
|
||||
}
|
||||
if(latencyMin==Long.MAX_VALUE||latency<= latencyMin) {
|
||||
latencyMin=latency;
|
||||
}else {
|
||||
@@ -102,19 +138,30 @@ public class SpeedAndTrafficAndDelayMonitorDataImpl extends SpeedAndTrafficMonit
|
||||
}
|
||||
long tmp= latency>>1;
|
||||
this.inDelay=tmp;
|
||||
if(inDelayAvg==Long.MAX_VALUE) {
|
||||
inDelayAvg=latency;
|
||||
}else {
|
||||
inDelayAvg=(inDelayAvg*9999+tmp)/10000;
|
||||
}
|
||||
if(inDelayMin==Long.MAX_VALUE||tmp<=inDelayMin) {
|
||||
inDelayMin=tmp;
|
||||
}else{
|
||||
inDelayMin=(inDelayMin*9999+tmp)/10000;
|
||||
}
|
||||
|
||||
this.outDelay=tmp;
|
||||
if(outDelayAvg==Long.MAX_VALUE) {
|
||||
outDelayAvg=latency;
|
||||
}else {
|
||||
outDelayAvg=(outDelayAvg*9999+tmp)/10000;
|
||||
}
|
||||
if(outDelayMin==Long.MAX_VALUE||tmp<=outDelayMin) {
|
||||
outDelayMin=tmp;
|
||||
}else{
|
||||
outDelayMin=(outDelayMin*9999+tmp)/10000;
|
||||
}
|
||||
outDelayPredicted=outDelay+(outDelay-outDelayOld);
|
||||
inDelayPredicted=inDelay+(inDelay-inDelayOld);
|
||||
outDelayPredicted=outDelay;
|
||||
inDelayPredicted=inDelay;
|
||||
updateOutJitter();
|
||||
updateInJitter();
|
||||
updateTotalJitter();
|
||||
|
||||
@@ -16,4 +16,19 @@ public long getInSpeed();
|
||||
|
||||
public long getOutSpeed();
|
||||
|
||||
|
||||
public long getInPPS();
|
||||
|
||||
public long getOutPPS();
|
||||
|
||||
public AtomicLong getInPacketCounterAL();
|
||||
|
||||
public AtomicLong getOutPacketCounterAL();
|
||||
|
||||
public long getInPacketCounter();
|
||||
|
||||
|
||||
public long getOutPacketCounter();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
|
||||
private volatile long inSpeedMax;
|
||||
private volatile long outSpeedMax;
|
||||
private volatile long inSpeedMax2;
|
||||
private volatile long outSpeedMax2;
|
||||
|
||||
public SpeedAndTrafficMonitorDataImpl() {
|
||||
super();
|
||||
@@ -101,12 +103,23 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
return outSpeedMax;
|
||||
}
|
||||
|
||||
|
||||
public long getInSpeedMax2() {
|
||||
return inSpeedMax2;
|
||||
}
|
||||
|
||||
|
||||
public long getOutSpeedMax2() {
|
||||
return outSpeedMax2;
|
||||
}
|
||||
|
||||
|
||||
protected TimerTask tmt=new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long d=System.nanoTime()-updatetime;
|
||||
|
||||
if(d!=0) {
|
||||
if(inTraffic!=null) {
|
||||
long i=inTraffic.get()-inTrafficOld;
|
||||
inTrafficOld =inTraffic.get();
|
||||
@@ -119,16 +132,40 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
outSpeed= o*1000000000/d;
|
||||
}
|
||||
|
||||
if(inCounter!=null) {
|
||||
long i=inCounter.get()-inCounterOld;
|
||||
inCounterOld =inCounter.get();
|
||||
inPPS= i*1000000000/d;
|
||||
}
|
||||
if(outCounter!=null) {
|
||||
long i=outCounter.get()-outCounterOld;
|
||||
outCounterOld =outCounter.get();
|
||||
outPPS= i*1000000000/d;
|
||||
}
|
||||
}
|
||||
if(outSpeed>=outSpeedMax) {
|
||||
outSpeedMax=outSpeed;
|
||||
}else {
|
||||
outSpeedMax=(outSpeedMax*999+outSpeed)/1000;
|
||||
outSpeedMax=(outSpeedMax*99+outSpeed)/100;
|
||||
}
|
||||
|
||||
if(inSpeed>=inSpeedMax) {
|
||||
inSpeedMax=inSpeed;
|
||||
}else {
|
||||
inSpeedMax=(inSpeedMax*999+inSpeed)/1000;
|
||||
inSpeedMax=(inSpeedMax*99+inSpeed)/100;
|
||||
}
|
||||
|
||||
|
||||
if(outPPS>=outPPSMax) {
|
||||
outPPSMax=outPPS;
|
||||
}else {
|
||||
outPPSMax=(outPPSMax*99+outPPS)/100;
|
||||
}
|
||||
|
||||
if(inPPS>=inPPSMax) {
|
||||
inPPSMax=inPPS;
|
||||
}else {
|
||||
inPPSMax=(inPPSMax*99+inPPS)/100;
|
||||
}
|
||||
|
||||
updatetime=System.nanoTime();
|
||||
@@ -141,7 +178,7 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
@Override
|
||||
public void run() {
|
||||
long d=System.nanoTime()-updatetime1;
|
||||
|
||||
if(d!=0) {
|
||||
if(inTraffic!=null) {
|
||||
long i=inTraffic.get()-inTrafficOld1;
|
||||
inTrafficOld1 =inTraffic.get();
|
||||
@@ -153,8 +190,19 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
outTrafficOld1 =outTraffic.get();
|
||||
outSpeedAvg= o*1000000000/d;
|
||||
}
|
||||
|
||||
if(inCounter!=null) {
|
||||
long i=inCounter.get()-inCounterOld1;
|
||||
inCounterOld1 =inCounter.get();
|
||||
inPPSAvg= i*1000000000/d;
|
||||
}
|
||||
|
||||
|
||||
if(outCounter!=null) {
|
||||
long o=outCounter.get()-outCounterOld1;
|
||||
outCounterOld1 =outCounter.get();
|
||||
outPPSAvg= o*1000000000/d;
|
||||
}
|
||||
}
|
||||
|
||||
updatetime1=System.nanoTime();
|
||||
|
||||
@@ -166,7 +214,7 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
@Override
|
||||
public void run() {
|
||||
long d=System.nanoTime()-updatetime2;
|
||||
|
||||
if(d!=0) {
|
||||
if(inTraffic!=null) {
|
||||
long i=inTraffic.get()-inTrafficOld2;
|
||||
inTrafficOld2 =inTraffic.get();
|
||||
@@ -180,6 +228,45 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(inCounter!=null) {
|
||||
long i=inCounter.get()-inCounterOld2;
|
||||
inCounterOld2 =inCounter.get();
|
||||
inPPSAvg2= i*1000000000/d;
|
||||
}
|
||||
|
||||
if(outCounter!=null) {
|
||||
long o=outCounter.get()-outCounterOld2;
|
||||
outCounterOld2 =outCounter.get();
|
||||
outPPSAvg2= o*1000000000/d;
|
||||
}
|
||||
}
|
||||
|
||||
if(outSpeedAvg2>=outSpeedMax2) {
|
||||
outSpeedMax2=outSpeedAvg2;
|
||||
}else {
|
||||
outSpeedMax2=(outSpeedMax2*999+outSpeedAvg2)/1000;
|
||||
}
|
||||
|
||||
if(inSpeedAvg2>=inSpeedMax2) {
|
||||
inSpeedMax2=inSpeedAvg2;
|
||||
}else {
|
||||
inSpeedMax2=(inSpeedMax2*999+inSpeedAvg2)/1000;
|
||||
}
|
||||
|
||||
|
||||
if(outPPSAvg2>=outPPSMax2) {
|
||||
outPPSMax2=outPPSAvg2;
|
||||
}else {
|
||||
outPPSMax2=(outPPSMax2*999+outPPSAvg2)/1000;
|
||||
}
|
||||
|
||||
if(inPPSAvg2>=inPPSMax2) {
|
||||
inPPSMax2=inPPSAvg2;
|
||||
}else {
|
||||
inPPSMax2=(inPPSMax2*999+inPPSAvg2)/1000;
|
||||
}
|
||||
|
||||
updatetime2=System.nanoTime();
|
||||
|
||||
}
|
||||
@@ -208,5 +295,77 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
tmt1.cancel();
|
||||
tmt2.cancel();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private volatile AtomicLong inCounter=new AtomicLong();
|
||||
private volatile AtomicLong outCounter=new AtomicLong();
|
||||
|
||||
private long inCounterOld;
|
||||
private long outCounterOld;
|
||||
private long inCounterOld1;
|
||||
private long outCounterOld1;
|
||||
private long inCounterOld2;
|
||||
private long outCounterOld2;
|
||||
|
||||
private volatile long inPPS;
|
||||
private volatile long outPPS;
|
||||
|
||||
|
||||
private volatile long inPPSMax;
|
||||
private volatile long outPPSMax;
|
||||
private volatile long inPPSMax2;
|
||||
private volatile long outPPSMax2;
|
||||
|
||||
private volatile long inPPSAvg;
|
||||
private volatile long outPPSAvg;
|
||||
private volatile long inPPSAvg2;
|
||||
private volatile long outPPSAvg2;
|
||||
|
||||
@Override
|
||||
public long getInPPS() {
|
||||
return inPPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getOutPPS() {
|
||||
return outPPS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicLong getInPacketCounterAL() {
|
||||
return inCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicLong getOutPacketCounterAL() {
|
||||
return outCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getInPacketCounter() {
|
||||
return inCounter.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getOutPacketCounter() {
|
||||
return outCounter.get();
|
||||
}
|
||||
|
||||
public double getOutPPSMax2() {
|
||||
return outPPSMax2;
|
||||
}
|
||||
|
||||
public double getInPPSMax2() {
|
||||
return inPPSMax2;
|
||||
}
|
||||
|
||||
public long getOutPPSAvg() {
|
||||
return outPPSAvg;
|
||||
}
|
||||
|
||||
public long getInPPSAvg() {
|
||||
return inPPSAvg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user