IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> easyexcel替换poi导出大数据量数据时解决内存溢出问题时的一个性能测试 -> 正文阅读

[大数据]easyexcel替换poi导出大数据量数据时解决内存溢出问题时的一个性能测试

最近在项目中遇到导出大量数据到excel时发生内存溢出问题,然后看网上有人说用阿里开源的easyexcel性能非常好,我就在本地做了一个关于easyexcel和poi导出100w条一样数据时占用内存情况的测试,内存情况及GC情况用JDK自带的visualVM进行监控。

  • 首先是poi的导出内存情况及代码示例:
public class PoiDemo {
    public static void main(String[] args) {
        Workbook w = new XSSFWorkbook();
        Sheet sheet = w.createSheet();
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 1000000; i++) {
            Row row = sheet.createRow(i);
            Student student = new Student();
            student.setAge("age:"+i);
            student.setDay("day:"+i);
            student.setHeight("height:"+i);
            student.setMonth("month:"+i);
            student.setName("name:"+i);
            student.setWeight("weight:"+i);
            student.setYear("year:"+i);
            students.add(student);
            row.createCell(0).setCellValue(student.getAge());
            row.createCell(1).setCellValue(student.getDay());
            row.createCell(2).setCellValue(student.getHeight());
            row.createCell(3).setCellValue(student.getMonth());
            row.createCell(4).setCellValue(student.getName());
            row.createCell(5).setCellValue(student.getWeight());
            row.createCell(6).setCellValue(student.getYear());
        }
        String filePath = "D:\\easyExcel.xlsx";
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(filePath);
            w.write(fileOutputStream);
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}

运行情况:
在这里插入图片描述
这个是我运行了近两分钟的情况,可以看到运行25秒后堆空间基本已经无法扩容而且GC也回收不了其他对象了,这样运行下去肯定会OOM了。测试结果表明POI导出100w条数据占用堆内存肯定超过3000多M的。

  • 再看easyexcel的导出情况和代码示例:
public class EasyDemo {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 1000000; i++) {
            Student student = new Student();
            student.setAge("age:"+i);
            student.setDay("day:"+i);
            student.setHeight("height:"+i);
            student.setMonth("month:"+i);
            student.setName("name:"+i);
            student.setWeight("weight:"+i);
            student.setYear("year:"+i);
            students.add(student);
        }
        String filePath = "D:\\easyExcel.xlsx";
        EasyExcel.write(filePath,Student.class).sheet("测试1").doWrite(students);
    }
}

运行情况:
在这里插入图片描述

可以看到只用14秒的时间就完成了100w数据量的导出,并且内存只占用了750M的样子,性能确实非常好。所以导出大数据量数据时可以使用easyexcel,还是比较好用的。

  • 最好附上easyexcel的maven仓库地址
<dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.2.6</version>
</dependency>

实体类代码:

public class Student {
    private String name;
    private String age;
    private String height;
    private String weight;
    private String year;
    private String month;
    private String day;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }
}

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-07-10 11:34:54  更:2021-07-10 11:35:41 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/5 0:08:06-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码