pyspark Sparkconf()參數配置


from pyspark import SparkContext, SparkConf
from pyspark.sql import SparkSession


def create_sc():
    sc_conf = SparkConf()
    sc_conf.setMaster('spark://master:7077')
    sc_conf.setAppName('my-app')
    sc_conf.set('spark.executor.memory', '2g')  #executor memory是每個節點上占用的內存。每一個節點可使用內存
    sc_conf.set("spark.executor.cores", '4') #spark.executor.cores:顧名思義這個參數是用來指定executor的cpu內核個數,分配更多的內核意味着executor並發能力越強,能夠同時執行更多的task
    sc_conf.set('spark.cores.max', 40)    #spark.cores.max:為一個application分配的最大cpu核心數,如果沒有設置這個值默認為spark.deploy.defaultCores
    sc_conf.set('spark.logConf', True)    #當SparkContext啟動時,將有效的SparkConf記錄為INFO。
    print(sc_conf.getAll())

    sc = SparkContext(conf=sc_conf)

    return sc

 

 

 

from pyspark.conf import SparkConf
conf=SparkConf()
        conf.set('spark.sql.execute.arrow.enabled','true')
        if os.getenv("APP_MODE") == 'prod':
            """
            集群環境
            """
            url = 'spark://master:7077'
            conf.setAppName('prod-practice-info').setMaster(url).set("spark.driver.maxResultSize", "12g").set("spark.executor.memory", '4g')
        else:
            """
            本地環境
            """
            print("本地環境")
            url = 'local[*]'
            conf.setAppName('prod-practice-info').setMaster(url)
        spark = SparkSession.builder. \
            config(conf=conf).\
            getOrCreate()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM