use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class TestLoadClient method buildRequest.
private static ByteBuf buildRequest(String request, int pipes) {
byte[] bytes = request.getBytes();
ByteBuf buf = ByteBuf.direct(bytes.length * pipes);
for (int i = 0; i < pipes; i++) {
buf.writeBytes(bytes);
}
return buf;
}
use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class TestLoadServer method main.
public static void main(String[] args) throws Exception {
Options.setBufAutoExpansion(AUTO_EXPANSION);
Options.setEnableEpoll(ENABLE_EPOLL);
Options.setEnableUnsafeBuf(ENABLE_UNSAFE_BUF);
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
String text = f.getStringContent();
if (BUFFERED_WRITE) {
ByteBuf buf = ch.getAttribute(WRITE_BUF);
if (buf == null) {
buf = ch.allocate();
ByteBuf temp = buf;
ch.setAttribute(WRITE_BUF, buf);
ch.getEventLoop().submit(() -> {
ch.writeAndFlush(temp);
ch.setAttribute(WRITE_BUF, null);
});
}
byte[] data = text.getBytes(ch.getCharset());
buf.writeInt(data.length);
buf.writeBytes(data);
} else {
f.setString(text, ch);
ch.writeAndFlush(f);
}
}
};
NioEventLoopGroup group = new NioEventLoopGroup(SERVER_CORE_SIZE);
group.setMemoryCapacity(1024 * 512 * MEM_UNIT * SERVER_CORE_SIZE);
group.setWriteBuffers(WRITE_BUFFERS);
group.setMemoryUnit(MEM_UNIT);
group.setEnableMemoryPool(ENABLE_POOL);
ChannelAcceptor context = new ChannelAcceptor(group, 8300);
context.addProtocolCodec(new LengthValueCodec());
context.setIoEventHandle(eventHandle);
if (ENABLE_SSL) {
// context.setSslPem("localhost.key;localhost.crt");
}
context.addChannelEventListener(new LoggerChannelOpenListener());
if (ENABLE_WORK_EVENT_LOOP) {
context.setExecutorGroup(new ThreadEventLoopGroup("ep", 1024 * 256 * CLIENT_CORE_SIZE));
}
context.bind();
}
use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class TestBytebufPut method testPut4.
@Test
public void testPut4() {
ByteBuf src = ByteBuf.heap(1024);
src.writeBytes("hello;hello;".getBytes());
ByteBuf dst = ByteBuf.heap(1024);
dst.writeBytes(src);
v(dst);
}
use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class TestBytebufPut method testput2.
@Test
public void testput2() {
ByteBuf src = ByteBuf.heap(1024);
src.writeBytes(data.getBytes());
ByteBuf dst = ByteBuf.direct(1024);
dst.writeBytes(src);
v(dst);
}
use of com.firenio.buffer.ByteBuf in project baseio by generallycloud.
the class TestExpansion method arrayPool.
@Test
public void arrayPool() throws Exception {
ByteBufAllocator alloc = TestAllocUtil.heap(1024 * 4);
ByteBuf buf = alloc.allocate(2);
for (int i = 0; i < 10; i++) {
buf.writeBytes(data);
buf.writeByte(a);
alloc.allocate(1);
}
Assert.assertTrue(v(buf));
}
Aggregations