Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark spark缓存的奇怪问题_Apache Spark_Hadoop_Dataframe_Caching - Fatal编程技术网

Apache spark spark缓存的奇怪问题

Apache spark spark缓存的奇怪问题,apache-spark,hadoop,dataframe,caching,Apache Spark,Hadoop,Dataframe,Caching,我们正在使用Spark 2.2.0。我们在一个配置单元表中有1.5 TB的数据。我们有80个节点的集群,每个节点有大约512GB的RAM和40个内核 我正在使用Spark SQL访问此数据。使用普通的sparksql(不带缓存)简单的命令,比如获取特定列值的不同计数大约需要13秒。但是,当我在缓存表后运行相同的命令时,需要10分钟以上的时间。不确定问题出在哪里 export SPARK_MAJOR_VERSION=2 spark-shell --master yarn --num-executo

我们正在使用Spark 2.2.0。我们在一个配置单元表中有1.5 TB的数据。我们有80个节点的集群,每个节点有大约512GB的RAM和40个内核

我正在使用Spark SQL访问此数据。使用普通的sparksql(不带缓存)简单的命令,比如获取特定列值的不同计数大约需要13秒。但是,当我在缓存表后运行相同的命令时,需要10分钟以上的时间。不确定问题出在哪里

export SPARK_MAJOR_VERSION=2
spark-shell --master yarn --num-executors 40 --driver-memory 5g --executor-memory 100g --executor-cores 5
spark.conf.set("spark.sql.shuffle.partitions", 10)
val df = spark.sql("select * from analyticalprofiles.customer_v2")
df.createOrReplaceTempView("tmp")
spark.time(spark.sql("select count(distinct(household_number)) from tmp").show())
>> Time taken: 13927 ms



import  org.apache.spark.storage.StorageLevel
val df2 = df.persist(StorageLevel.MEMORY_ONLY)
df2.createOrReplaceTempView("tmp2")
spark.time(spark.sql("select count(distinct(household_number)) from tmp2").show())
>> 1037482 ms ==> FIRST TIME - okay if this is more
spark.time(spark.sql("select count(distinct(household_number)) from tmp2").show())
>> 834740 ms  ==> SECOND TIME - Was expecting much faster execution ???
尝试使用“spark.catalog.cacheTable(“tmp”)”进行相同的操作,但仍然使用缓存查询需要更多的时间。不知道为什么???有人能帮忙吗

df2.storageLevel.useMemory
res6: Boolean = true

sc.getPersistentRDDs
res8: scala.collection.Map[Int,org.apache.spark.rdd.RDD[_]] = Map(12 -> In-memory table tmp MapPartitionsRDD[12] at cacheTable at <console>:24)

spark.conf.get("spark.sql.inMemoryColumnarStorage.compressed")
res11: String = true

spark.conf.get("spark.sql.inMemoryColumnarStorage.batchSize")
res12: String = 10000

spark.catalog.isCached("tmp")
res13: Boolean = true
df2.storageLevel.usemory
res6:Boolean=true
sc.getPersistentRDDs
res8:scala.collection.Map[Int,org.apache.spark.rdd.rdd["]]=Map(12->缓存表中的内存表tmp-MapPartitionsRDD[12]位于:24)
spark.conf.get(“spark.sql.inMemoryColumnarStorage.compressed”)
res11:String=true
spark.conf.get(“spark.sql.inMemoryColumnarStorage.batchSize”)
res12:String=10000
spark.catalog.isCached(“tmp”)
res13:Boolean=true

您可以尝试以下方法

  • 您可以使用以下公式增加执行器的数量并减少执行器内存

      SPARK_EXECUTOR_CORES (--executor-cores) : 5 
    
      Number of Executors (--num-executors) : (number of nodes) *  (number of cores) /(executor cores) -1 (for Application Master) = (80*40)/5 ~ 640-1 = 639
    
      SPARK_EXECUTOR_MEMORY (--executor-memory): Memory/(Number of Executors/Number of Nodes):  512/(639/80) ~ 64 GB
    
  • 如果要持久化数据帧,请使用StorageLevel.MEMORY\u和磁盘服务器。如果内存(RAM)已满,它将保存在磁盘中


  • 希望它能帮助您。

    您能检查一下分区的数量吗?我想检查它是否从内存溢出并试图将其写入磁盘?如果是这样的话,所花费的时间可能是由于写入所需的I/O。似乎许多人都面临着这样的问题。不保证所有的都可以保留,而且我假设集群是一个共享资源。谢谢,我尝试了MEMORY_ONLY和MEMORY_and_DISK_SER。仅使用内存时,它只缓存了18%的数据,但当我使用内存和磁盘时,它缓存了100%——其中18%在内存中,其余在磁盘上。但我发现了另一个问题。磁盘上的数据大小约为1.5 TB(拼花格式),但当我使用Sparks MEMORY_和_disk_SER选项读取数据时,它会占用约11 TB(内存为2 TB,磁盘为9 TB)。为什么会这样?我认为序列化数据在缓存时会占用更少的空间?有没有办法压缩缓存的数据,或者至少让它占用更少的内存/磁盘空间?