簡體   English   中英

Spark Java堆空間

[英]Spark Java Heap Space

我有一個問題與火花,當我試圖生成模型我得到一個例外的Java堆空間,我無法解決。 我試圖將這些值放在VM選項-Xmx4g上,但沒有任何反應。 我試圖將這些參數添加到spark配置但是再沒有任何事情發生。 Java版本:7 Spark版本:2.1.0

 SparkConf conf = newSparkConf().setAppName("myAPP").setMaster("local");
    conf = (conf.setMaster("local[*]"));
    SparkContext sc = new SparkContext(conf);


    JavaRDD<LabeledPoint> data = MLUtils.loadLibSVMFile(sc, path).toJavaRDD();

    // Split initial RDD into two... [60% training data, 40% testing data].
    JavaRDD<LabeledPoint>[] splits =
            data.randomSplit(new double[]{0.6, 0.4}, 11L);
    JavaRDD<LabeledPoint> training = splits[0].cache();
    JavaRDD<LabeledPoint> test = splits[1];

    // Run training algorithm to build the model.
    final LogisticRegressionModel model = new LogisticRegressionWithLBFGS()
            .setNumClasses(2)
            .run(training.rdd());

    // Clear the prediction threshold so the model will return probabilities
    model.clearThreshold();


    // Compute raw scores on the test set.
    JavaRDD<Tuple2<Object, Object>> predictionAndLabels = test.map(
            new Function<LabeledPoint, Tuple2<Object, Object>>() {
                @Override
                public Tuple2<Object, Object> call(LabeledPoint p) {
                    Double prediction = model.predict(p.features());
                    return new Tuple2<Object, Object>(prediction, p.label());
                }
            }
    );

    // Get evaluation metrics.
    BinaryClassificationMetrics metrics =
            new BinaryClassificationMetrics(predictionAndLabels.rdd());

錯誤

18/05/02 13:06:49 INFO DAGScheduler: Job 1 finished: first at GeneralizedLinearAlgorithm.scala:206, took 0,038806 s
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at org.apache.spark.mllib.linalg.Vectors$.zeros(Vectors.scala:340)
    at org.apache.spark.mllib.regression.GeneralizedLinearAlgorithm.run(GeneralizedLinearAlgorithm.scala:222)
    at Principal.main(Principal.java:114)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

我經常遇到這個問題,我們使用動態資源分配,我認為它將利用我的群集資源來最好地適應應用程序。

但事實是,動態資源分配不會設置驅動程序內存,而是將其保持為默認值1g。

我已經通過將spark.driver.memory設置為適合我的驅動程序內存的數字來解決它(對於32gb ram我將其設置為18gb)

你可以使用spark submit命令設置它,如下所示:

spark-submit --conf spark.driver.memory=18gb ....cont

非常重要的說明,根據spark文檔,如果您從代碼中設置它,則不會考慮此屬性:

Spark屬性主要可以分為兩種:一種與deploy相關,如“spark.driver.memory”,“spark.executor.instances”,在運行時通過SparkConf以編程方式設置時,這種屬性可能不受影響,或者行為取決於您選擇的集群管理器和部署模式,因此建議通過配置文件或spark-submit命令行選項進行設置; 另一個主要與Spark運行時控件有關,比如“spark.task.maxFailures”,這種屬性可以以任何一種方式設置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM