spark streaming 调试技巧

  1. spark streaming 如果以local 模式运行,log日志非常清楚。
  2. 如果log 日志是运行在yarn 模式下,driver 的日志可以通过reource manager 日志看到。但是executor的日志却看不到,我们往往错误都发生在executor里,比如典型的错误:如果我们连接hbase去存取数据的话,我们会在driver里初始化了连接,缺忽略的excutors里,导致程序出错。如果你的代码里有try cache,executor的 错误不会影响driver 运行,但是结果却是错误的。我们这需要查看executor的日志:由于executor运行在yarn 的模式下,我们从本地containner查看日志。 CDH 版本yarn container 的日志再以下路径下:

[root@hadoop-3 ~]# ll /var/log/hadoop-yarn/container/application_1429701572510_0022/container_1429701572510_0022_01_000002/
总用量 932
-rw-r–r– 1 yarn yarn 339015 4月 29 11:53 stderr
-rw-r–r– 1 yarn yarn 613851 4月 29 11:53 stdout (我们输出的日志)

  1. hbase 初始化连接,官网也有说明,在executor去初始化:

userLog.foreachRDD(new Function2<JavaPairRDD<String, Iterable<String>>, Time, Void>() {
    @Override
    public Void call(JavaPairRDD<String, Iterable<String>> stringIterableJavaPairRDD, Time time) throws Exception {
        if(!stringIterableJavaPairRDD.partitions().isEmpty()) {
            stringIterableJavaPairRDD.foreachPartition(new VoidFunction<Iterator<Tuple2<String, Iterable<String>>>>() {
                @Override
                public void call(Iterator<Tuple2<String, Iterable<String>>> tuple2Iterator) throws Exception {
                    //初始化hbase 连接
                    HBaseConnectionFactory.init();
                    while (tuple2Iterator.hasNext()) {
                      // 具体的逻辑代码
                    }

            });}
            return null;
        }
});

上述代码有个bug,这样会初始化很多的hbase connection,最后抛出类似如下异常:
Caused by: java.net.SocketException: 打开的文件过多
加个判断,

userLog.foreachRDD(new Function2<JavaPairRDD<String, Iterable<String>>, Time, Void>() {
    @Override
    public Void call(JavaPairRDD<String, Iterable<String>> stringIterableJavaPairRDD, Time time) throws Exception {
        if(!stringIterableJavaPairRDD.partitions().isEmpty()) {
            stringIterableJavaPairRDD.foreachPartition(new VoidFunction<Iterator<Tuple2<String, Iterable<String>>>>() {
                @Override
                public void call(Iterator<Tuple2<String, Iterable<String>>> tuple2Iterator) throws Exception {
                    //初始化hbase 连接
                  if(HBaseConnectionFactory.getConnection() == null || HBaseConnectionFactory.getConnection.isClosed())
                    HBaseConnectionFactory.init();
                    while (tuple2Iterator.hasNext()) {
                      // 具体的逻辑代码
                    }

            });}
            return null;
        }
});
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值