Spark-Submit์ด๋?
Spark job์ ๋ฐฐ์น ํน์ ์คํธ๋ฆฌ๋ฐ ํํ๋ก ์คํํ๊ธฐ ์ํ ๊ณต์ CLI ๋ฐ์ฒ๋ก notebook์ด๋ spark-shell๊ณผ ํจ๊ป Spark job์ ์คํํ ์ ์๋ ๋ฐฉ๋ฒ ์ค ํ๋
Spark์์ ์ง์ํ๋ ๋ชจ๋ cluster manager๋ฅผ ๋์ผํ ์ธํฐํ์ด์ค๋ฅผ ํตํด ์ฌ์ฉํ ์ ์์ด์ ์ ์ฉ
๋์์๋ฆฌ
- ์ฌ์ฉ์๊ฐ ๋ช
๋ น์ด ์
๋ ฅ โ
spark-submit
์คํฌ๋ฆฝํธ๊ฐ ํ๊ฒฝ ๋ณ์ยทํด๋์คํจ์ค ์ธํ ํ JVM ๋ถํธ์คํธ๋ฉ SparkSubmit
ํด๋์ค๊ฐ ์ ๋ฌ ํ๋ผ๋ฏธํฐ ํ์ฑ โ ๋ฐฐํฌ ๋ชจ๋(client/cluster)ยทํด๋ฌ์คํฐ ๋งค๋์ ์ ๋ง๋ LauncherBackend ์ ํ- Driver JVM ๊ธฐ๋ โ Cluster Manager ์ ํต์ ํด Executor ๋์ฐ๊ณ ํ์คํฌ ์ค์ผ์ค
- Job ์ข ๋ฃ ์ ExitCode ๋ฐํ โ ์ ธ ์คํฌ๋ฆฝํธ๊ฐ ๊ทธ๋๋ก ์ ๋ฌํด ํ์ดํ๋ผ์ธ ์คํจ ๊ฐ์ง ๊ฐ๋ฅ
notebook ยท shell ๋๋น ํน์ง
- notebook / shell โ REPL ์ธํฐ๋ํฐ๋ธ ์ธ์ , ์ฌ์ฉ์ ์ ๋ ฅ์ด ๋๊ธฐ๋ฉด ์ข ๋ฃ
- spark-submit โ ์คํฌ๋ฆฝํธยท์ํฌํ๋ก ์์ง(airflow, azkaban ๋ฑ)์์ ํธ์ถํด ๋น๋ํ์ ์คํ
- ๋ฆฌ์์คยท์ต์ ์ผ๊ด์ฑ ํ๋ณด, CI/CD ํฌํจ ์๋ํ์ ์ ๋ฆฌ
๊ธฐ๋ณธ ๊ตฌ์กฐ
spark-submit ๋ช ๋ น์ด
spark-submit \
--master <url|mode> \
--deploy-mode <client|cluster> \
--name <appโname> \
--class <main-class> \
--conf k=v (์ฌ๋ฌ ๋ฒ ์ฌ์ฉ ๊ฐ๋ฅ) \
--packages g:a:v (์ฌ๋ฌ ๋ฒ ์ฌ์ฉ ๊ฐ๋ฅ) \
--jars a.jar,b.jar (์ฝค๋ง ๊ตฌ๋ถ) \
--py-files deps.zip (PySpark) \
--files config.json (๋ชจ๋ ๋
ธ๋๋ก ๋ฐฐํฌ) \
--executor-memory 4g \
--executor-cores 2 \
--num-executors 5 \
--driver-cores 4 \
--driver-memory 2g \
<application file> (py ํ์ผยทJARยทR file) \
[application args]
๋ํ์ ์ธ ์ต์
--class
: JAR ํ์ผ ์์์ ์ด๋ค Main ํด๋์ค (main ๋ฉ์๋ ๊ฐ์ง ์ํธ๋ฆฌํฌ์ธํธ)๋ฅผ ์คํํ ์ง spark-submit ์๊ฒ ์๋ ค์ฃผ๋ ์ค์์น- ํ๋์ JAR ์์ ์ฌ๋ฌ main ํด๋์ค ํฌํจ๋์ด ์๋ ๋ฑ ์ด๋ ๊ฒ ์คํํด์ผํ ์ง ์ ๋งคํ ๊ฒฝ์ฐ ํ์
- Java, Scala ๊ธฐ๋ฐ Spark ์ ํ๋ฆฌ์ผ์ด์ ์๋ง ์๋ฏธ์์
--master
: cluster์ master URL- local : ๋จ์ผ worker thread ์ฌ์ฉ (no parallelism)
- local[K] : K worker threads
- local[K, F]: K worker threads์ F๋ฒ์ maxFailure1
- local[*] : ์ต๋ํ ๋ง์ worker threads
- local[*, F] : ์ต๋ํ ๋ง์ worker threads์ F๋ฒ์ maxFailure
- local-cluster[N, C, M] : ๋จ์ผ JVM์์ N๊ฐ์ worker, C cores per worker, M MiB ๋ฉ๋ชจ๋ฆฌ per worker. unit test์ฉ local cluster mode
- spark://HOST:PORT : Standalone cluster master์ ์ฐ๊ฒฐ. 7077์ด default
- spark://HOST1:PORT1,HOST2:PORT2 : Zookeeper ์ฌ์ฉํด์ ๋๊ธฐ master๊ฐ ์๋ standalone cluster์ ์ฐ๊ฒฐ
- yarn : client ํน์ cluster ๋ชจ๋๋ก YARN ํด๋ฌ์คํฐ์ ์ฐ๊ฒฐ. cluster location ํ๊ฒฝ๋ณ์๋ก ์ฃผ์ ํ์
- k8s://HOST:PORT : client ํน์ cluster ๋ชจ๋๋ก k8s cluster์ ์ฐ๊ฒฐ
--deploy-mode
: Spark Driver๋ฅผ worker node์ ๋ฐฐํฌํ ์ง (cluster) ์๋ ์ธ๋ถ client์ ๋ฐฐํฌํ ์ง (client, ๊ธฐ๋ณธ๊ฐ)--conf
: key=value ํํ์ spark configuration. ์ฌ๋ฌ๊ฐ๋ฅผ ๋ฐ๋ณตํด์ ์ ๋ ฅ ๊ฐ๋ฅ- spark.app.name=name : ์ฑ ์ด๋ฆ ์ค๋ฒ๋ผ์ด๋
- spark.sql.shuffle.partitions=200ย : ์ ํ ํํฐ์
- spark.hadoop.fs.s3a.access.key=โฆย : S3ย ์๊ฒฉ ์ฃผ์
- spark.driver.extraJavaOptions=-Duser.name=airflowย : ์ปจํ ์ด๋ HOMEย ๋ฌธ์ ํด๊ฒฐ
- spark.ui.port=4041ย : UIย ํฌํธ ์ถฉ๋ ์ ๋ณ๊ฒฝ
- application-jar : application๊ณผ ๋ชจ๋ dependency๋ฅผ ํฌํจํ bundled jar์ path (์์ :
hdfs://path
orfile:// path
) - application-arguments : ์คํ ์คํฌ๋ฆฝํธ์ ํ์ํ ์ธ์
๊ธฐํ ์ต์
--executor-memory
ย : Executorย JVMย Heap (์โฏ4g
,ย512m
)--executor-cores
ย : Executorโฏ๋น CPUย ์ฝ์ด ์--num-executors
ย : Executor ๊ฐ์ (StandโaloneยทYARN)--driver-memory
ย : Driverย Heap--total-executor-cores
ย : Mesos ์ ์ฉ ์ด ์ฝ์ด ์--jars
ย ย : ์ถ๊ฐ JARย classpath--packages
ย : Mavenย Centralย Ivy ๋ค์ด๋ก๋--repositories
ย : ์ฌ์ค Mavenย ์ ์ฅ์ URL--py-files
ย : PySpark ์์กด zip/egg--files
ย : ๋ชจ๋ ๋ ธ๋์ ํ์ผ ๋ฐฐํฌ ํยSparkFiles.get()
ย ๋ก ์ ๊ทผ
์์ ์คํฌ๋ฆฝํธ
# Run application locally on 8 cores
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master "local[8]" \
/path/to/examples.jar \
100
# Run on a Spark standalone cluster in client deploy mode
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--executor-memory 20G \
--total-executor-cores 100 \
/path/to/examples.jar \
1000
# Run on a Spark standalone cluster in cluster deploy mode with supervise
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--deploy-mode cluster \
--supervise \
--executor-memory 20G \
--total-executor-cores 100 \
/path/to/examples.jar \
1000
# Run on a YARN cluster in cluster deploy mode
export HADOOP_CONF_DIR=XXX
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
--deploy-mode cluster \
--executor-memory 20G \
--num-executors 50 \
/path/to/examples.jar \
1000
# Run a Python application on a Spark standalone cluster
./bin/spark-submit \
--master spark://207.184.161.138:7077 \
examples/src/main/python/pi.py \
1000
# Run on a Kubernetes cluster in cluster deploy mode
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master k8s://xx.yy.zz.ww:443 \
--deploy-mode cluster \
--executor-memory 20G \
--num-executors 50 \
http://path/to/examples.jar \
1000
Footnotes
-
Number of continuous failures of any particular task before giving up on the job โฉ