
可以看出来实际设置了10G,而执行内存却只有了3.5G,所以需要根据业务来进行参数调整。
2.1 调大spark.memory.storageFraction=0.6如果程序中有需要使用内存Cache的而不需要太多计算shuffer之类的那么可以增加存储内存,调大spark.memory.storageFraction参数
2.2 调小spark.memory.storageFraction=0.3为了减少有些数据结构与对象的元数据占用大量空间,尽量使用:
字符串代替对象,基本数据类型(int long)代替字符串,数组代替ArrayList等
String内部是一个char数据,char采用UTF-16编码,每个字符两字节,可以设置JVM参数 -XX:+UseCompressedStrings采用8位来编码每一个ASCII字符来压缩字符。
# --为了好看换行了
spark-submit --master spark://11.172.54.167:7077
--class $main --deploy-mode client --driver-memory 16g
--executor-memory 25g
--executor-cores 8
--total-executor-cores 320
--conf spark.memory.fraction=0.8
--conf spark.memory.storageFraction=0.3
--conf spark.memory.offHeap.enabled=true
--conf spark.memory.offHeap.size=5g
--conf "spark.executor.extraJavaOptions=-XX:+UseG1GC -XX:-TieredCompilation -XX:G1HeapRegionSize=16m -XX:InitiatingHeapOccupancyPercent=55 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:-UseCompressedClassPointers -XX:metaspaceSize=256m -XX:MaxmetaspaceSize=256m -XX:ReservedCodeCacheSize=512m -XX:+UseCodeCacheFlushing -XX:ParallelGCThreads=20 -XX:ConcGCThreads=20 -Xms22g -Xmn18g -XX:+PrintGCDetails -XX:+PrintGCTimeStamps"
--jars $jars xxxx.jar $date1 $max $date2 >> log/$log_file
#代码内参数
conf.set("spark.driver.maxResultSize", "8g");
conf.set("spark.serialize", "org.apache.spark.serializer.KryoSerializer");
conf.registerKryoClasses(new Class[]{ImmutableBytesWritable.class, HyperLogLog.class, HashSet.class, RegisterSet.class, IllegalArgumentException.class, FileCommitProtocol.TaskCommitMessage.class});
//conf.set("spark.kryo.registrationRequired","true"); #开启的话类没加到上面会报错
conf.set("spark.kryoserializer.buffer.mb", "10");
conf.set("spark.shuffle.file.buffer", "128");
conf.set("spark.reducer.maxSizeInFlight", "144");
conf.set("spark.shuffle.io.maxRetries", "50");
conf.set("spark.shuffle.io.retryWait", "5s");