Cài đặt và Lấy Cấu Hình Spark

Cài đặt Cấu hình Spark

Phương pháp 1: Xác định cấu hình Spark khi tạo SparkSession thông qua .config

pythonSao chép mãspark = SparkSession \
          .builder \
          .appName("SparkExample") \
          .config("spark.sql.warehouse.dir", "/user/hive/warehouse") \
          .getOrCreate()

Nếu bạn cần thiết lập nhiều cấu hình, bạn có thể định nghĩa chúng trong một từ điển hoặc trong tệp yaml và thiết lập tương ứng thông qua một vòng lặp.

pythonSao chép mãspark = SparkSession \
          .builder \
          .appName("SparkExample") \

custom_spark_config = {
    "spark.driver.memory": "9g",
    "spark.executor.cores": "2",
    "spark.executor.memory": "9g",
    "spark.yarn.queue": "root.tnm.ada_analytics_tnm", # cần cập nhật với tên Queue YARN
}

# Vòng lặp để thiết lập từng cấu hình Spark trong từ điển
for key, value in custom_spark_config.items():
    spark = spark.config(key, value)

spark = spark.getOrCreate()  # tạo phiên Spark với các cấu hình đã chỉ định

Phương pháp 2: Để thiết lập cấu hình Spark sau khi đối tượng SparkSession đã được tạo

pythonSao chép mã# trong trường hợp này, chúng ta có "spark" là đối tượng SparkSession đã tạo
spark.conf.set("spark.sql.shuffle.partitions", "200")

Phương pháp 3: Xác định cấu hình Spark trong lệnh spark-submit, vì hai phương pháp trên được cố định và khá tĩnh, và bạn muốn có các tham số khác nhau cho các công việc khác nhau.

bashSao chép mãspark-submit --executor-memory 16G

Lấy Cấu hình Spark

pythonSao chép mãspark.conf.get("spark.executor.memory") # để kiểm tra cấu hình Spark xem nó được thiết lập đúng không

Danh sách các cấu hình

spark.memory

  • (“spark.memory.offHeap.enabled”,”true”): Nếu là true, dữ liệu được lưu trữ trong bộ nhớ off-heap để tránh lưu trữ trực tiếp trên đĩa.
  • (“spark.memory.offHeap.size”,”10g”): Bạn cũng có thể xác định kích thước bộ nhớ off-heap.

spark.sql

  • (“spark.sql.shuffle.partitions”, “200”): Để thiết lập số lượng phân vùng đầu ra từ shuffle (mặc định là 200). Thử nghiệm với các giá trị khác nhau, bạn sẽ thấy thời gian chạy khác biệt đáng kể.
  • (“spark.sql.warehouse.dir”, “/user/hive/warehouse”): Thuộc tính cấu hình này chỉ định vị trí mặc định mà Spark SQL sẽ lưu trữ bảng được quản lý trong thư mục kho dữ liệu của Hive.

162 thoughts on “Cài đặt và Lấy Cấu Hình Spark

  1. Hey would you mind stating which blog platform you’re using?

    I’m planning to start my own blog in the near future
    but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your design and style seems
    different then most blogs and I’m looking for something unique.
    P.S Apologies for being off-topic but I had to ask!

  2. В данной обзорной статье представлены интригующие факты, которые не оставят вас равнодушными. Мы критикуем и анализируем события, которые изменили наше восприятие мира. Узнайте, что стоит за новыми открытиями и как они могут изменить ваше восприятие реальности.
    Исследовать вопрос подробнее – https://medalkoblog.ru/

  3. ¡Saludos, aventureros de emociones !
    Juegos mГЎs rentables en casinos online extranjeros – п»їhttps://casinoextranjerosenespana.es/ mejores casinos online extranjeros
    ¡Que disfrutes de jackpots impresionantes!

  4. ¡Bienvenidos, aventureros del desafío !
    Casino online fuera de EspaГ±a sin presiГіn fiscal – п»їhttps://casinoporfuera.guru/ casino por fuera
    ¡Que disfrutes de maravillosas momentos memorables !

  5. Keep your garage door running smoothly with FixingOTX Garage Door Maintenance. Our expert technicians provide thorough inspections, lubrication, and adjustment services to ensure safe, reliable performance year-round. Prevent costly repairs with regular maintenance. Whether it’s a quick fix or full service, we have you covered. Trust FixingOTX for all your garage door needs.

  6. ¡Hola, amantes del ocio y la emoción !
    Casinos sin licencia que aceptan Skrill y Neteller – п»їhttps://casinosinlicenciaespana.xyz/ casinos sin licencia espaГ±a
    ¡Que vivas increíbles instantes únicos !

  7. Greetings, enthusiasts of clever wordplay !
    Short jokes for adults to copy & paste – п»їhttps://jokesforadults.guru/ top 5 hilarious jokes for adults
    May you enjoy incredible unique witticisms !

  8. Hello discoverers of fresh clarity !
    Invest in the best smoke air purifier for cleaner air after cooking or smoking. These models excel in removing fine particles and strong smells. A best smoke air purifier option is also energy-efficient.
    If your living conditions involve frequent indoor smoking, an air purifier for smokers is essential.best air filter for smokeIt keeps the environment safer for everyone present. The right air purifier for smokers is designed for durability and ease of use.
    Air purifier smoking area solution for home – п»їhttps://www.youtube.com/watch?v=fJrxQEd44JM
    May you delight in extraordinary remarkable freshness !

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *