修复Kperf测速工具仪表盘显示bug,优化Kperf缓存命中率
This commit is contained in:
@@ -1417,29 +1417,29 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
private void updateDashboardData(KLALBController kc) {
|
||||
// 更新上行速度
|
||||
double outload = kc.getLinkMonitor().getOutSpeed() * 100.0 / kc.getLinkMonitor().getOutSpeedMax();
|
||||
if (Double.isFinite(outload)) {
|
||||
upSpeedText.setLabel(KLALBUtils.convertIBUint(kc.getLinkMonitor().getOutSpeed()) + "/s");
|
||||
if (Double.isFinite(outload)) {
|
||||
upSpeed.setValue(Math.min(upSpeed.getValue().doubleValue() * 0.98 + outload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
// 更新下行速度
|
||||
double inload = kc.getLinkMonitor().getInSpeed() * 100.0 / kc.getLinkMonitor().getInSpeedMax();
|
||||
if (Double.isFinite(inload)) {
|
||||
downSpeedText.setLabel(KLALBUtils.convertIBUint(kc.getLinkMonitor().getInSpeed()) + "/s");
|
||||
if (Double.isFinite(inload)) {
|
||||
downSpeed.setValue(Math.min(downSpeed.getValue().doubleValue() * 0.98 + inload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
// 更新上行包速率
|
||||
double outPPSload = kc.getLinkMonitor().getOutPPS() * 100.0 / kc.getLinkMonitor().getOutPPSMax();
|
||||
if (Double.isFinite(outPPSload)) {
|
||||
upPPSText.setLabel(KLALBUtils.convertUintDefalut(kc.getLinkMonitor().getOutPPS()) + "PPS");
|
||||
if (Double.isFinite(outPPSload)) {
|
||||
upPPS.setValue(Math.min(upPPS.getValue().doubleValue() * 0.98 + outPPSload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
// 更新下行包速率
|
||||
double inPPSload = kc.getLinkMonitor().getInPPS() * 100.0 / kc.getLinkMonitor().getInPPSMax();
|
||||
if (Double.isFinite(inPPSload)) {
|
||||
downPPSText.setLabel(KLALBUtils.convertUintDefalut(kc.getLinkMonitor().getInPPS()) + "PPS");
|
||||
if (Double.isFinite(inPPSload)) {
|
||||
downPPS.setValue(Math.min(downPPS.getValue().doubleValue() * 0.98 + inPPSload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
@@ -1471,29 +1471,29 @@ public class KLALBStateGUI3 extends XFrame {
|
||||
if(router!=null) {
|
||||
// 更新背板延迟
|
||||
double backplaneTimev = router.getBackplaneTime()* 100.0/100000.0;
|
||||
if (Double.isFinite(backplaneTimev)) {
|
||||
backplaneDelayText.setLabel(KLALBUtils.convertUintNanoDefalut(router.getBackplaneTime()) + "s");
|
||||
if (Double.isFinite(backplaneTimev)) {
|
||||
backplaneDelay.setValue(Math.min(backplaneDelay.getValue().doubleValue() * 0.98 + backplaneTimev * 0.02, 101.0));
|
||||
}
|
||||
|
||||
// 更新背板转发率
|
||||
double backplanePPSv = router.getBackplanePPS() * 100.0 / router.getBackplanePPSMax();
|
||||
if (Double.isFinite(backplanePPSv)) {
|
||||
backplanePPSText.setLabel(KLALBUtils.convertUintDefalut(router.getBackplanePPS()) + "PPS");
|
||||
if (Double.isFinite(backplanePPSv)) {
|
||||
backplanePPS.setValue(Math.min(backplanePPS.getValue().doubleValue() * 0.98 + backplanePPSv * 0.02, 101.0));
|
||||
}
|
||||
|
||||
// 更新背板ECN率
|
||||
double backplaneECNv = router.getECNRate() * 100.0 ;
|
||||
if (Double.isFinite(backplaneECNv)) {
|
||||
backplaneECNRateText.setLabel(String.format("%.1f",backplaneECNv) + "%");
|
||||
if (Double.isFinite(backplaneECNv)) {
|
||||
backplaneECNRate.setValue(Math.min(backplaneECNRate.getValue().doubleValue() * 0.98 + backplaneECNv * 0.02, 101.0));
|
||||
}
|
||||
|
||||
// 更新背板ECN率
|
||||
double backplaneLossv = router.getLossRate() * 100.0 ;
|
||||
if (Double.isFinite(backplaneLossv)) {
|
||||
backplaneLossRateText.setLabel(String.format("%.1f",backplaneLossv) + "%");
|
||||
if (Double.isFinite(backplaneLossv)) {
|
||||
backplaneLossRate.setValue(Math.min(backplaneLossRate.getValue().doubleValue() * 0.98 + backplaneLossv * 0.02, 101.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ public class KperfGUI extends XFrame{
|
||||
private Kperf kperf;
|
||||
private JTextField targetAddressField;
|
||||
private JButton startButton;
|
||||
private JProgressBar progressBar;
|
||||
private DefaultValueDataset upSpeed;
|
||||
private DefaultValueDataset upDataSpeed;
|
||||
private DialTextAnnotation upSpeedText;
|
||||
@@ -54,7 +53,7 @@ public class KperfGUI extends XFrame{
|
||||
private DialTextAnnotation downSpeedText;
|
||||
private JTextField sourceAddressField;
|
||||
|
||||
private SpeedAndTrafficAndDelayMonitorDataImpl monitor;
|
||||
private volatile SpeedAndTrafficAndDelayMonitorDataImpl monitor;
|
||||
|
||||
private DefaultValueDataset upPPS;
|
||||
|
||||
@@ -70,10 +69,6 @@ public class KperfGUI extends XFrame{
|
||||
|
||||
private TimerTask tsk;
|
||||
private class KperfReportsImpl implements KperfReports{
|
||||
@Override
|
||||
public void testProcess(double process) {
|
||||
progressBar.setValue((int) (process*100.0f));
|
||||
}
|
||||
@Override
|
||||
public void testFinish() {
|
||||
if(kperf!=null) {
|
||||
@@ -521,9 +516,6 @@ public class KperfGUI extends XFrame{
|
||||
|
||||
|
||||
|
||||
progressBar = new JProgressBar();
|
||||
progressBar.setPreferredSize(new Dimension(100, 5));
|
||||
getContentPane().add(progressBar, BorderLayout.NORTH);
|
||||
getTitlelabel().setFont(UIEnv.getFont().deriveFont(17.0f));
|
||||
getTitlepanel().setBorder(new LineBorder(Color.LIGHT_GRAY));
|
||||
getTitlelabel().setForeground(Color.WHITE);
|
||||
@@ -538,26 +530,26 @@ public class KperfGUI extends XFrame{
|
||||
public void run() {
|
||||
if(monitor!=null) {
|
||||
double outload = monitor.getOutSpeed() * 100.0 / monitor.getOutSpeedMax();
|
||||
if (Double.isFinite(outload)) {
|
||||
upSpeedText.setLabel(KLALBUtils.convertIBUint(monitor.getOutSpeed()) + "/s");
|
||||
if (Double.isFinite(outload)) {
|
||||
upSpeed.setValue(Math.min(upSpeed.getValue().doubleValue() * 0.98 + outload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
double inload = monitor.getInSpeed() * 100.0 / monitor.getInSpeedMax();
|
||||
if (Double.isFinite(inload)) {
|
||||
downSpeedText.setLabel(KLALBUtils.convertIBUint(monitor.getInSpeed()) + "/s");
|
||||
if (Double.isFinite(inload)) {
|
||||
downSpeed.setValue(Math.min(downSpeed.getValue().doubleValue() * 0.98 + inload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
double outPPSload = monitor.getOutPPS() * 100.0 / monitor.getOutPPSMax();
|
||||
if (Double.isFinite(outPPSload)) {
|
||||
upPPSText.setLabel(KLALBUtils.convertUintDefalut(monitor.getOutPPS()) + "PPS");
|
||||
if (Double.isFinite(outPPSload)) {
|
||||
upPPS.setValue(Math.min(upPPS.getValue().doubleValue() * 0.98 + outPPSload * 0.02, 101.0));
|
||||
}
|
||||
|
||||
double inPPSload = monitor.getInPPS() * 100.0 / monitor.getInPPSMax();
|
||||
if (Double.isFinite(inPPSload)) {
|
||||
downPPSText.setLabel(KLALBUtils.convertUintDefalut(monitor.getInPPS()) + "PPS");
|
||||
if (Double.isFinite(inPPSload)) {
|
||||
downPPS.setValue(Math.min(downPPS.getValue().doubleValue() * 0.98 + inPPSload * 0.02, 101.0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class SpeedAndTrafficMonitorDataImpl extends MonitorDataImpl implements S
|
||||
inPPSEvaluator.markDirty();
|
||||
}
|
||||
long time=System.nanoTime();
|
||||
if(time-stime>timewindowmax) {
|
||||
if(time-stime>timewindow) {
|
||||
stime=time;
|
||||
long os=uploadBandwidth.calculateBandwidth(timewindowmax);
|
||||
long is=downloadBandwidth.calculateBandwidth(timewindowmax);
|
||||
|
||||
@@ -77,11 +77,9 @@ public class Kperf implements Runnable{
|
||||
|
||||
|
||||
|
||||
KLALBPacket testPacket=null;
|
||||
private KLALBPacket testPacket=null;
|
||||
|
||||
private long starttime=System.nanoTime();
|
||||
long totaltime=1000;
|
||||
long usedtime=0;
|
||||
|
||||
|
||||
private ScheduledFuture<?> monitorUpdater;
|
||||
@@ -121,9 +119,9 @@ public class Kperf implements Runnable{
|
||||
});
|
||||
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("测速开始!");
|
||||
if(reports!=null)
|
||||
reports.updateDial(monitor);
|
||||
try {
|
||||
long startTime;
|
||||
|
||||
@@ -132,7 +130,6 @@ public class Kperf implements Runnable{
|
||||
startTime=System.nanoTime();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Thread.sleep(1000);
|
||||
updateUsedTime();
|
||||
}
|
||||
System.out.printf("上传延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms\n",monitor.getOutDelay()/1000000.0,monitor.getOutDelay()/1000000.0,monitor.getOutJitter()/1000000.0);
|
||||
System.out.printf("下载延迟 最小:%.3fms 平均:%.3fms 抖动:%.3fms\n",monitor.getInDelay()/1000000.0,monitor.getInDelay()/1000000.0,monitor.getInJitter()/1000000.0);
|
||||
@@ -298,9 +295,6 @@ public class Kperf implements Runnable{
|
||||
|
||||
|
||||
tlock.unpark();
|
||||
updateUsedTime() ;
|
||||
if(reports!=null)
|
||||
reports.updateDial(monitor);
|
||||
break;
|
||||
case KLALBPacket.TESTN:
|
||||
break;
|
||||
@@ -325,12 +319,7 @@ public class Kperf implements Runnable{
|
||||
tcc.interrupt();
|
||||
}
|
||||
}
|
||||
private void updateUsedTime() {
|
||||
usedtime=System.nanoTime()-starttime;
|
||||
//System.out.println(usedtime+" "+totaltime);
|
||||
if(reports!=null)
|
||||
reports.testProcess(usedtime/(double)totaltime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.kne.cloud.network.perf;
|
||||
import org.kne.cloud.network.monitor.SpeedAndTrafficAndDelayMonitorDataImpl;
|
||||
|
||||
public interface KperfReports {
|
||||
public void testProcess(double d);
|
||||
public void testFinish();
|
||||
public void updateDial(SpeedAndTrafficAndDelayMonitorDataImpl mdt);
|
||||
public void uploadSpeedFinish(long uploadSpeed);
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
package org.kne.cloud.network.perf;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import org.kne.cloud.network.ByteBufferAllocator;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.klalb.KLALBPacket;
|
||||
|
||||
@@ -18,56 +13,75 @@ public class TESTNPacket extends KLALBPacket {
|
||||
|
||||
private static final int HEADER_LENGTH = 3;
|
||||
|
||||
private ByteBuffer dataBuffer;//=NetworkPacket.databufferpool_65535.borrow();
|
||||
// 核心:一个线程私有的 65535 字节大缓存,生命周期与线程同寿
|
||||
private static final ThreadLocal<ByteBuffer> BENCH_BUFFER =
|
||||
ThreadLocal.withInitial(() -> ByteBuffer.allocate(65535));
|
||||
|
||||
// 不再持有 ByteBuffer,只记录长度
|
||||
private int payloadLength;
|
||||
|
||||
@Override
|
||||
public long getTotalLength() {
|
||||
return HEADER_LENGTH+dataBuffer.limit();
|
||||
return HEADER_LENGTH + payloadLength;
|
||||
}
|
||||
|
||||
|
||||
// 发送端构造
|
||||
public TESTNPacket(int limit) {
|
||||
super(TESTN, HEADER_LENGTH);
|
||||
//dataBuffer.limit(limit);
|
||||
dataBuffer=NetworkPacket.bufferAllocator.allocate(limit);
|
||||
this.payloadLength = limit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ByteBuffer getDataBuffer() {
|
||||
return dataBuffer;
|
||||
// 接收端构造(从已有的 ByteBuffer 解析)
|
||||
public TESTNPacket(ByteBuffer bb) {
|
||||
super(bb, HEADER_LENGTH);
|
||||
this.payloadLength = klalbHeader.getChar(1);
|
||||
}
|
||||
|
||||
public int getPayloadLength() {
|
||||
return payloadLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToChannel(WritableByteChannel dto) throws IOException {
|
||||
klalbHeader.putChar(1, (char) dataBuffer.limit());
|
||||
// 1. 写入包头(包含 payloadLength)
|
||||
klalbHeader.putChar(1, (char) payloadLength);
|
||||
super.writeToChannel(dto);
|
||||
//System.out.println(dataBuffer);
|
||||
dto.write(dataBuffer.slice(0, dataBuffer.limit()));
|
||||
|
||||
// 2. 如果有 payload,借用 ThreadLocal 缓冲区并写出去
|
||||
if (payloadLength > 0) {
|
||||
ByteBuffer buf = BENCH_BUFFER.get();
|
||||
buf.clear();
|
||||
buf.limit(payloadLength); // 限制到指定长度
|
||||
|
||||
// 直接写出,里面的数据是上一次残留的或者全 0,对于烤机无所谓
|
||||
dto.write(buf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromChannel(ReadableByteChannel din) throws IOException {
|
||||
// 1. 读包头
|
||||
super.readFromChannel(din);
|
||||
int limit=klalbHeader.getChar(1);
|
||||
dataBuffer=NetworkPacket.bufferAllocator.allocate(limit);
|
||||
while(dataBuffer.hasRemaining()){
|
||||
if(din.read(dataBuffer)==-1) {
|
||||
throw new EOFException();
|
||||
}
|
||||
}
|
||||
dataBuffer.flip();
|
||||
}
|
||||
this.payloadLength = klalbHeader.getChar(1);
|
||||
|
||||
public TESTNPacket(ByteBuffer bb) {
|
||||
super(bb,HEADER_LENGTH);
|
||||
}
|
||||
// 2. 如果有 payload,借用缓冲区接收数据
|
||||
if (payloadLength > 0) {
|
||||
ByteBuffer buf = BENCH_BUFFER.get();
|
||||
buf.clear();
|
||||
buf.limit(payloadLength);
|
||||
|
||||
// 循环读满(使用你现有的 KNEChannels 工具或手动循环)
|
||||
while (buf.hasRemaining()) {
|
||||
if (din.read(buf) == -1) {
|
||||
throw new EOFException("连接提前断开,未能读满 TESTN 载荷");
|
||||
}
|
||||
}
|
||||
// 数据读完直接丢弃,缓冲区不保存,下一次 clear() 时会自动覆盖
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TESTN["+dataBuffer.limit()+"]";
|
||||
return "TESTN[" + payloadLength + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user