perf[buffer]: 自定义私有协议格式,可以针对性的对存在性能瓶颈的数据结构做特定优化

This commit is contained in:
godotg
2022-10-21 08:55:36 +08:00
parent 5b9174c494
commit 2962f56cd8
4 changed files with 139 additions and 3 deletions
@@ -13,6 +13,9 @@
package com.zfoo.protocol.buffer;
import com.zfoo.protocol.ProtocolManager;
import com.zfoo.protocol.buffer.model.BigDataPacket;
import com.zfoo.protocol.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
@@ -21,6 +24,9 @@ import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.util.Arrays;
import java.util.Set;
/**
* @author godotg
* @version 3.0
@@ -162,4 +168,24 @@ public class ByteBufUtilsTest {
}
}
@Ignore
@Test
public void bigDataTest() {
ProtocolManager.initProtocol(Set.of(BigDataPacket.class));
var bigDataPact = new BigDataPacket();
Arrays.fill(bigDataPact.a, 99);
var buffer = new UnpooledHeapByteBuf(ByteBufAllocator.DEFAULT, 100, 100_0000);
long startTime = System.currentTimeMillis();
for (int i = 0; i < 10_0000; i++) {
buffer.clear();
ProtocolManager.write(buffer, bigDataPact);
var newPacket = ProtocolManager.read(buffer);
}
System.out.println(StringUtils.format("[zfoo][size:{}] [time:{}]", buffer.writerIndex(), System.currentTimeMillis() - startTime));
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2020 The zfoo Authors
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package com.zfoo.protocol.buffer.model;
import com.zfoo.protocol.IPacket;
import com.zfoo.protocol.registration.anno.Protocol;
/**
* @author godotg
* @version 3.0
*/
@Protocol(id = 1000)
public class BigDataPacket implements IPacket {
public int[] a = new int[10_0000];
}