-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extension for tracking off-heap memory use for netty #475
Comments
Some more information: https://dzone.com/articles/default-hotspot-maximum-direct-memory-size |
Test program: import java.lang.management.*;
import java.lang.reflect.*;
import java.nio.*;
import sun.misc.*;
public class Test {
private static void dumpBufferStats() {
System.out.println("==========================================");
System.out.println("BufferPoolMXBean");
System.out.println("------------------------------------------");
for (BufferPoolMXBean mbean : ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class)) {
System.out.printf("%s: count %d, capacity %d, used %d%n",
mbean.getName(),
mbean.getCount(),
mbean.getTotalCapacity(),
mbean.getMemoryUsed());
}
JavaNioAccess.BufferPool pool = SharedSecrets.getJavaNioAccess().getDirectBufferPool();
System.out.printf("SharedSecrets: %s: count %d, capacity %d, used %d%n",
pool.getName(),
pool.getCount(),
pool.getTotalCapacity(),
pool.getMemoryUsed());
System.out.printf("VM.maxDirectMemory: %d%n", VM.maxDirectMemory());
System.out.println("==========================================\n\n");
}
private static Unsafe getUnsafe() throws Exception {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe) f.get(null);
}
public static void main(String[] args) throws Exception {
dumpBufferStats();
System.out.println("ByteBuffer.allocateDirect(4096)");
ByteBuffer.allocateDirect(4096);
dumpBufferStats();
System.out.println("Unsafe.allocateMemory(4096)");
long address = getUnsafe().allocateMemory(4096);
dumpBufferStats();
System.out.println("Unsafe.freeMemory(address)");
getUnsafe().freeMemory(address);
dumpBufferStats();
}
} Neither BufferPoolMXBean or SharedSecrets captures memory allocated using
|
@brharrington in both the tests you've done above, the used and capacity values were 0 in the beginning and then after calling
Also, is the BufferPoolMeter's equivalent of spectator/spectator-ext-jvm/src/main/java/com/netflix/spectator/jvm/BufferPoolMeter.java Line 38 in 5b72bb6
|
Yes, I meant The buffer pool memoryUsed metric will get set to the value from |
For a lot of the common netty usage, it is probably possible to use PooledByteBufAllocator.metric. The other problem we have run into is a lot of our internal usage now shadows netty (e.g. gRPC) so it is a bit harder for us to hook into the right places for each shadowed version. That is partly why I would prefer to capture it at the JVM level, but I don't think that is possible right now. |
Netty is used widely at Netflix and it uses off-heap memory that is not showing up in the existing buffer pool metrics. It would be useful if we could support an extension for tracking the memory use of netty allocators.
The text was updated successfully, but these errors were encountered: