mysql fetchsize_Sqoop fetchsize失效-阿里云开发者社区

前几天线上Sqoop的一个Job(从MySQL抽取数据到Hadoop)突然报了OOME,后重跑并做java trace发现内存占用都是byte[],同时cpu top 3的方法都是com.mysql.jdbc.ByteArraryBuffer.getBytes即内存都是被数据消耗掉了;很奇怪,为什么在option里指定了fetch-size=100怎么会OOME呢(平均记录长度不到1kb);

再看昨天成功的发现100W条记录,发现占用了860MB内存,明显是fetch-size没有生效

+---------+---------+------------+----------+-------------+--------------+

|type | status | host | cpusec | mrinput_rec |memory_mb |

+---------+---------+------------+----------+-------------+--------------+

|CLEANUP | SUCCESS | A | 0.3400 | NULL | 191.84765625 |

|MAP | SUCCESS | A | 335.6400 | 1006942 | 862.39843750 |

|SETUP | SUCCESS | B | 0.2000 | NULL | 179.34765625 |

+---------+---------+------------+----------+-------------+--------------+

没办法,把sqoop源码翻出来终于发现RC了:fetchsize被忽略掉了

protectedvoidinitOptionDefaults() {

if(options.getFetchSize() ==null) {

LOG.info("Preparing to use a MySQL streaming resultset.");

options.setFetchSize(Integer.MIN_VALUE);

}elseif(

!options.getFetchSize().equals(Integer.MIN_VALUE)

&&!options.getFetchSize().equals(0)) {

LOG.info("Argument '--fetch-size "+ options.getFetchSize()

+"' will probably get ignored by MySQL JDBC driver.");

}

}

究其原因是MySQL提供的API只支持row-by-row和all模式:

By default,ResultSets are completely retrieved and stored in memory. In most cases this isthe most efficient way to operate, and due to the design of the MySQL networkprotocol is easier to implement. If you are working with ResultSets that have alarge number of rows or large values, and cannot allocate heap space in yourJVM for the memory required, you can tell the driver to stream the results backone row at a time.

最后把fetchsize给去掉了,Job执行成功,700W行占用内存400MB;

+---------+---------+------------+----------+-------------+--------------+

| type | status | host | cpusec | mrinput_rec | memory_mb |

+---------+---------+------------+----------+-------------+--------------+

| CLEANUP | SUCCESS | A | 0.4200 | NULL | 183.49218750 |

| MAP | FAILED | B | NULL | NULL | NULL |

| MAP | SUCCESS | A | 377.1200 | 7195560 | 408.08593750 |

| SETUP | SUCCESS | C | 0.2900| NULL | 188.64843750 |

+---------+---------+------------+----------+-------------+--------------+

本文转自MIKE老毕 51CTO博客,原文链接:http://blog.51cto.com/boylook/1298634,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值