Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visualvm profiles jvm heap found int array takes huge memory

I have a Spring boot program using OpenJdk (jdk1.8) running at server, consuming about 200 or 300 million data from kafka and write to csv files each day. Less than 2 hours after starts up, it using more than 6GB memory. So I dump heap using jmap histo. And find that int[] array using 2.6GB and byte[] array using 1.3GB. enter image description here But I defined neither int[] nor byte[] in my project. I'm using spring kafka(org.springframework.kafka, version2.3.3) consume kafka message, opencsv(com.opencsv, version4.6) write csv.

Any one knows the reason?

Below is part of my code:

public <T> Boolean parseDataToFile(String filePath, List<T> data) throws IOException, CsvDataTypeMismatchException, CsvRequiredFieldEmptyException {
    if (data == null || data.size() <= 0) {
        return false;
    }
    File file = new File(filePath);
    //创建父目录
    boolean mkdirs = file.getParentFile().mkdirs();
    Writer writer = null;
    try {
        writer = new FileWriter(filePath, true);
        StatefulBeanToCsv beanToCsv = new StatefulBeanToCsvBuilder(writer).withThrowExceptions(false).withSeparator(',').build();
        beanToCsv.write(data);
        return true;
    } finally {
        if (writer != null) {
                writer.flush();
                writer.close();
        }
    }
}

Addtion: at Instance view, most(more than 90%) of them are none-used(retained size are 0), so it can be GCed? But why not? What are these int[] byte[] data? enter image description here

like image 533
Joshua Avatar asked Jan 24 '26 12:01

Joshua


1 Answers

Thanks to @AlBlue and @JurajMartinka. I analysed the byte[] array and int[] array and found part of the answer. The int[] array which have 166921 instance, using 2.6GB memory(57.3%). Most of them have no reference: enter image description here Some of them are used by kafka: enter image description here Meanwhile spring boot loader: enter image description here

On the other hand, the byte[] array have 39400 instance, using 1.3GB memory(28.8%). Most of them are kafka data: enter image description here Some are other referred dependencies: enter image description here

The real memory using by live objects are not big. MAT(The Eclipse Memory Analyzer tool) shows that only 43.6M are occupied. enter image description here

Yet, there are still many questions needs to find out. Such as when to GC, where is netty used, etc.

like image 121
Joshua Avatar answered Jan 27 '26 01:01

Joshua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!