forked from KNEMC/KLALB
KLALB V3.4
This commit is contained in:
@@ -56,11 +56,16 @@ import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.PortPair;
|
||||
import org.kne.cloud.network.SpeedLimiter;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.VirtualSocketImpl;
|
||||
import org.kne.cloud.network.congress.CongressAlgorithm;
|
||||
import org.kne.cloud.network.congress.ECNCongressAlgorithm;
|
||||
import org.kne.cloud.network.congress.LARCCongressAlgorithm;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
import org.kne.concurrent.HighPerformanceExecutor;
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.concurrent.ThreadParker;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
@@ -69,10 +74,10 @@ import org.kne.io.Data;
|
||||
import com.google.gson.internal.Pair;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements BindableKLALBPacketConsumer{
|
||||
|
||||
private static final int HEADER_CALIBRATE = 40;
|
||||
private static final int HEADER_CALIBRATE = 80;
|
||||
/*
|
||||
private PrintStream dbg;
|
||||
{
|
||||
@@ -84,6 +89,9 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
|
||||
private SpeedAndTrafficAndDelayMonitorDataImpl socketMonitor=new SpeedAndTrafficAndDelayMonitorDataImpl();
|
||||
@@ -94,13 +102,13 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
|
||||
//60000 30 30
|
||||
private final int MTU=60000;
|
||||
private final long MIN_RTTVAR=100000000L;
|
||||
private final long MIN_LIMIT_SPEED=64*1024L;
|
||||
private final int MTU=8192;
|
||||
private final long MIN_RTTVAR=200000000L;
|
||||
private final long MIN_LIMIT_SPEED=128*1024L;
|
||||
private final long REACK_INTERVAL = 100000000L;
|
||||
|
||||
|
||||
private SpeedLimiter spdlmt=new SpeedLimiter(MIN_LIMIT_SPEED,2000000L);
|
||||
private SpeedLimiter spdlmt=new SpeedLimiter(MIN_LIMIT_SPEED,1000000L);
|
||||
|
||||
protected Inet6Address remoteaddr;
|
||||
protected Inet6Address localaddr;{
|
||||
@@ -156,24 +164,15 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
private int inputchachesize =128* 1024*1024;
|
||||
private int outputchachesize = 128* 1024*1024;
|
||||
|
||||
//long pad0,pad1,pad2,pad3,pad4,pad5,pad6,pad7;
|
||||
//4000 100 100
|
||||
//10000 500 500//500
|
||||
private volatile long congressWindowSize = MTU * 40;
|
||||
private volatile long sendWindowSize = MTU * 40;
|
||||
|
||||
private volatile long rcvSpeed=MIN_LIMIT_SPEED;
|
||||
private volatile long requestSpeed=MIN_LIMIT_SPEED;
|
||||
private volatile long congressWindowSize = MTU * 10;
|
||||
private volatile long sendWindowSize = MTU * 100;
|
||||
|
||||
private volatile long requestSpeedOld=MIN_LIMIT_SPEED;
|
||||
//private volatile long congressSpeed=0;
|
||||
private volatile double congressFactor=2;
|
||||
|
||||
//private double[] congressFactors=new double[] {0.95,0.95,0.95,1.2,0.8};
|
||||
//private int congressFactorsState=0;
|
||||
//private volatile double maxutilization=0.8;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -182,18 +181,12 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
private long outputcount = 0;
|
||||
|
||||
|
||||
private volatile long RTTMin=1000000000L;
|
||||
private volatile long RTTVar=1000000000L;
|
||||
private volatile long RTTAvg=1000000000L;
|
||||
private volatile long RTO=1000000000L;
|
||||
|
||||
private volatile long QueueingAvg=1000000000L;
|
||||
|
||||
//private volatile long RunningSpeed=spdlmt.getLimitspeed();
|
||||
|
||||
|
||||
|
||||
|
||||
private CongressAlgorithm algorithm=new ECNCongressAlgorithm();
|
||||
|
||||
|
||||
|
||||
@@ -238,21 +231,21 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
try {
|
||||
long x=System.nanoTime();
|
||||
long dt=x-dtp.resendtimer;
|
||||
long limit= (long) (Math.pow(2, dtp.getSendCounter()-1)*(RTO*2));
|
||||
long limit= (long) ((1<< (dtp.getSendCounter()-1))*(algorithm.getRTO()*2));
|
||||
if(dt>limit) {
|
||||
if(dtp.getSendCounter()>=10) {
|
||||
throw new IOException("send error!");
|
||||
}
|
||||
|
||||
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
dtp.setPriority(4);
|
||||
long length= dtp.getLength();
|
||||
socketRawMonitor.getOutTrafficAL().addAndGet(length);
|
||||
long length= dtp.getTotalLength();
|
||||
socketRawMonitor.getOutTrafficAL().add(length);
|
||||
spdlmt.forceTransmit(length);
|
||||
controller.sendPacketToAddress((Inet6Address) remoteaddr,0,dtp,1);
|
||||
//System.out.println("第"+(dtp.getSendCounter()-1)+"次重传:"+dtp+" "+dt+">"+limit);
|
||||
dtp.resendtimer=x;
|
||||
|
||||
});
|
||||
|
||||
/*if(congressWindowSize>65535) {
|
||||
congressWindowSize-=(dtp.getSize()+HEADER_CALIBRATE);
|
||||
@@ -283,19 +276,12 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(getLocalPort()!=0&&getPort()!=0)
|
||||
if(remoteaddr instanceof Inet6Address&&(!remoteaddr.isAnyLocalAddress()))
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress((Inet6Address) remoteaddr,0, new ACKTPacket(getLocalPort(),getPort(), -1,
|
||||
getAvaliableRcvWindow(),false,socketMonitor.getInSpeedMax(),0));
|
||||
} catch (IOException e) {
|
||||
try {
|
||||
close0(true);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -437,8 +423,25 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
//System.out.println(c);
|
||||
spdlmt.setLimitspeed(Math.max(MIN_LIMIT_SPEED,c));
|
||||
});
|
||||
updateBandwidthReq(requestSpeed);
|
||||
|
||||
//updateBandwidthReq(MIN_LIMIT_SPEED);
|
||||
algorithm.setSpeedControlConsumer((speed,burst)->{
|
||||
if(debug)
|
||||
System.out.println("speed:"+speed);
|
||||
if(portp!=null) {
|
||||
if(speed>requestSpeedOld*1.01||speed<requestSpeedOld*0.99) {
|
||||
updateBandwidthReq(speed);
|
||||
requestSpeedOld=speed;
|
||||
}
|
||||
}
|
||||
spdlmt.setBrustTime(burst);
|
||||
});
|
||||
algorithm.setWindowControlConsumer((window)->{
|
||||
if(debug)
|
||||
System.out.println("window:"+window);
|
||||
congressWindowSize=window;
|
||||
updateWindowSize();
|
||||
});
|
||||
algorithm.reset();
|
||||
this.portp=portpx;
|
||||
|
||||
}catch(SocketTimeoutException e) {
|
||||
@@ -450,7 +453,6 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}finally {
|
||||
connectionPending=false;
|
||||
}
|
||||
|
||||
controller.getResendTimer().schedule(flowControlTask, 5000, 5000);
|
||||
}
|
||||
private void updateBandwidthReq(long requestSpeed) {
|
||||
@@ -477,7 +479,7 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
if (!(host instanceof Inet6Address)) {
|
||||
throw new IllegalArgumentException("invalid address type, KLALB socket can only use IPV6 virtualaddress");
|
||||
}
|
||||
if ((!host.isAnyLocalAddress()) && (!host.equals(controller.getSelf()))) {
|
||||
if ((!host.isAnyLocalAddress()) && (!host.equals(controller.getSelf().getAddress()))) {
|
||||
throw new BindException("must bind to self");
|
||||
}
|
||||
localaddr = (Inet6Address) host;
|
||||
@@ -577,10 +579,10 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
}
|
||||
//System.out.println("PULL:"+dtp2);
|
||||
dataPack = dtp2;
|
||||
socketMonitor.getInTrafficAL().addAndGet(dtp2.getSize());
|
||||
socketMonitor.getInPacketCounterAL().incrementAndGet();
|
||||
controller.getDatatMonitor().getInTrafficAL().addAndGet(dtp2.getSize());
|
||||
controller.getDatatMonitor().getInPacketCounterAL().incrementAndGet();
|
||||
socketMonitor.getInTrafficAL().add(dtp2.getSize());
|
||||
socketMonitor.getInPacketCounterAL().add(1);
|
||||
controller.getDatatMonitor().getInTrafficAL().add(dtp2.getSize());
|
||||
controller.getDatatMonitor().getInPacketCounterAL().add(1);
|
||||
//checkFlowControl(dtp2);
|
||||
break;
|
||||
|
||||
@@ -987,58 +989,50 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
tt.cancel();
|
||||
tt=null;
|
||||
}
|
||||
//TimeDebugger td=new TimeDebugger();
|
||||
//td.putTime("start");
|
||||
dataPack.putTimePassport("packed");
|
||||
/*while (!avaliable) {
|
||||
sendthread.parkNanos(1000000L);
|
||||
}*/
|
||||
dataPack.putTimePassport("waitForAvaliable");
|
||||
//td.putTime("waitForAvaliable");
|
||||
while(true){
|
||||
if (isClosed())
|
||||
throw new SocketException("Socket is closed");
|
||||
//System.out.println(sendmap.size());
|
||||
boolean b=sendmapWindowUsed.get()<=sendWindowSize;
|
||||
//boolean b=sendmap.size()<=reallimit/MTU;
|
||||
if(b)
|
||||
break;
|
||||
sendthread.parkNanos(1000000L);
|
||||
}
|
||||
dataPack.putTimePassport("waitForWindow");
|
||||
//td.putTime("waitForCache");
|
||||
DATATPacket pack=dataPack;
|
||||
dataPack=null;
|
||||
pack.getDataBuffer().flip();
|
||||
//System.out.println(pack.getDataBuffer());
|
||||
//cacheCreateTime=System.nanoTime();
|
||||
//td.putTime("flipBuffer");
|
||||
|
||||
|
||||
spdlmt.transmit(pack.getDataBuffer().limit());
|
||||
socketMonitor.getOutTrafficAL().addAndGet(pack.getDataBuffer().limit());
|
||||
socketMonitor.getOutPacketCounterAL().incrementAndGet();
|
||||
controller.getDatatMonitor().getOutTrafficAL().addAndGet(pack.getDataBuffer().limit());
|
||||
controller.getDatatMonitor().getOutPacketCounterAL().incrementAndGet();
|
||||
//td.putTime("doStatistic");
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
DATATPacket prv= sendmap.put(pack.getNumber(),pack);
|
||||
long wu=sendmapWindowUsed.addAndGet((int) (pack.getTotalLength()+HEADER_CALIBRATE));
|
||||
if(prv!=null) {
|
||||
wu=sendmapWindowUsed.addAndGet((int) (-(prv.getTotalLength()+HEADER_CALIBRATE)));
|
||||
}
|
||||
algorithm.setCurrentWindowUsed(wu );
|
||||
if(debug)
|
||||
System.out.println("windowused:"+wu);
|
||||
|
||||
|
||||
socketMonitor.getOutTrafficAL().add(pack.getDataBuffer().limit());
|
||||
socketMonitor.getOutPacketCounterAL().add(1);
|
||||
controller.getDatatMonitor().getOutTrafficAL().add(pack.getDataBuffer().limit());
|
||||
controller.getDatatMonitor().getOutPacketCounterAL().add(1);
|
||||
|
||||
pack.setPriority(5);
|
||||
pack.resendtimer=System.nanoTime();
|
||||
socketRawMonitor.getOutTrafficAL().addAndGet(pack.getLength());
|
||||
socketRawMonitor.getOutTrafficAL().add(pack.getTotalLength());
|
||||
controller.sendPacketToAddress(remoteaddr,0,pack);
|
||||
//td.putTime("doSend");
|
||||
/* sendmaplock.readLock().lock();
|
||||
try{*/
|
||||
DATATPacket prv= sendmap.put(pack.getNumber(),pack);
|
||||
sendmapWindowUsed.addAndGet((int) (pack.getLength()+HEADER_CALIBRATE));
|
||||
if(prv!=null)
|
||||
sendmapWindowUsed.addAndGet((int) (-(prv.getLength()+HEADER_CALIBRATE)));
|
||||
//System.out.println("PUSH:"+pack);
|
||||
/*}finally {
|
||||
sendmaplock.readLock().unlock();
|
||||
}*/
|
||||
//td.putTime("addToList");
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//td.putTime("newPacket");
|
||||
//td.print();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1066,12 +1060,14 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
DATATPacket pack=new DATATPacket(localport, port, outputcount++,MTU);
|
||||
pack.setPriority(5);
|
||||
pack.getDataBuffer(). flip();
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress(remoteaddr,0,pack);
|
||||
});
|
||||
/*sendmaplock.readLock().lock();
|
||||
try{*/
|
||||
pack.resendtimer=System.nanoTime();
|
||||
sendmap.put(pack.getNumber(),pack);
|
||||
sendmapWindowUsed.addAndGet((int) (pack.getLength()+HEADER_CALIBRATE));
|
||||
sendmapWindowUsed.addAndGet((int) (pack.getTotalLength()+HEADER_CALIBRATE));
|
||||
/*}finally {
|
||||
sendmaplock.readLock().unlock();
|
||||
}*/
|
||||
@@ -1173,11 +1169,11 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
@Override
|
||||
protected void close() throws IOException {
|
||||
close0(true);
|
||||
|
||||
//new Exception().printStackTrace();
|
||||
}
|
||||
|
||||
private void close0(boolean b) throws IOException {
|
||||
|
||||
//new Exception().printStackTrace();
|
||||
if ( !isClosed()) {
|
||||
closed = true;
|
||||
|
||||
@@ -1185,12 +1181,11 @@ public class KLALBVirtualSocketImpl extends VirtualSocketImpl implements Bindabl
|
||||
sendCheckTask.cancel();
|
||||
flowControlTask.cancel();
|
||||
if(b)
|
||||
if(remoteaddr!=null)
|
||||
try {
|
||||
|
||||
if(remoteaddr!=null) {
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress(remoteaddr,0, new RSTPacket(super.localport, super.port),
|
||||
2);
|
||||
} catch (NoRouteToHostException e) {
|
||||
});
|
||||
}
|
||||
controller.getStreamPortBinder().disconnect(this);
|
||||
if(portp!=null) {
|
||||
@@ -1496,7 +1491,8 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Inet6Address from, KLALBPacket u) {
|
||||
public void accept(Inet6Address from,NetworkPacket np) {
|
||||
KLALBPacket u=(KLALBPacket) np;
|
||||
try {
|
||||
//System.out.println(this+" "+u);
|
||||
switch (u.getType()) {
|
||||
@@ -1544,14 +1540,14 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
}
|
||||
|
||||
private void acceptDATA(Inet6Address from, DATATPacket dtp) throws BindException, IOException {
|
||||
socketRawMonitor.getInTrafficAL().addAndGet(dtp.getLength());
|
||||
socketRawMonitor.getInTrafficAL().add(dtp.getTotalLength());
|
||||
if(isListening()) {
|
||||
if(dtp.getNumber()==0) {
|
||||
backlogQueuelock.lock();
|
||||
try{
|
||||
|
||||
//controller.getStreamPortBinder().checkIsConnected(new Pair);
|
||||
InetSocketAddress is=new InetSocketAddress(from, dtp.getSport());
|
||||
InetSocketAddress is=new InetSocketAddress(from, dtp.getSrcPort());
|
||||
AtomicBoolean ab=new AtomicBoolean(true);
|
||||
for (Iterator iterator = backlogQueue.iterator(); iterator.hasNext();) {
|
||||
Object[] objects = (Object[]) iterator.next();
|
||||
@@ -1561,7 +1557,7 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
}
|
||||
}
|
||||
if(ab.get()) {
|
||||
if(controller.getStreamPortBinder().checkIsConnect(this,new InetSocketAddress(from, dtp.getSport()))) {
|
||||
if(controller.getStreamPortBinder().checkIsConnect(this,new InetSocketAddress(from, dtp.getSrcPort()))) {
|
||||
ab.set(false);
|
||||
}
|
||||
}
|
||||
@@ -1572,8 +1568,10 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
/* controller.sendPacketToAddress(from.getRemoteVaddr(), new ACKTPacket(dtp.getDport(), dtp.getSport(),dtp.getNumber(),true,0),
|
||||
0,2);*/
|
||||
}else {
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(dtp.getDport(), dtp.getSport()),
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(dtp.getDstPort(), dtp.getSrcPort()),
|
||||
2);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1581,14 +1579,17 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
backlogQueuelock.unlock();
|
||||
}
|
||||
}else {
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(dtp.getDport(), dtp.getSport()),
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(dtp.getDstPort(), dtp.getSrcPort()),
|
||||
2);
|
||||
});
|
||||
}
|
||||
}else {
|
||||
//System.out.println(dtp.isCE());
|
||||
controller.sendPacketToAddress(from,0, new ACKTPacket(dtp.getDport(), dtp.getSport(), dtp.getNumber(),
|
||||
getAvaliableRcvWindow(),dtp.isCE(),socketMonitor.getInSpeedMax(),dtp.getSendcount()), 1);
|
||||
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress(from,0, new ACKTPacket(dtp.getDstPort(), dtp.getSrcPort(), dtp.getNumber(),
|
||||
getAvaliableRcvWindow(),dtp.isCE(),socketMonitor.getInSpeedAvg(),dtp.getSendcount()), 1);
|
||||
});
|
||||
boolean added=false;
|
||||
|
||||
long number=dtp.getNumber();
|
||||
@@ -1624,138 +1625,47 @@ public void associateSocketChannel(SocketChannel b) throws IOException{
|
||||
|
||||
private void acceptACK(Inet6Address from, ACKTPacket ackt) throws IOException {
|
||||
if(isListening()) {
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(ackt.getDport(), ackt.getSport()),
|
||||
HighPerformanceExecutor.defaultExecutor.execute(() -> {
|
||||
controller.sendPacketToAddress(from,0, new RSTPacket(ackt.getDstPort(), ackt.getSrcPort()),
|
||||
2);
|
||||
});
|
||||
}else {
|
||||
peerAvaliableRcvWindow = ackt.getAvaliableRcvWindow();
|
||||
updateWindowSize();
|
||||
long bwrcv=ackt.getRcvSpeed();
|
||||
if(debug)
|
||||
System.out.println("bwrcv:"+bwrcv);
|
||||
algorithm.setCurrentBandwidth(bwrcv);
|
||||
|
||||
rcvSpeed=ackt.getRcvSpeed();
|
||||
|
||||
/*if(rcvSpeed>=congressSpeed) {
|
||||
congressSpeed=rcvSpeed;
|
||||
}else {
|
||||
congressSpeed=(congressSpeed*99+rcvSpeed)/100;
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
requestSpeed=(long) (Math.max(MIN_LIMIT_SPEED, rcvSpeed)*congressFactor);
|
||||
|
||||
|
||||
if(portp!=null) {
|
||||
if(requestSpeed>requestSpeedOld*1.01||requestSpeed<requestSpeedOld*0.99) {
|
||||
updateBandwidthReq(requestSpeed);
|
||||
requestSpeedOld=requestSpeed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//System.out.println(spdlmt.getLimitspeed()/1024+"K "+ackt.getRcvSpeed()/1024+"K");
|
||||
DATATPacket kl=null;
|
||||
|
||||
|
||||
kl=sendmap.remove(ackt.getNumber());
|
||||
if(kl!=null) {
|
||||
sendmapWindowUsed.addAndGet((int) (-(kl.getLength()+HEADER_CALIBRATE)));
|
||||
long wu= sendmapWindowUsed.addAndGet((int) (-(kl.getTotalLength()+HEADER_CALIBRATE)));
|
||||
if(debug)
|
||||
System.out.println("windowused:"+wu);
|
||||
algorithm.setCurrentWindowUsed(wu);
|
||||
}
|
||||
|
||||
if(kl!=null) {
|
||||
/* if(ackt.isCongress()) {
|
||||
congressFactor=1.5;
|
||||
int cachesizeold,cachesizenew;
|
||||
do {
|
||||
cachesizeold=congresscachesize.get();
|
||||
cachesizenew=cachesizeold- kl.getSize()/2;
|
||||
if(cachesizenew<8192) {
|
||||
cachesizenew=8192;
|
||||
}
|
||||
|
||||
}while(congresscachesize.compareAndSet(cachesizeold, cachesizenew));
|
||||
//System.out.println(reallimit+" -8192");
|
||||
|
||||
}else {
|
||||
int cachesizeold,cachesizenew;
|
||||
do {
|
||||
cachesizeold=congresscachesize.get();
|
||||
cachesizenew=cachesizeold+kl.getSize()/16;
|
||||
long swu=sendmapWindowUsed.get()*2L;
|
||||
if(cachesizenew>swu) {
|
||||
cachesizenew=(int) swu;
|
||||
}
|
||||
|
||||
}while(congresscachesize.compareAndSet(cachesizeold, cachesizenew));
|
||||
|
||||
//System.out.println(reallimit+" +1024");
|
||||
|
||||
}*/
|
||||
if(ackt.isCongress()) {
|
||||
congressFactor=1.5;
|
||||
if(congressWindowSize>65535) {
|
||||
congressWindowSize-=(kl.getSize()+HEADER_CALIBRATE)/8;
|
||||
updateWindowSize();
|
||||
//System.out.println(reallimit+" -8192");
|
||||
}
|
||||
}else {
|
||||
if(sendmapWindowUsed.get()*2L>=congressWindowSize&&congressWindowSize<=outputchachesize) {
|
||||
congressWindowSize+=(kl.getSize()+HEADER_CALIBRATE)/32;
|
||||
updateWindowSize();
|
||||
//System.out.println(reallimit+" +1024");
|
||||
}
|
||||
}
|
||||
//controller.removeFromSend(from.getRemoteVaddr(),kl);
|
||||
|
||||
|
||||
if(kl.getSendCounter()==1) {
|
||||
long RTTC=ackt.getRcvtime()- kl.getSndtime();
|
||||
if(RTTC<=RTTMin) {
|
||||
RTTMin=RTTC;
|
||||
}else {
|
||||
RTTMin= (RTTMin*99999+RTTC)/100000;
|
||||
}
|
||||
|
||||
long queueing=RTTC-RTTMin;
|
||||
QueueingAvg=(QueueingAvg*99999+queueing)/100000;
|
||||
|
||||
if(firstUpdate.compareAndSet(true, false)) {
|
||||
RTTAvg=RTTC;
|
||||
RTTVar=RTTC/2;
|
||||
|
||||
}else {
|
||||
RTTVar=(RTTVar*3+Math.abs(RTTAvg-RTTC))/4;
|
||||
RTTAvg= (RTTAvg*7+RTTC)/8;
|
||||
}
|
||||
RTO=RTTAvg+Math.max(MIN_RTTVAR, RTTVar*4);//RTTVar*4
|
||||
|
||||
|
||||
|
||||
/*if(RTTC>RTO) {
|
||||
congressFactor=Math.min( 0.9,congressFactor);
|
||||
}else {
|
||||
if(congressFactor<1.1)
|
||||
congressFactor+=0.001;
|
||||
} */
|
||||
|
||||
|
||||
//System.out.println(congressFactor);
|
||||
//spdlmt.setLimitspeed(1024*1024);
|
||||
//reallimit=Math.max(MTU*2,(int) (congressSpeed*RTTMin*4/1000000000L));
|
||||
//System.out.println(reallimit/MTU);
|
||||
/*long nspd=(long) (congressSpeed*congressFactor);
|
||||
spdlmt.setLimitspeed(Math.max(nspd,MIN_LIMIT_SPEED));*/
|
||||
|
||||
|
||||
// System.out.println("RwqSpeed:"+(requestSpeed/1024)+"K MaxSpeed:"+(congressSpeed/1024)+"K LimitSpeed:"+(spdlmt.getLimitspeed()/1024)+"K");
|
||||
//System.out.println("RTTMin:"+RTTMin/1000000L+"ms RTTAvg:"+RTTAvg/1000000L+"ms");
|
||||
|
||||
|
||||
algorithm.putAck(kl.getTotalLength(), RTTC,ackt.isCongress());
|
||||
}
|
||||
//kl.dispose();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
//ackt.dispose();
|
||||
}
|
||||
|
||||
private void updateWindowSize() {
|
||||
|
||||
Reference in New Issue
Block a user