Google-perftools analyzing Java out-of-heap memoryCategory: J2se2011-08-25 21:48 3358 People read Comments (4) favorite reports javahbasehtml tool OS
Translated from: http://koven2049.iteye.com/blog/1142768, all rights attributed to the original author
HBase discovery, which runs on the line recently, allocates 16g of memory, but actually uses 22g, and the out-of-heap memory reaches 6g. It feels very strange. Out-of-heap memory is difficult to see with general tools and can be tracked by Google-perftools:
Http://code.google.com/p/google-perftools/downloads/list
The idea is that when a Java application runs, it's libtcmalloc.so when you call malloc, so you can do some statistics.
- Download Http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-beta.tar.gz,configure;make;sudo make Install
- Download http://google-perftools.googlecode.com/files/google-perftools-1.8.1.tar.gz, configure--prefix=/home/user/ Perftools;make;sudo make Install
- Join before application launch: Export ld_preload=/home/hadoop/perftools/lib/libtcmalloc.so and Export heapprofile=/home/user/perftools/ Test
- Modify Lc_config:sudo vi/etc/ld.so.conf.d/usr_local_lib.conf, add/usr/local/lib (the directory where the Libunwind Lib is located)
- Execute sudo/sbin/ldconfig to make libunwind effective
- Start the application and you will see a heap file such as Test_pid.xxxx.heap under/home/user/perftools/, using Bin/bin/pprof--text $JAVA _home/bin/java test_ Pid.xxxx.heap to view
See the following through Perftools:
- Total: 3263.2 MB
- 3145.2 96.4% 96.4% 3145.2 96.4% zcalloc
- 83.8 2.6% 99.0% 83.8 2.6% os::malloc
- 30.0 0.9% 99.9% 30.0 0.9% init
- 2.2 0.1% 99.9% 2.2 0.1% objectsynchronizer::omalloc
- 1.0 0.0% 100.0% 3144.1 96.4% java_java_util_zip_deflater_init
- 0.6 0.0% 100.0% 0.7 0.0% readcen
Visible calls to Java.util.zip.Deflater occupy the vast majority. Knowing that this deflater has a bug that cannot free memory, write btrace to see if it has entered the function:
- Import static com.sun.btrace.btraceutils.*;
- Import com.sun.btrace.annotations.*;
- Import Java.nio.ByteBuffer;
- Import Java.lang.Thread;
- @BTrace public class testregion1{
- @OnMethod (
- clazz="Java.util.zip.Deflater",
- method="Deflate"
- )
- public static void Tracecacheblock () {
- println ("deflate?");
- }
- }
I found that this line of code is constantly being called. What should be done?
Since Deflater is the code that gzip needs to use, look at the user-created table, discover that the compressor setting is GZ, try to adjust to Lzo, and find btrace Unable to enter the above code, and then view it through Perftools, the heap memory no longer applies, completely no longer applies ...
episode, the author of Perftools is an honest man, provided a zip version of the download, but do not provide installation files, why? In the Readme, the following paragraph is spoken:
- I don ' t know very much about what to install DLLs on Windows, so you ll
- There is a to figure out the that part for yourself.
Google-perftools analyzing Java out-of-heap memory