leewenshu36 opened a new issue, #60435:
URL: https://github.com/apache/spark/issues/60435
Description
I encountered a JVM OutOfMemoryError: Java heap space when calling
DataFrame.collect() on a PySpark DataFrame loaded from PostgreSQL using JDBC.
The DataFrame was reduced to only three columns before collection. However,
the Spark executor ran out of Java heap memory during task-result serialization.
I would like to understand whether this behavior is expected for large JDBC
datasets or whether there is an issue with memory management during result
serialization.
Environment
OS: Linux
Python: 3.12
Apache Spark / PySpark version: [Please provide]
Java version: [Please provide]
PostgreSQL JDBC driver: 42.7.14
Spark deployment mode: [Please provide]
Driver memory: [Please provide]
Dataset: Large PostgreSQL table containing industrial monitoring records
Steps to Reproduce
from pyspark.sql import functions as F
data = (
spark.read
.format("jdbc")
.option("url", jdbc_url)
.option("dbtable", "public.example_table")
.option("user", username)
.option("password", password)
.option("driver", "org.postgresql.Driver")
.load()
)
data = data.select(
"mp_id",
"data_time",
"important_industry_name"
).filter(
F.col("mp_id").isNotNull()
& F.col("data_time").isNotNull()
)
rows = data.collect()
example_table represents the actual PostgreSQL table. A smaller independent
reproducer has not yet been established.
Actual Behavior
The Spark executor fails with the following exception:
ERROR Executor: Exception in task 0.0 in stage 39.0
java.lang.OutOfMemoryError: Java heap space
at java.base/java.nio.HeapByteBuffer.<init>
at java.base/java.nio.ByteBuffer.allocate
at org.apache.spark.serializer.SerializerHelper$.
serializeToChunkedBuffer
at org.apache.spark.executor.Executor$TaskRunner.run
ERROR TaskSetManager:
Task 0 in stage 39.0 failed 1 times; aborting job
The Python application subsequently reports:
py4j.protocol.Py4JJavaError:
An error occurred while calling collectToPython.
org.apache.spark.SparkException:
Job cancelled because SparkContext was shut down
Expected Behavior
I understand that DataFrame.collect() transfers the full result to the
driver and may exceed the available memory.
However, I would like to clarify whether the observed failure during
executor-side serialization is expected and whether there are recommended
configurations or safeguards for this scenario.
Questions
Is this OutOfMemoryError during SerializerHelper.serializeToChunkedBuffer
expected when collecting a large JDBC DataFrame?
Could JDBC partitioning or task-result serialization contribute to excessive
JVM heap consumption?
Are there recommended strategies to avoid this failure while processing
large JDBC datasets?
Additional Information
The original execution log can be attached after removing private hostnames,
IP addresses, database credentials, and local paths.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]