Tôi hiện đang cố gắng đào tạo một bộ các Vector từ vựng trên UMBC Webbase Corpus (khoảng 30GB văn bản trong 400 tệp).Cách hiệu quả của bộ nhớ để kết hợp một chuỗi các RDD từ các tệp trong Apache Spark
Tôi thường gặp phải tình trạng thiếu bộ nhớ ngay cả trên 100 GB cộng với Máy. Tôi chạy Spark trong ứng dụng. Tôi đã cố gắng tinh chỉnh một chút, nhưng tôi không thể thực hiện thao tác này trên hơn 10 GB dữ liệu văn bản. Sự tắc nghẽn rõ ràng của việc thực hiện của tôi là sự kết hợp của các RDD được tính toán trước đó, mà ở đó không có ngoại lệ bộ nhớ.
Có lẽ một trong những bạn có kinh nghiệm để đưa ra một bộ nhớ thực hiện hiệu quả hơn này:
object SparkJobs {
val conf = new SparkConf()
.setAppName("TestApp")
.setMaster("local[*]")
.set("spark.executor.memory", "100g")
.set("spark.rdd.compress", "true")
val sc = new SparkContext(conf)
def trainBasedOnWebBaseFiles(path: String): Unit = {
val folder: File = new File(path)
val files: ParSeq[File] = folder.listFiles(new TxtFileFilter).toIndexedSeq.par
var i = 0;
val props = new Properties();
props.setProperty("annotators", "tokenize, ssplit");
props.setProperty("nthreads","2")
val pipeline = new StanfordCoreNLP(props);
//preprocess files parallel
val training_data_raw: ParSeq[RDD[Seq[String]]] = files.map(file => {
//preprocess line of file
println(file.getName() +"-" + file.getTotalSpace())
val rdd_lines: Iterator[Option[Seq[String]]] = for (line <- Source.fromFile(file,"utf-8").getLines) yield {
//performs some preprocessing like tokenization, stop word filtering etc.
processWebBaseLine(pipeline, line)
}
val filtered_rdd_lines = rdd_lines.filter(line => line.isDefined).map(line => line.get).toList
println(s"File $i done")
i = i + 1
sc.parallelize(filtered_rdd_lines).persist(StorageLevel.MEMORY_ONLY_SER)
})
val rdd_file = sc.union(training_data_raw.seq)
val starttime = System.currentTimeMillis()
println("Start Training")
val word2vec = new Word2Vec()
word2vec.setVectorSize(100)
val model: Word2VecModel = word2vec.fit(rdd_file)
println("Training time: " + (System.currentTimeMillis() - starttime))
ModelUtil.storeWord2VecModel(model, Config.WORD2VEC_MODEL_PATH)
}}
}
Dữ liệu 30 GB trong tệp ... chắc chắn sẽ dẫn đến hơn 100 GB đối tượng Java ... Làm như vậy chỉ có một tệp trong bộ nhớ cùng một lúc ... xử lý ... sau đó tải tiếp một. –
Ngoài ra ... không làm điều này -> 'StorageLevel.MEMORY_ONLY_SER' –
Tôi cần xử lý chúng cùng một lúc vì trong bước phù hợp với mô hình, tất cả dữ liệu cần phải có mặt – dice89