forked from KNEMC/KLALB
优化TUN性能
This commit is contained in:
@@ -9,9 +9,6 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.debug.TimeDebugger;
|
||||
|
||||
|
||||
public class ByteBufferPool {
|
||||
private AtomicReferenceArray< ByteBuffer> rec;
|
||||
|
||||
@@ -258,7 +258,7 @@ public class FilterSocket extends Socket {
|
||||
// TODO 自动生成的方法存根
|
||||
return socket.isOutputShutdown();
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
@Override
|
||||
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
|
||||
// TODO 自动生成的方法存根
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.concurrent.locks.LockSupport;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.concurrent.YieldLock;
|
||||
import org.kne.opencl64.Releaser;
|
||||
|
||||
/**
|
||||
@@ -105,7 +105,7 @@ class ArrayListMessageBatcherReleaser<T> extends Releaser<ArrayListMessageBatche
|
||||
}
|
||||
class ArrayListMessageBatcher0<T> implements Runnable,MessageBatcher<T>{
|
||||
private ArrayList<T> messageList;
|
||||
private Lock lock=new SpinLock();
|
||||
private Lock lock=new YieldLock();
|
||||
private final int batchSize;
|
||||
private final long maxDelay;
|
||||
private Consumer<List<T>> consumer;
|
||||
|
||||
@@ -2,8 +2,7 @@ package org.kne.cloud.network.congestion;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.kne.cloud.network.monitor.DelaySampler;
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.concurrent.YieldLock;
|
||||
|
||||
public class Vegas2CongestionAlgorithm implements CongestionAlgorithm,DetnetCongestionAlgorithm {
|
||||
|
||||
@@ -32,7 +31,7 @@ public class Vegas2CongestionAlgorithm implements CongestionAlgorithm,DetnetCong
|
||||
private volatile long window2 = MIN_WINDOW;
|
||||
private volatile long maxwindow = 99999999999L;
|
||||
|
||||
private final SpinLock slock=new SpinLock();
|
||||
private final YieldLock slock=new YieldLock();
|
||||
|
||||
public Vegas2CongestionAlgorithm() {
|
||||
reset();
|
||||
|
||||
@@ -613,13 +613,16 @@ public class IPv6Packet extends NetworkPacket {
|
||||
*/
|
||||
@Override
|
||||
public void readFromChannel(ReadableByteChannel din, long length) throws IOException {
|
||||
IPv6header.limit(IPv6_HEADER_LENGTH);
|
||||
IPv6header.position(0);
|
||||
while (IPv6header.hasRemaining()) {
|
||||
if (din.read(IPv6header) == -1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
IPv6header.limit(1);
|
||||
KNEChannels.readFully(din,IPv6header);
|
||||
int ver=getVersion();
|
||||
if(ver!=6){
|
||||
throw new StreamCorruptedException("Unsupported IPv"+ver);
|
||||
}
|
||||
|
||||
IPv6header.limit(IPv6_HEADER_LENGTH);
|
||||
KNEChannels.readFully(din,IPv6header);
|
||||
int payloadlength = getPayloadLength();
|
||||
int nextheader = getNextHeader();
|
||||
loop: while (true) {
|
||||
|
||||
@@ -2,8 +2,11 @@ package org.kne.cloud.network.ipv6;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -25,20 +28,21 @@ import org.kne.cloud.network.srv6.SRv6Router;
|
||||
import org.kne.cloud.network.tun.InetAddressRow;
|
||||
import org.kne.cloud.network.tun.TUNChannel;
|
||||
import org.kne.cloud.network.tun.TUNNetworkDevice;
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.concurrent.ThreadParker;
|
||||
import org.kne.concurrent.YieldLock;
|
||||
import org.kne.io.KNEChannels;
|
||||
|
||||
public class IPv6TUNLoopbackNetworkLink extends AbstractIPv6NetworkLink
|
||||
implements IPv6NetworkLink, Closeable, AutoCloseable {
|
||||
|
||||
|
||||
private TUNChannel channel;
|
||||
private TUNNetworkDevice tun;
|
||||
|
||||
private IPv6AddressGroup hostAddress;
|
||||
|
||||
private Thread tr;
|
||||
|
||||
private Lock slok = new SpinLock();
|
||||
private Lock slok = new YieldLock();
|
||||
|
||||
public IPv6TUNLoopbackNetworkLink(String name,IPv6AddressGroup hostAddress, int mtu, List<InetAddress> dns) throws IOException {
|
||||
super(true);
|
||||
@@ -60,27 +64,20 @@ public class IPv6TUNLoopbackNetworkLink extends AbstractIPv6NetworkLink
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
TUNChannel channel= tun.openSession();
|
||||
|
||||
channel = tun.openSession();
|
||||
Thread tb = new Thread(() -> {
|
||||
while (true) {
|
||||
ByteBuffer tmp = NetworkPacket.bufferAllocator.allocateNative(65535);
|
||||
try {
|
||||
channel.read(tmp);
|
||||
tmp.flip();
|
||||
// System.out.println(tmp);
|
||||
if (IPv6Packet.getIPVersion(tmp.get(0)) == 6) {
|
||||
|
||||
ReadableByteChannel tmp = channel.readPacket();
|
||||
try {
|
||||
IPv6Packet ipp = new IPv6Packet();
|
||||
ipp.readFromChannel(KNEChannels.newReadableChannel(tmp), mtu);
|
||||
ipp.readFromChannel(tmp, mtu);
|
||||
|
||||
// NetworkPacket.databufferpool_65535.back(tmp);
|
||||
BiConsumer<IPv6NetworkLink, Supplier<IPv6Packet>> con = super.getReceiveConsumer();
|
||||
if (con != null) {
|
||||
if (ipp.getPayload().getProtocolNumber() == 6) {
|
||||
SRv6Router router = getSrv6Router();
|
||||
|
||||
if (router != null) {
|
||||
router.insertHopByHopHeader(ipp);
|
||||
}
|
||||
@@ -91,51 +88,22 @@ public class IPv6TUNLoopbackNetworkLink extends AbstractIPv6NetworkLink
|
||||
if (pid != null) {
|
||||
monitor.getUploadBandwidth().recordPacket(pid,1, (int) ipp.getTotalLength());
|
||||
}
|
||||
// ipp.setDisposeAfterSend(true);
|
||||
// ipp.getPayload().setDisposeAfterSend(true);
|
||||
return ipp;
|
||||
});
|
||||
} else {
|
||||
// ipp.dispose();
|
||||
}
|
||||
}catch(StreamCorruptedException e){
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
tmp.close();
|
||||
}
|
||||
|
||||
} else {
|
||||
// NetworkPacket.databufferpool_65535.back(tmp);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// NetworkPacket.databufferpool_65535.back(tmp);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
tb.setPriority(Thread.MAX_PRIORITY - 1);
|
||||
tb.start();
|
||||
tr = new Thread(() -> {
|
||||
while (true) {
|
||||
ByteBuffer tmp = sendQueue.poll();
|
||||
if (tmp != null) {
|
||||
|
||||
slok.lock();
|
||||
try {
|
||||
channel.write(tmp);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
slok.unlock();
|
||||
// NetworkPacket.databufferpool_65535.back(tmp);
|
||||
}
|
||||
} else {
|
||||
|
||||
LockSupport.parkNanos(1000000L);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
tr.setPriority(Thread.MAX_PRIORITY - 1);
|
||||
tr.start();
|
||||
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
throw new IOException(e);
|
||||
@@ -143,8 +111,6 @@ public class IPv6TUNLoopbackNetworkLink extends AbstractIPv6NetworkLink
|
||||
onOnlineStateUpdate();
|
||||
}
|
||||
|
||||
private LinkedBlockingQueue<ByteBuffer> sendQueue = new LinkedBlockingQueue<ByteBuffer>();
|
||||
|
||||
private SpeedAndTrafficMonitorDataImpl monitor;
|
||||
|
||||
@Override
|
||||
@@ -192,17 +158,20 @@ public class IPv6TUNLoopbackNetworkLink extends AbstractIPv6NetworkLink
|
||||
}
|
||||
|
||||
private void sendPacket0(IPv6Packet pack, KLALBOAMHopByHopTLV oamtlv, DetNetSRv6TLV detNet) throws IOException {
|
||||
|
||||
|
||||
ByteBuffer tmp = NetworkPacket.bufferAllocator.allocate(65535);
|
||||
pack.writeToChannel(KNEChannels.newWritableChannel(tmp));
|
||||
WritableByteChannel wp = null;
|
||||
slok.lock();
|
||||
try {
|
||||
wp= channel.writePacket();
|
||||
pack.writeToChannel(wp);
|
||||
UUID pid = pack.getPacketID();
|
||||
if (pid != null) {
|
||||
monitor.getUploadBandwidth().recordPacket(pid, 1,(int) pack.getTotalLength());
|
||||
monitor.getUploadBandwidth().recordPacket(pid, 1, (int) pack.getTotalLength());
|
||||
}
|
||||
tmp.flip();
|
||||
sendQueue.add(tmp);
|
||||
LockSupport.unpark(tr);
|
||||
}finally {
|
||||
if(wp!=null)
|
||||
wp.close();
|
||||
slok.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,8 +41,8 @@ import org.kne.cloud.network.monitor.LinkStatus;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
import org.kne.cloud.network.perf.TESTNPacket;
|
||||
import org.kne.cloud.network.te.BandwidthDistributer;
|
||||
import org.kne.concurrent.SpinLock;
|
||||
import org.kne.concurrent.ThreadParker;
|
||||
import org.kne.concurrent.YieldLock;
|
||||
import org.kne.math.Long128;
|
||||
|
||||
public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implements ControlledIPv6NetworkLink {
|
||||
@@ -192,7 +192,7 @@ public class KLALBRemoteLink extends AbstractControlledIPv6NetworkLink implement
|
||||
private volatile long time = System.nanoTime();
|
||||
private volatile long pingInterval = 100000000L;
|
||||
|
||||
private Lock sendLock=new SpinLock();
|
||||
private Lock sendLock=new YieldLock();
|
||||
|
||||
private boolean checkPingTime() {
|
||||
long cu = System.nanoTime();
|
||||
|
||||
@@ -569,13 +569,13 @@ public class GraphPanel extends JPanel {
|
||||
double x_4 = ex - arrXY_2[0]; // (x4,y4)是第二端点
|
||||
double y_4 = ey - arrXY_2[1];
|
||||
|
||||
Double X3 = new Double(x_3);
|
||||
Double X3 = Double.valueOf(x_3);
|
||||
x3 = X3.intValue();
|
||||
Double Y3 = new Double(y_3);
|
||||
Double Y3 = Double.valueOf(y_3);
|
||||
y3 = Y3.intValue();
|
||||
Double X4 = new Double(x_4);
|
||||
Double X4 = Double.valueOf(x_4);
|
||||
x4 = X4.intValue();
|
||||
Double Y4 = new Double(y_4);
|
||||
Double Y4 =Double.valueOf(y_4);
|
||||
y4 = Y4.intValue();
|
||||
// 画线
|
||||
g2.drawLine(sx, sy, ex, ey);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class KLTPOutputStream extends OutputStream implements KLTPPacketConsumer
|
||||
|
||||
|
||||
|
||||
private Lock olock=new SpinLock();
|
||||
private Lock olock=new YieldLock();
|
||||
|
||||
private volatile boolean autoFlush=true;
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user