小编use*_*932的帖子

在spark中的大数据上运行reduceByKey

我在spark中运行reduceByKey.我的程序是spark的最简单的例子:

val counts = textFile.flatMap(line => line.split(" ")).repartition(20000).
                 .map(word => (word, 1))
                 .reduceByKey(_ + _, 10000)
counts.saveAsTextFile("hdfs://...")
Run Code Online (Sandbox Code Playgroud)

但它总是耗尽内存......

我使用50台服务器,每台服务器35个执行器,每台服务器140GB内存.

文件量为:8TB文件,20亿文件,总计1000亿字.减少后的字数将约为1亿.

我想知道如何设置spark的配置?

我想知道这些参数应该是什么价值?

1. the number of the maps ? 20000 for example?
2. the number of the reduces ? 10000 for example?
3. others parameters?
Run Code Online (Sandbox Code Playgroud)

apache-spark

8
推荐指数
1
解决办法
2702
查看次数

如何处理spark map()函数中的Exception?

我想在map()函数中忽略Exception,例如:

rdd.map(_.toInt)
Run Code Online (Sandbox Code Playgroud)

其中rdd是一个RDD[String].

但如果它遇到非数字字符串,它将失败.

什么是忽略任何异常并忽略该行的简单方法?(我不想使用过滤器来处理异常,因为可能有很多其他异常......)

scala apache-spark

6
推荐指数
2
解决办法
1万
查看次数

如何使用大括号扩展变量

我有四个文件:

1.txt  2.txt  3.txt  4.txt
Run Code Online (Sandbox Code Playgroud)

在linux shell中,我可以使用: ls {1..4}.txt 列出所有四个文件,但是如果我设置两个变量:var1 = 1和var2 = 4,如何列出这四个文件?那是:

var1=1
var2=4
ls {$var1..$var2}.txt  # error
Run Code Online (Sandbox Code Playgroud)

什么是正确的代码?

linux bash shell brace-expansion

4
推荐指数
1
解决办法
539
查看次数

我什么时候应该在 Scala 中使用“new”?

当我使用时ArrayBuffer,我应该使用:

val arr = new ArrayBuffer[Int]
Run Code Online (Sandbox Code Playgroud)

但是当我使用时Map,我应该使用:

val map = Map[Int, Int]()
Run Code Online (Sandbox Code Playgroud)

collections dictionary scala scala-collections arraybuffer

2
推荐指数
1
解决办法
1040
查看次数

我如何获得scala数组中的第一个K元素?

我想在scala数组中获得第一个K元素,在Python中,我可以使用:

arr[0:K] 获得arr的顶级K元素,

我怎么能在scala中做?

scala

2
推荐指数
1
解决办法
689
查看次数

如何使用逗号将 ls 命令的结果连接到字符串中

我正在使用Linux shell。

我想将ls .结果连接到一个字符串中。

例如:

a=`ls .`
echo $a
Run Code Online (Sandbox Code Playgroud)

那么 $a 将是“file1 file2 file3”

但我希望它是“文件1,文件2,文件3”

很热意识到这一点?

linux shell

2
推荐指数
1
解决办法
4650
查看次数

如何将Tuple2附加到ArrayBuffer?

我的scala代码有什么问题吗?

val arr = new ArrayBuffer[Tuple2]
val t = (1, 2)
arr.append(t)
Run Code Online (Sandbox Code Playgroud)

我认为我的代码是正确的,但编译器说:

type mismatch, expected:Tuple2, actual:(int, int)
Run Code Online (Sandbox Code Playgroud)

我想知道Tuple2和之间的区别是什么(int, int)

scala

1
推荐指数
1
解决办法
115
查看次数

是否有更优雅的方式来实现滤镜+地图火花功能

我想使用flatMap来实现filter()+ map(),如下面的代码:有三个if语句用于输出一个Tuple2.否则将输出一个空数组[Tuple2]

你有更优雅的方式来实现这个功能吗?

 rddx.flatMap { case (arr: Array[String]) =>
          val url_parts = arr(1).split("/")
          if (url_parts.length > 7) {
            val pid = url_parts(4)
            val lid = url_parts(7).split("_")
            if (lid.length == 2) {
              val sid = lid(0)
              val eid = lid(1)
              if (eid.length > 0 && eid(0) == "h") {
                Array((pid, 1))
              }
              else new Array[(String, Int)](0)
            }
            else Array((pid, 1))
          }
          else new Array[(String, Int)](0)
         }
Run Code Online (Sandbox Code Playgroud)

scala apache-spark

1
推荐指数
1
解决办法
1636
查看次数

为什么g ++编译器使用这么多内存?

我在我的ubuntu服务器上写了一个最简单的c ++程序:

TEST.CPP:

#include<iostream>
using namespace std;
int a[100*100*100*100*10];
int main() {
    unsigned int count = 0;
    for (int i = 0; i < 100*100*100*100*10; i++) {
        if (i % 10000000 == 0) cout << i << endl; 
        a[i] = i;
        count += i; 
    }
    cout << count << endl;
}
Run Code Online (Sandbox Code Playgroud)

我的g ++编译器是:

root@ubuntu:~# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 …
Run Code Online (Sandbox Code Playgroud)

c++

0
推荐指数
1
解决办法
2484
查看次数