在DirectMemory中找不到PooledUnsafeDirectByteBuf [英] PooledUnsafeDirectByteBuf not found in DirectMemory

查看:1105
本文介绍了在DirectMemory中找不到PooledUnsafeDirectByteBuf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netty 4.1.17-Final.

I am using Netty 4.1.17-Final.

我编写了发送和接收100 MB随机ASCII的代码.直到ByteBuf变为100 MB时,解码器才会读取.

I wrote the code to send and receive 100 MB random ASCII. Decoder does not read until ByteBuf becomes 100 MB.

@Override
public void decode(ByteBuffer _in, List<Object> _out) {
    if (_in.remaining() == size) {   // size = 100 * 1024 * 1024
        _in.get(new byte[size]);
    }
}

因此,Netty会缓冲100 MB,但即使通过监视直接内存也找不到它.

Therefore, Netty buffers 100 MB, but it was not found even by monitoring Direct Memory.

System.out.println(sun.misc.SharedSecrets.getJavaNioAccess().getDirectBufferPool().getMemoryUsed());
ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class).forEach(buf -> {
    System.out.printf("%s: Used=%d, TotalCap=%d%n", buf.getName(), buf.getMemoryUsed(), buf.getTotalCapacity());
});

// Result
// 10
// direct: Used=9, TotalCap=8
// mapped: Used=0, TotalCap=0

Netty使用PooledUnsafeDirectByteBuf,但是您在哪里缓冲接收到的数据?还是直接缓冲区监视方法不正确?

Netty used PooledUnsafeDirectByteBuf, but where do you buffer the received data? Or is the direct buffer monitoring method incorrect?

推荐答案

您可以告诉Netty不要将Unsafe用作直接缓冲区,因此它会再次出现在JMX中.不幸的是,这也会对性能产生一些影响.

You can tell Netty to not use Unsafe for the direct buffers and so have it show up in JMX again. Unfortunally this also will have some performance impact.

只需使用-Dio.netty.maxDirectMemory=0.

请参阅: https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/internal/PlatformDependent.java#L153

这篇关于在DirectMemory中找不到PooledUnsafeDirectByteBuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆