[SUPPORT]Use Spark to Hudi and JVM Metaspace OOM
Use Spark to Hudi and JVM Metaspace OOM
When I use the Spark API to write a piece of data to Hudi, I notice that the JVM's Metaspace continues to grow until the OOM.
Here's my code:
def testBloomFileByHudi(spark: SparkSession, tablePath: String, tableName: String, operation: String) = {
val list = new ListBuffer[TestPartition]();
list.+=:(TestPartition(1, 2, "a", "b","2015/01/01"))
val df = spark.createDataFrame(list)
df.write.format("org.apache.hudi").
options(getQuickstartWriteConfigs).
option(PRECOMBINE_FIELD_OPT_KEY, "ts").
option(RECORDKEY_FIELD_OPT_KEY, "id").
option(HoodieIndexConfig.INDEX_TYPE_PROP, IndexType.GLOBAL_BLOOM.name()).
option(HoodieIndexConfig.BLOOM_INDEX_UPDATE_PARTITION_PATH, "true").
option(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY, "date").
option(TABLE_NAME, tableName).
option(PAYLOAD_CLASS_OPT_KEY, classOf[OverwriteNonPartialWithLatestAvroPayload].getName).
option(OPERATION_OPT_KEY, operation).
mode(Append).
save(tablePath)
}
val spark = HoodieExampleSparkUtils.defaultSparkSession("Hudi Spark basic example")
for (i <- 1 to 1000){
testBloomFileByHudi(spark, tablePath, "hoodie_foo_tbl",WriteOperationType.UPSERT.value())
println(s"i = $i")
}
Then I let this method loop 1000 times, I found every JVM load of classes named GeneratedSerializationConstructorAccessor, this look like a generated by reflection.
this is my start jvm parameters.
-Xmn400m
-Xms2000m
-Xmx2000m
-XX:SurvivorRatio=2
-XX:MetaspaceSize=256m
-XX:MaxMetaspaceSize=256m
-XX:+CMSClassUnloadingEnabled
-XX:SoftRefLRUPolicyMSPerMB=1000
-XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses
-XX:+UseCompressedOops
-XX:+UseConcMarkSweepGC
-XX:+UseParNewGC
-XX:CMSInitiatingOccupancyFraction=70
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+UnlockDiagnosticVMOptions
-XX:+HeapDumpOnOutOfMemoryError
-Dsun.reflect.inflationThreshold=2147483647
-XX:+TraceClassLoading
-XX:+TraceClassUnloading
-XX:HeapDumpPath=/Users/edz/Desktop/heapDump1.hprof
and this is number of jvm load classes.
GeneratedSerializationConstructorAccessor loaded by sun.reflect.DelegatingClassLoader.These classes remain loaded until Full GC and are unloaded. This results in frequent Full GC.
Trace the code and I find that these reflections are caused by Spark's transform operator, since an operator like map calls sc.clean() at the beginning. In this method, the following method is called.

Environment Description
- Hudi version : 0.8.0
- Spark version : 2.4.7
- Running on Docker? (yes/no) : no
- OS:Mac
Can any one please help us to fix this issue.
awesome find! thanks.