Spark Documentation 문서 번역을 한 번 해보려고 한다.

눈가락번역기의 번역 상태가 많이 좋지 않으니 양해 바람.

 

 

 

번역 대상 문서 : https://spark.apache.org/docs/latest/spark-connect-overview.html

 

Spark Connect Overview
Spark Connect 개요

Building client-side Spark applications
client-side Spark 어플리케이션 구축하기

In Apache Spark 3.4, Spark Connect introduced a decoupled client-server architecture that allows remote connectivity to Spark clusters using the DataFrame API and unresolved logical plans as the protocol.
Apache Spark 3.4 에서, Spark Connect 는 DataFrame API 및 해결되지 않은 논리적 계획(???) 을 프로토콜로 이용하여 Spark clusters 에 원격으로 연결 가능하도록 비결합된 client-server 구조를 제안한다. 

The separation between client and server allows Spark and its open ecosystem to be leveraged from everywhere.

Client 와 Server 의 분리는 Spark 와 Spark 의 Ecosystem 들이 어디서든 활용될 수 있도록 한다.

It can be embedded in modern data applications, in IDEs, Notebooks and programming languages.

Spark Connect 는 data applications, IDEs, 주피터 노트북, 그리고 Programming Lang 에 내장될 수 있다.

To get started, see Quickstart: Spark Connect.

시작하려면 Quickstart: Spark Connect 문서를 확인하라.

 

How Spark Connect works
Spark Connect 가 동작하는 방식

The Spark Connect client library is designed to simplify Spark application development.
Spark Connect client lib 는 Spark Application 개발을 간단하게 만들도록 디자인되었다.

It is a thin API that can be embedded everywhere: in application servers, IDEs, notebooks, and programming languages.
Application Servers, IDEs, 주피터 노트북, Programming Lang 등 어디에든 내장될 수 있는 가벼운 API 이다.

The Spark Connect API builds on Spark’s DataFrame API using unresolved logical plans as a language-agnostic protocol between the client and the Spark driver.
Spark Connect API 는 client 와 Spark driver 간 언어의 장벽이 없는 프로토콜로, 미해결된 논리적 계획들(??) 을 사용한 Spark 의 Data Frame API 을 기반으로 구축된다. 뭔 소리야.... 

The Spark Connect client translates DataFrame operations into unresolved logical query plans which are encoded using protocol buffers.

Spark Connect client 는 DataFrame 의 동작을 미해결된 논리적 query 계획들로 변형하며, 그 계획들은 protocol buffers 를 이용하여 인코딩된다.

These are sent to the server using the gRPC framework.

그리고 인코딩 된 정보들은 gRPC framework 를 이용하여 server 로 보내진다.

The Spark Connect endpoint embedded on the Spark Server receives and translates unresolved logical plans into Spark’s logical plan operators.

Spark Server 에 내장된 Spark Connect endpoint 는 그것을 받고, 받은 미해결된 논리 계획들을 동작가능한 Spark 의 논리적 계획으로 변형한다.

This is similar to parsing a SQL query, where attributes and relations are parsed and an initial parse plan is built.

이것은 SQL 쿼리를 파싱하는 것과 비슷하다. 마치 attributes 와 relations 가 파싱되고 초기 파싱 계획이 구축되는 것처럼...(??)

From there, the standard Spark execution process kicks in, ensuring that Spark Connect leverages all of Spark’s optimizations and enhancements.

일반적인 Spark 실행 프로세스가 시작되며, Spark Connect 가 모든 Spark 의 최적화 전략과 향상된 기능들을 활용할 수 있도록 보장한다.

Results are streamed back to the client through gRPC as Apache Arrow-encoded row batches.

그 결과는 gRPC-Arrow 의 row 배치를 통해 client 에 다시 스트림으로 되돌아간다.

 

Operational benefits of Spark Connect
Spark Connect 의 실행시 얻는 장점

With this new architecture, Spark Connect mitigates several multi-tenant operational issues:

새로운 architecture인 Spark Connect 는 몇몇 multi-tenant 실행 이슈들을 완화해준다.

Stability: Applications that use too much memory will now only impact their own environment as they can run in their own processes.

안정성 : applications 이 메모리를 많이 사용하는 것은 그 applications 프로세스들을 실행하는 그 환경에만 영향을 준다.

Users can define their own dependencies on the client and don’t need to worry about potential conflicts with the Spark driver.
사용자들은 client 단에서 그들 자신의 의존성들을 정의할 수 있으며, Spark driver 로 인한 잠재적인 결함에 대해 걱정하지 않아도 된다.

Upgradability: The Spark driver can now seamlessly be upgraded independently of applications, for example to benefit from performance improvements and security fixes.

업그레이드 능력 : Spark driver 는 applications 에 상관없이 독립적으로, 그리고 downtime 없이 업그레이드가 가능하다. 예를 들어 퍼포먼스 향상과 시큐리티 보완의 장점을 가져갈 수 있다.

This means applications can be forward-compatible, as long as the server-side RPC definitions are designed to be backwards compatible.

이것은, 서버 측 RPC 정의가 역방향 호환성을 갖도록 설계되어 있다면, applications 가 순방향 호환이 될 수 있다는 것을 의미한다.

Debuggability and observability: Spark Connect enables interactive debugging during development directly from your favorite IDE.

디버깅 능력과 모니터링 능력 : Spark Connect 는 사용자가 어느 IDE 에서 개발을 진행하든, 상호보완적 디버깅 기능을 제공한다.

Similarly, applications can be monitored using the application’s framework native metrics and logging libraries.

이와 비슷하게, applications 는 applications 의 framework 기본 메트릭과 로깅 lib 를 이용하여 모니터링 가능하다.

How to use Spark Connect
Spark Connect 사용법

Starting with Spark 3.4, Spark Connect is available and supports PySpark and Scala applications.
Spark 3.4 부터, Spark Connect 는 PySpark 와 Scala applications 에서 사용 가능하다.

We will walk through how to run an Apache Spark server with Spark Connect and connect to it from a client application using the Spark Connect client library.

Spark Connect 를 이용하여 Apache Spark 서버를 실행하는 방법과, Spark Connect Client Lib 를 이용하여 Client Application 으로부터 Spark 서버에 연결하는 방법을 연습해보겠다.

Download and start Spark server with Spark Connect
Spark Connect 를 이용하여 Spark server 실행하기

First, download Spark from the Download Apache Spark page.

먼저 Download Apache Spark 페이지에서 Spark를 다운받는다. 

Spark Connect was introduced in Apache Spark version 3.4 so make sure you choose 3.4.0 or newer in the release drop down at the top of the page.

Spark Connect 는 Apache Spark 3.4 이후부터 제공되기 때문에, 페이지 꼭대기에 drop down 메뉴에서 3.4.0 이상 버전을 선택해야 한다.

Then choose your package type, typically “Pre-built for Apache Hadoop 3.3 and later”, and click the link to download.

그리고 package type 을 선택한다. 일반적으로 “Pre-built for Apache Hadoop 3.3 and later” 을 선택하며,, 이것을 클릭하고 다운로드한다.

Now extract the Spark package you just downloaded on your computer, for example:

그리고 컴퓨터에 다운받은 Spark package 를 아래 명령어로 압축 해제한다.

tar -xvf spark-3.4.0-bin-hadoop3.tgz

In a terminal window, go to the spark folder in the location where you extracted Spark before and run the start-connect-server.sh script to start Spark server with Spark Connect, like in this example:

터미널 창에서 방금 압축 해제한 위치로 이동한 후, Spark Connect 와 함께 Spark Server 를 실행하기 위해 start-connect-server.sh 스크립트를 실행해라.

./sbin/start-connect-server.sh --packages org.apache.spark:spark-connect_2.12:3.4.0

Note that we include a Spark Connect package (spark-connect_2.12:3.4.0), when starting Spark server.

Spark Server 가 시작할 때, Spark Connect 패키지가 포함되도록 하자.

This is required to use Spark Connect.

그것은 Spark Connect 를 사용하기 위한 조건이다.

Make sure to use the same version of the package as the Spark version you downloaded previously.

다운받은 Spark 와 같은 버전의 Spark Connect package 를 사용해야 한다.

In this example, Spark 3.4.0 with Scala 2.12.

위의 예에서는 Spark 3.4.0 + Scala 2.12 와 같은 버전의 package 를 사용하면 된다.

Now Spark server is running and ready to accept Spark Connect sessions from client applications.

이제 Spark server 가 실행되고, Client Applications 로부터 Spark Connect Session 을 맺을 준비가 되었다.

In the next section we will walk through how to use Spark Connect when writing client applications.

다음 단계에서, Client Applications 을 작성할 때 Spark Connect 를 어떻게 사용하는지 연습해보자.

Use Spark Connect in client applications
Client Applications 에서 Spark Connect 사용하기

When creating a Spark session, you can specify that you want to use Spark Connect and there are a few ways to do that outlined as follows.

Spark 세션을 생성할 때, Spark Connect 를 사용하도록 구성할 수 있으며, 이를 위한 몇 가지 방법이 있다.

If you do not use one of the mechanisms outlined here, your Spark session will work just like before, without leveraging Spark Connect, and your application code will run on the Spark driver node.

만약 다음의 방법을 사용하지 않는다면, Spark Session 은 Spark Connect 활용 없이 이전과 동일하게 동작 할 것이며, Application 코드는 Spark Driver 노드에서 동작 할 것이다.

Set SPARK_REMOTE environment variable
SPARK_REMOTE 환경 변수 설정

If you set the SPARK_REMOTE environment variable on the client machine where your Spark client application is running and create a new Spark Session as in the following example, the session will be a Spark Connect session.

만약 Spark Client Application 이 동작중인 client 컴퓨터의 SPARK_REMOTE 환경 변수가 설정되고 다음과 같은 예제로 새로운 Spark Session 이 생성되면, Session 은 Spark Connect Session 이 된다.

With this approach, there is no code change needed to start using Spark Connect.

이러한 방법으로, Spark connect 를 사용하기 위해 코드를 변경하는 일은 불필요하게 된다.

In a terminal window, set the SPARK_REMOTE environment variable to point to the local Spark server you started previously on your computer:

터미널 창에서, SPARK_REMOTE 환경 변수를 local spark server 를 바라보도록 설정하라.

여기서 local spark server 란, 위에서 미리 실행해두었던 Spark server 를 의미한다.

export SPARK_REMOTE="sc://localhost"

And start the Spark shell as usual:

그리고 Spark Shell 을 실행하라.

./bin/pyspark

The PySpark shell is now connected to Spark using Spark Connect as indicated in the welcome message:
PySpark shell 은 환영 메세지에서 볼 수 있듯이, Spark Connect 를 이용하여 Spark 에 연결되었다.

Client connected to the Spark Connect server at localhost

And if you write your own program, create a Spark session as shown in this example:
프로그램 코드를 작성할 때 아래 예제처럼 Spark Session 을 생성하라.

from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()

This will create a Spark Connect session from your application by reading the SPARK_REMOTE environment variable we set previously.

이것은 미리 설정해 둔 SPARK_REMOTE 환경 변수를 읽고 Spark Connect Session 을 생성 할 것이다.

Specify Spark Connect when creating Spark session
Spark Session 을 생성할 때 Spark Connect 특정짓기

You can also specify that you want to use Spark Connect explicitly when you create a Spark session.
Spark Session 을 생성할 때, 명시적으로 Spark Connect 를 사용하도록 특정지을 수 있다.

For example, you can launch the PySpark shell with Spark Connect as illustrated here.
예를 들어, 다음 설명과 같이 Spark Connect 와 함께 PySpark shell 을 실행할 수 있다.

To launch the PySpark shell with Spark Connect, simply include the remote parameter and specify the location of your Spark server.
Spark Connect 를 사용하는 PySpark Shell 을 실행하기 위해, remote 파라미터와 특정 Spark server 위치를 넣어라.

We are using localhost in this example to connect to the local Spark server we started previously:
앞서 실행해 둔 local Spark Server 에 연결하는 현 예제를 계속 이어간다면, localhost 를 파라미터 값으로 넣으면 된다.

./bin/pyspark --remote "sc://localhost"

And you will notice that the PySpark shell welcome message tells you that you have connected to Spark using Spark Connect:
그러면 PySpark Shell 의 환영 메세지를 볼 수 있고, 이는 Spark Connect 를 이용하여 Spark 에 연결되었다는 것을 의미한다.

Client connected to the Spark Connect server at localhost

You can also check the Spark session type.
또한 Spark Session type 을 확인해 볼 수 있다.

If it includes .connect. you are using Spark Connect as shown in this example:
만약 아래와 같이 type 에 ".connect." 가 포함되어있다면, Spark Connect 를 사용중인 것이다.

SparkSession available as 'spark'.
>>> type(spark)
<class 'pyspark.sql.connect.session.SparkSession'>

Now you can run PySpark code in the shell to see Spark Connect in action:
이제 PySpark 코드를 shell 에서 실행해보자. Spark Connect 가 사용되는 것을 볼 수 있다.

>>> columns = ["id","name"]
>>> data = [(1,"Sarah"),(2,"Maria")]
>>> df = spark.createDataFrame(data).toDF(*columns)
>>> df.show()
+---+-----+
| id| name|
+---+-----+
|  1|Sarah|
|  2|Maria|
+---+-----+

Or, when writing your own code, include the remote function with a reference to your Spark server when you create a Spark session, as in this example:
혹은, 프로그램 코드를 작성할 때, Spark Session 을 생성할 때 Spark Server 정보와 함께 remote 함수를 추가해라.

from pyspark.sql import SparkSession
spark = SparkSession.builder.remote("sc://localhost").getOrCreate()

What is supported in Spark 3.4
Spark 3.4 에서 지원하는 것

PySpark: In Spark 3.4, Spark Connect supports most PySpark APIs, including DataFrame, Functions, and Column.
PySpark : Spark 3.4 에서, Spark Connect 는 DataFrame, Functions, Column 을 포함한 대부분의 PySpark API 들을 지원한다.

However, some APIs such as SparkContext and RDD are not supported.

그렇지만, SparkContext 나 RDD 같은 몇몇 API 는 지원하지 않는다.

You can check which APIs are currently supported in the API reference documentation.

API 참고 문서에서 현재 지원중인 API 인지 아닌지 확인할 수 있다.

Supported APIs are labeled “Supports Spark Connect” so you can check whether the APIs you are using are available before migrating existing code to Spark Connect.

지원되는 API 는 "Supports Spark Connect" 이라는 라벨이 붙어있어서, 현재 스파크 코드를 Spark Connect 를 사용하도록 옮기는 작업을 하기 전에 미리 어떤 API 들이 사용 가능한지 확인할 수 있다.

Scala: In Spark 3.4, Spark Connect supports most Scala APIs, including Dataset, functions, and Column.

Support for more APIs is planned for upcoming Spark releases.

Scala : Spark 3.4 에서, Spark Connect 는 DataSet, functions, Column 등 대부분의 Scala API 들을 지원한다.

더 많은 API 를 지원 할 계획이며, 다가오는 Spark releases 에서 발표될 예정.

 

 

 

 

 

 

 

 

 

 

 

 

 

+ Recent posts