各位大牛:
小弟目前项目线上遇到一个诡异的JVM问题,困扰好久,还望各位大牛不吝赐教,万分感谢,情形如下:
使用Zabbix监控JVM内存情况:
dump内存后发现:
于是小弟查找调用代码,发现是在使用BarklyDB添加数据序列化时使用了ByteArrayOutputStream,代码如下:
org.apache.commons.lang3.SerializationUtils public static byte[] serialize(Serializable obj) { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); serialize(obj, baos); return baos.toByteArray(); }
于是使用BTrace跟踪ByteArrayOutputStream代码,BTrace代码如下:
import static com.sun.btrace.BTraceUtils.*; import com.sun.btrace.annotations.*; import java.lang.reflect.Field; import java.lang.reflect.Array; @BTrace public class Trace{ private static Field fd =field("java.io.ByteArrayOutputStream", "buf"); private static Field fd2 =field("java.io.ByteArrayOutputStream", "count"); @OnMethod(clazz="/.*ByteArrayOutputStream/",method="grow",location=@Location(Kind.RETURN)) public static void begin(@Self Object obj,@ProbeMethodName String pmn,int minCapacity){ byte[] bs=(byte[])get(fd,obj); if(bs.length > 1000000){ println("----------------"); if(bs.length > 100000000){ jstack(); } println(strcat("minCapacity: ",str(minCapacity))); println(strcat("buf.length: ",str(bs.length))); println(strcat("count: ",str(getInt(fd2,obj)))); println(timestamp()); } } }
结果如下:
minCapacity: 1137665 14-10-17 下午5:00 ---------------- minCapacity: 2275330 14-10-17 下午5:00 ---------------- minCapacity: 4550660 14-10-17 下午5:00 ---------------- minCapacity: 9101315 14-10-17 下午5:00 ---------------- minCapacity: 18202625 14-10-17 下午5:00 ---------------- minCapacity: 36405250 14-10-17 下午5:00 ---------------- minCapacity: 72810500 14-10-17 下午5:00 ---------------- minCapacity: 145620995 14-10-17 下午5:00 ---------------- minCapacity: 291241985 14-10-17 下午5:00 ---------------- minCapacity: 582483970 14-10-17 下午5:01 ---------------- minCapacity: 1137665 14-10-17 下午5:01 ---------------- minCapacity: 2275330 14-10-17 下午5:01 ---------------- minCapacity: 4550660 14-10-17 下午5:01 ---------------- minCapacity: 9101315 14-10-17 下午5:01 ---------------- minCapacity: 18202625 14-10-17 下午5:01 ---------------- minCapacity: 36405250 14-10-17 下午5:01 ---------------- minCapacity: 72810500 14-10-17 下午5:01 ---------------- minCapacity: 145620995 14-10-17 下午5:01 ---------------- minCapacity: 291241985 14-10-17 下午5:01 ---------------- minCapacity: 582483970 14-10-17 下午5:01上述问题导致线上性能很不稳定,毛刺非常多.但是开发环境测试,始终没有重现,还望各位多多指教.
PS:
线上JDK版本:
Linux内核版本:
Linux version 2.6.32-358.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Fri Feb 22 00:31:26 UTC 2013JVM配置:
-server -Xmx3g -Xms3g -Xmn768m -XX:PermSize=256m -Xss256k -XX:+UseConcMarkSweepGC -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70