๐ JVM๊ณผ Python ๊ฐ์ ํต์
PySpark Driver
- Python ํ๋ก์ธ์ค + JVM ํ๋ก์ธ์ค
- ์ค์ SparkContext๋ JVM์ชฝ์์ ์์ฑํ๋ค.

PySpark Memory
-
Spark์ JVM Application์ด์ง๋ง PySpark์ Python ํ๋ก์ธ์ค์ด๋ค.
-> JVM์์ ๋ฐ๋ก ๋์ํ์ง ๋ชปํ๊ธฐ ๋๋ฌธ์ JVM ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
-
Spark.executor.pyspark.memory(Pythonํ๋ก์ธ์ค)
-
Spark.python.worker.memory(Py4J)

-
Executor์์ 2๊ฐ์ ํ๋ก์ธ์ค๊ฐ ์กด์ฌํ๋ค.
- JVM ํ๋ก์ธ์
- Python Worker
-
์ด ๋๊ฐ์ ์ค๋ธ์ ํธ Serialization/deserialization์ ํ๋ ๊ฒ์ด Py4J์ ์ญํ ์ด๋ค.
-
spark.executor.pyspark.memory
- PySpark์ ๊ธฐ๋ณธ์ ์ผ๋ก overhead memory๋ฅผ ์ฌ์ฉํ๋ค. ์ด ํ๊ฒฝ๋ณ์๊ฐ ์ฌ์ฉ๋๋ฉด PySpark์ด ์ฌ์ฉํ ์ ์๋ ๋ฉ๋ชจ๋ฆฌ๋ ์ด ํ๊ฒฝ๋ณ์์ ๊ฐ์ผ๋ก ๊ณ ์ ๋๋ค.
- ์ด๋ ์ฌ์ค PySpark์ด ์ธ๋ถ ํ์ด์ฌ ํจ์๋ฅผ ์ฐ๋ ๊ฒฝ์ฐ์๋ง ํ์ํ๋ค.(๊ธฐ๋ณธ์ ์ผ๋ก๋ ์ธํ
๋์ง ์๋๋ค.)
-
spark.python.worker.memory
- default ๊ฐ์ 512MB์ด๋ค.
- JVM๊ณผ Python ํ๋ก์ธ์ค๊ฐ์ ํต์ ์ ๋ด๋นํ๋ Py4J๊ฐ ์ฌ์ฉํ ์ ์๋ ๋ฉ๋ชจ๋ฆฌ์ ์
- ์ด ํฌ๊ธฐ๋ฅผ ๋์ด๊ฐ๋ฉด ๋์คํฌ๋ก Spill์ด ๋ฐ์ํ๋ค.
-
spark.executor.pyspark.memory๋ ํ์ด์ฌ ํ๋ก์ธ์ค์ ์ฌ์ฉ ๋ฉ๋ชจ๋ฆฌํฌ๊ธฐ๋ฅผ ๊ฒฐ์ ํ๋ค.
-
spark.python.worker.memory๋ JVM์์ ์ฌ์ฉ๋๋ Python ์ค๋ธ์ ํธ๋ค์ ์ต๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ๊ฒฐ์ ํ๋ค.
Spark๊ณผ Python๊ฐ์ ํต์
-
Py4J : Python๊ณผ JVM๊ฐ์ ๋ฐ์ดํฐ ๊ตํ์ ํตํด ๋๊ฐ์ ์ฐ๋์ ๋์์ฃผ๋ ํ๋ ์์ํฌ
-
DataFrame/RDD ์ฐ์ฐ์ค์ Python ์ฝ๋๊ฐ ์ฌ์ฉ๋๋ค๋ฉด?
-> ์ด๋ ๋ณ๋์ Python ํ๋ก์ธ์ค๋ฅผ ํตํด ์คํ๋๋ฉฐ ์ด ๊ฒฝ์ฐ ํํฐ์
๋ฐ์ดํฐ๊ฐ ๋ชจ๋ ๋์ด๊ฐ๋ค.
df.select("foo", "bar").where(df["foo" > 100).count()
vs.
from operator import add
t = spark.sparkContext.parallelize(range(len))
a = t.reduce(add)
- ๋๋ผ์ด๋ฒ์์ ์์ Pythonํ๋ก์ธ์ค์์ ์คํํ ์ฝ๋์ ๊ธฐํ ๋ฐ์ดํฐ๋ฅผ serializeํด์ Executor์ ์ ์กํ๋ค.
- JVM executor๋ Python ํ๋ก์ธ์ค๋ฅผ ์คํํ๋ค.(PySpark Script)
- Executor๋ ์ด๊ฒ๊ณผ Partition์ Serializeํ๊ณ ์์์ ๋ฐ์ ์ฝ๋์ ํจ๊ป Python ํ๋ก์ธ์ค๋ก ์ ์กํ๋ค.
- Python ํ๋ก์ธ์ค์์ ๊ณ์ฐ์ด ๋๋๋ฉด ๊ฒฐ๊ณผ๊ฐ ๋ค์ Executor๋ก Serialize๋์ด์ ์ ์ก๋๋ค.