When does Spark send data to different executors after I created a DataFrame with RDD?

Viewed 19

I'm trying to construct a DataFrame from a list of data, then write it as parquet files:

dataframe = None
while True:
    data_list = get_data_list() # this function would return a list of data, about 1 million rows
    rdd = sparkContext.parallelize(data_list, 20)
    if dataframe:
        dataframe.union(sparkSession.createDataFrame(data=rdd))
    else:
        dataframe = sparkSession.createDataFrame(data=rdd)
    
    if some_judgement:
        break
dataframe.write.parquet('...')

But I found the driver would fail with java.lang.OutOfMemoryError: Java heap space after a few cycles. If I increase the driver-memory or decrease the number of cycles in the loop, this exception stops occurring. So I guess even if I created an RDD, the data is still stored in the driver. So when will the data be sent to executors ? I want to decrease the memory usage of the driver.

1 Answers

Can you check the logs and see where the exception is happening (Either at driver or executor)? If its happening at driver -> can you increase driver memory to 8 or 10 GB and see if it gets succeeded ?

Also I would suggest to set some higher values for memoryOverHead params.

spark.driver.memoryOverhead
spark.executor.memoryOverhead
Related