Search in sources :

Example 1 with PooledByteBufAllocatorManager

use of com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager in project baseio by generallycloud.

the class TestBytebufAllocator method test.

static void test() throws Exception {
    ServerConfiguration configuration = new ServerConfiguration();
    configuration.setSERVER_MEMORY_POOL_CAPACITY(10);
    configuration.setSERVER_MEMORY_POOL_UNIT(1);
    SocketChannelContext context = new NioSocketChannelContext(configuration);
    PooledByteBufAllocatorManager allocator = new PooledByteBufAllocatorManager(context);
    allocator.start();
    ByteBufAllocator allocator2 = allocator.getNextBufAllocator();
    ByteBuf buf = allocator2.allocate(15);
    System.out.println(buf);
}
Also used : ByteBufAllocator(com.generallycloud.baseio.buffer.ByteBufAllocator) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) PooledByteBufAllocatorManager(com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 2 with PooledByteBufAllocatorManager

use of com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager in project baseio by generallycloud.

the class TestPrintBusyServlet method doAccept.

@Override
protected void doAccept(HttpSession session, HttpFuture future) throws Exception {
    SocketChannelContext context = session.getIoSession().getContext();
    PooledByteBufAllocatorManager allocator = (PooledByteBufAllocatorManager) context.getByteBufAllocatorManager();
    allocator.printBusy();
    future.write("true");
    future.setResponseHeader("Content-Type", "text/html");
    session.flush(future);
}
Also used : PooledByteBufAllocatorManager(com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext)

Example 3 with PooledByteBufAllocatorManager

use of com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager in project baseio by generallycloud.

the class TestShowMemoryServlet method doAccept.

@Override
protected void doAccept(HttpSession session, HttpFuture future) throws Exception {
    ApplicationContext appContext = ApplicationContext.getInstance();
    FutureAcceptorServiceLoader fasLoader = appContext.getFutureAcceptorServiceLoader();
    TestWebSocketChatServlet chatServlet = (TestWebSocketChatServlet) fasLoader.getFutureAcceptor("/web-socket-chat");
    TestWebSocketRumpetrollServlet rumpetrollServlet = (TestWebSocketRumpetrollServlet) fasLoader.getFutureAcceptor("/web-socket-rumpetroll");
    WebSocketMsgAdapter chatMsgAdapter = chatServlet.getMsgAdapter();
    WebSocketMsgAdapter rumpetrollMsgAdapter = rumpetrollServlet.getMsgAdapter();
    SocketChannelContext context = session.getIoSession().getContext();
    HttpContext httpContext = session.getContext();
    BigDecimal time = new BigDecimal(System.currentTimeMillis() - context.getStartupTime());
    BigDecimal anHour = new BigDecimal(60 * 60 * 1000);
    BigDecimal hour = time.divide(anHour, 3, RoundingMode.HALF_UP);
    ByteBufAllocatorManager allocator = context.getByteBufAllocatorManager();
    String allocatorDes = "unpooled";
    if (allocator instanceof PooledByteBufAllocatorManager) {
        allocatorDes = ((PooledByteBufAllocatorManager) allocator).toDebugString();
    }
    ServerConfiguration configuration = context.getServerConfiguration();
    int SERVER_CORE_SIZE = configuration.getSERVER_CORE_SIZE();
    int SERVER_MEMORY_POOL_CAPACITY = configuration.getSERVER_MEMORY_POOL_CAPACITY() * SERVER_CORE_SIZE;
    int SERVER_MEMORY_POOL_UNIT = configuration.getSERVER_MEMORY_POOL_UNIT();
    double MEMORY_POOL_SIZE = new BigDecimal(SERVER_MEMORY_POOL_CAPACITY * SERVER_MEMORY_POOL_UNIT).divide(new BigDecimal(1024 * 1024), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
    int M = 1024 * 1024;
    Runtime runtime = Runtime.getRuntime();
    StringBuilder builder = new StringBuilder(HtmlUtil.HTML_HEADER);
    builder.append("		<div style=\"margin-left:20px;\">\n");
    builder.append("服务器内存使用情况:</BR>\n");
    builder.append("虚拟机占用内存:");
    builder.append(runtime.totalMemory() / M);
    builder.append("M;\n</BR>已占用内存:");
    builder.append((runtime.totalMemory() - runtime.freeMemory()) / M);
    builder.append("M;\n</BR>空闲内存:");
    builder.append(runtime.freeMemory() / M);
    builder.append("M;\n</BR>内存池大小:");
    builder.append(MEMORY_POOL_SIZE);
    builder.append("M;\n</BR>内存池状态(Heap):");
    builder.append(allocatorDes);
    builder.append("\n</BR>聊天室(WebSocket)客户端数量:");
    builder.append(chatMsgAdapter.getClientSize());
    builder.append("\n</BR>小蝌蚪(WebSocket)客户端数量:");
    builder.append(rumpetrollMsgAdapter.getClientSize());
    builder.append("\n</BR>服务器当前连接数(io-session):");
    builder.append(context.getSessionManager().getManagedSessionSize());
    builder.append(";\n</BR>服务器当前会话数(http-session):");
    builder.append(httpContext.getHttpSessionManager().getManagedSessionSize());
    builder.append(";\n</BR>服务运行时间:");
    builder.append(hour + "H;");
    builder.append("		</div>\n");
    builder.append(HtmlUtil.HTML_POWER_BY);
    builder.append(HtmlUtil.HTML_BOTTOM);
    future.write(builder.toString());
    future.setResponseHeader("Content-Type", "text/html");
    session.flush(future);
}
Also used : ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) HttpContext(com.generallycloud.baseio.container.http11.HttpContext) PooledByteBufAllocatorManager(com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager) FutureAcceptorServiceLoader(com.generallycloud.baseio.container.service.FutureAcceptorServiceLoader) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) ByteBufAllocatorManager(com.generallycloud.baseio.buffer.ByteBufAllocatorManager) PooledByteBufAllocatorManager(com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager) BigDecimal(java.math.BigDecimal) ApplicationContext(com.generallycloud.baseio.container.ApplicationContext)

Aggregations

PooledByteBufAllocatorManager (com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager)3 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)3 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)2 ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)1 ByteBufAllocator (com.generallycloud.baseio.buffer.ByteBufAllocator)1 ByteBufAllocatorManager (com.generallycloud.baseio.buffer.ByteBufAllocatorManager)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1 ApplicationContext (com.generallycloud.baseio.container.ApplicationContext)1 HttpContext (com.generallycloud.baseio.container.http11.HttpContext)1 FutureAcceptorServiceLoader (com.generallycloud.baseio.container.service.FutureAcceptorServiceLoader)1 BigDecimal (java.math.BigDecimal)1