0
votes

While analyzing the yarn launch_container.sh logs for a spark job, I got confused by some part of log. I will point out those asks step by step here

When you will submit a spark job with spark-submit having --pyfiles and --files on cluster mode on YARN:

  1. The config files passed in --files , executable python files passed in --pyfiles are getting uploaded into .sparkStaging directory created under user hadoop home directory. Along with these files pyspark.zip and py4j-version_number.zip from $SPARK_HOME/python/lib is also getting copied into .sparkStaging directory created under user hadoop home directory

  2. After this launch_container.sh is getting triggered by yarn and this will export all env variables required. If we have exported anything explicitly such as PYSPARK_PYTHON in .bash_profile or at the time of building the spark-submit job in a shell script or in spark_env.sh , the default value will be replaced by the value which we are providing

     This PYSPARK_PYTHON is a path in my edge node. 
     Then how a container launched in another node will be able to use this python version ?
    
     The default python version in  data nodes of my cluster is 2.7.5. 
     So without setting this pyspark_python , containers are using 2.7.5. 
     But when I will set pyspark_python to 3.5.x , they are using  what I have given.
    
  3. It is defining PWD='/data/complete-path'

     Where this PWD directory resides ? 
     This directory is getting cleaned up after job completion. 
     I have even tried to run the job in one session of putty  
     and kept the /data folder opened in another session of putty to see 
     if any directories are getting created on run time. but couldn't find any?
    
  4. It is also setting the PYTHONPATH to $PWD/pyspark.zip:$PWD/py4j-version.zip

     When ever I am doing a python specific  operation 
     in spark code , its using PYSPARK_PYTHON. So for what purpose this PYTHONPATH is being used?
    

3.After this yarn is creating softlinks using ln -sf for all the files in step 1

    soft links are created for for pyspark.zip , py4j-<version>.zip, 
    all python files mentioned in step 1.
    Now these links are again pointing to '/data/different_directories' 
    directory (which I am not sure where they are present).
    I know soft links can be used for accessing remote nodes ,
    but here why the soft links are created ?

Last but not the least , whether this launch_container.sh will run for each container launch ?

1

1 Answers

2
votes

Then how a container launched in another node will be able to use this python version ?

First of all, when we submit a Spark application, there are several ways to set the configurations for the Spark application. Such as:

  • Setting spark-defaults.conf
  • Setting environment variables
  • Setting spark-submit options (spark-submit —help and —conf)
  • Setting a custom properties file (—properties-file)
  • Setting values in code (exposed in both SparkConf and SparkContext APIs)
  • Setting Hadoop configurations (HADOOP_CONF_DIR and spark.hadoop.*)

In my environment, the Hadoop configurations are placed in /etc/spark/conf/yarn-conf/, and the spark-defaults.conf and spark-env.sh is in /etc/spark/conf/.

As the order of precedence for configurations, this is the order that Spark will use:

  1. Properties set on SparkConf or SparkContext in code
  2. Arguments passed to spark-submit, spark-shell, or pyspark at run time
  3. Properties set in /etc/spark/conf/spark-defaults.conf, a specified properties file
  4. Environment variables exported or set in scripts

So broadly speaking:

For properties that apply to all jobs, use spark-defaults.conf, for properties that are constant and specific to a single or a few applications use SparkConf or --properties-file, for properties that change between runs use command line arguments.

Now, regarding the question:

  • In Cluster mode of Spark, the Spark driver is running in container in YARN, the Spark executors are running in container in YARN.
  • In Client mode of Spark, the Spark driver is running outside of the Hadoop cluster(out of YARN), and the executors are always in YARN.

So for your question, it is mostly relative with YARN. When an application is submitted to YARN, first there will be an ApplicationMaster container, which nigotiates with NodeManager, and is responsible to control the application containers(in your case, they are Spark executors). NodeManager will then create a local temporary directory for each of the Spark executors, to prepare to launch the containers(that's why the launch_container.sh has such a name). We can find the location of the local temporary directory is set by NodeManager's ${yarn.nodemanager.local-dirs} defined in yarn-site.xml. And we can set yarn.nodemanager.delete.debug-delay-sec to 10 minutes and review the launch_container.sh script.

In my environment, the ${yarn.nodemanager.local-dirs} is /yarn/nm, so in this directory, I can find the tempory directories of Spark executor containers, they looks like: /yarn/nm/nm-local-dir/container_1603853670569_0001_01_000001. And in this directory, I can find the launch_container.sh for this specific container and other stuffs for running this container.

Where this PWD directory resides ?

I think this is a special Environment Variable in Linux OS, so better not to modify it unless you know how it works percisely in your application. As per above, if you export this PWD environment at the runtime, I think it is passed to Spark as same as any other Environment Variables.

I'm not sure how the PYSPARK_PYTHON Environment Variable is used in Spark's launch scripts chain, but here you can find the instruction in the official documentation, showing how to set Python binary executable while you are using spark-submit:

spark-submit --conf spark.pyspark.python=/<PATH>/<TO>/<FILE>

As for the last question, yes, YARN will create a temp dir for each of the containers, and the launch_container.sh is included in the dir.