본문 바로가기
Programming

[Apache Spark] Deployment

by Deafhong 2019. 3. 18.
반응형
p.s> 개인적인 공부 및 내용 정리를 위해 파파고 및 구글을 통해 번역을 한 것이므로, 틀린 번역 내용이 있을 수도 있습니다.
이점을 감안하시고, 읽어봐주세요.


스파크 애플리케이션은 스파크 서브미트를 사용하여 클러스터에 스파크 애플리케이션을 배치하는 데 사용되는 셸 명령이다. 그것은 균일한 인터페이스를 통해 모든 각 클러스터 관리자를 사용한다. 따라서, 당신은 각각의 신청서를 구성할 필요가 없다.

Example

이전에 사용했던 단어 수에 대한 동일한 예를 들어봅시다. 쉘 명령을 사용했었죠. 여기서, 우리는 스파크 적용과 같은 예를 고려한다.

Sample Input

다음 텍스트는 입력 데이터이고 이름은 in.txt이다.

people are not as beautiful as they look,
as they walk or as they talk.
they are only as beautiful  as they love,
as they care as they share.

다음 프로그램을 보라.

SparkWordCount.scala

import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark._  
object SparkWordCount {
   def main(args: Array[String]) {
      val sc = new SparkContext( "local", "Word Count", "/usr/local/spark", Nil, Map(), Map())
                
      /* local = master URL; Word Count = application name; */  
      /* /usr/local/spark = Spark Home; Nil = jars; Map = environment */
      /* Map = variables to work nodes */
      /*creating an inputRDD to read text file (in.txt) through Spark context*/
      val input = sc.textFile("in.txt")
      /* Transform the inputRDD into countRDD */
                
      val count = input.flatMap(line ⇒ line.split(" "))
      .map(word ⇒ (word, 1))
      .reduceByKey(_ + _)
       
      /* saveAsTextFile method is an action that effects on the RDD */  
      count.saveAsTextFile("outfile")
      System.out.println("OK");
   }
}

위의 프로그램을 SparkWordCount.scala라는 파일에 저장하고 스파크 애플리케이션이라는 사용자 정의 디렉토리에 저장한다.

Note − While transforming the inputRDD into countRDD, we are using flatMap() for tokenizing the lines (from text file) into words, map() method for counting the word frequency and reduceByKey() method for counting each word repetition.
Use the following steps to submit this application. Execute all steps in the spark-application directory through the terminal.
참고 - inputRDD를 countRDD로 변환하는 동안, 행을(text 파일에서) 단어로 토큰화하는 데 flatMap()를 사용하고, 단어 빈도 계산을 위해 map() 메소드를 사용하고, 각 단어 반복 계산을 위해 byKey() 메소드를 줄이고 있다.
이 신청서를 제출하려면 다음 단계를 사용하십시오. 스파크 응용 프로그램 디렉터리의 모든 단계를 터미널을 통해 실행한다.

Step 1: Download Spark Ja (  Spark Ja 다운로드 )
컴파일을 위해서는 spark core jar가 필요합니다. 그러므로 spark core jar 링크에서 spark-core_2.10-1.3.0.jar를 다운로드하고 jar 파일을 다운로드 디렉토리에서 spark-application 디렉토리로 이동하십시오.

Step 2: Compile program ( 프로그램 컴파일 )
아래 주어진 명령을 사용하여 위의 프로그램을 컴파일하십시오. 이 명령은 spark-application 디렉토리에서 실행해야합니다. 여기, /usr/local/spark/lib/spark-assembly-1.4.0-hadoop2.6.0.jar은 Spark 라이브러리에서 가져온 Hadoop 지원 jar입니다.

$ scalac -classpath "spark-core_2.10-1.3.0.jar:/usr/local/spark/lib/spark-assembly-1.4.0-hadoop2.6.0.jar" SparkPi.scala

Step 3: Create a JAR ( JAR 만들기 )
다음 명령을 사용하여 spark 응용 프로그램의 jar 파일을 만듭니다. 여기서 wordcount는 jar 파일의 파일 이름입니다.

jar -cvf wordcount.jar SparkWordCount*.class spark-core_2.10-1.3.0.jar/usr/local/spark/lib/spark-assembly-1.4.0-hadoop2.6.0.jar

Step 4: Submit spark application ( Spark 신청서 제출 )
다음 명령을 사용하여 스파크 애플리케이션을 제출하십시오 -

spark-submit --class SparkWordCount --master local wordcount.jar

성공적으로 실행되면 다음과 같은 출력이 표시됩니다. 다음 출력을 허용하는 OK는 사용자 식별을위한 것이며 프로그램의 마지막 줄입니다. 다음 출력을주의 깊게 읽으면 -
  • 포트 42954에서 'sparkDriver'서비스가 시작되었습니다.
  • MemoryStore는 용량 267.3 MB에서 시작되었습니다.
  • http://192.168.1.217:4040에서 SparkUI 시작됨
  • JAR 파일 추가 : /home/hadoop/piapplication/count.jar
  • ResultStage 1 (SparkPi.scala의 saveAsTextFile : 11)이 0.566 초에 완료되었습니다.
  • 중지 된 Spark 웹 UI http://192.168.1.217:4040
  • MemoryStore가 지워짐

15/07/08 13:56:04 INFO Slf4jLogger: Slf4jLogger started
15/07/08 13:56:04 INFO Utils: Successfully started service 'sparkDriver' on port 42954.
15/07/08 13:56:04 INFO Remoting: Remoting started; listening on addresses :[akka.tcp://sparkDriver@192.168.1.217:42954]
15/07/08 13:56:04 INFO MemoryStore: MemoryStore started with capacity 267.3 MB
15/07/08 13:56:05 INFO HttpServer: Starting HTTP Server
15/07/08 13:56:05 INFO Utils: Successfully started service 'HTTP file server' on port 56707.
15/07/08 13:56:06 INFO SparkUI: Started SparkUI at http://192.168.1.217:4040
15/07/08 13:56:07 INFO SparkContext: Added JAR file:/home/hadoop/piapplication/count.jar at http://192.168.1.217:56707/jars/count.jar with timestamp 1436343967029
15/07/08 13:56:11 INFO Executor: Adding file:/tmp/spark-45a07b83-42ed-42b3b2c2-823d8d99c5af/userFiles-df4f4c20-a368-4cdd-a2a7-39ed45eb30cf/count.jar to class loader
15/07/08 13:56:11 INFO HadoopRDD: Input split: file:/home/hadoop/piapplication/in.txt:0+54
15/07/08 13:56:12 INFO Executor: Finished task 0.0 in stage 0.0 (TID 0). 2001 bytes result sent to driver
(MapPartitionsRDD[5] at saveAsTextFile at SparkPi.scala:11), which is now runnable
15/07/08 13:56:12 INFO DAGScheduler: Submitting 1 missing tasks from ResultStage 1 (MapPartitionsRDD[5] at saveAsTextFile at SparkPi.scala:11)
15/07/08 13:56:13 INFO DAGScheduler: ResultStage 1 (saveAsTextFile at SparkPi.scala:11) finished in 0.566 s
15/07/08 13:56:13 INFO DAGScheduler: Job 0 finished: saveAsTextFile at SparkPi.scala:11, took 2.892996 s
OK
15/07/08 13:56:13 INFO SparkContext: Invoking stop() from shutdown hook
15/07/08 13:56:13 INFO SparkUI: Stopped Spark web UI at http://192.168.1.217:4040
15/07/08 13:56:13 INFO DAGScheduler: Stopping DAGScheduler
15/07/08 13:56:14 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
15/07/08 13:56:14 INFO Utils: path = /tmp/spark-45a07b83-42ed-42b3-b2c2823d8d99c5af/blockmgr-ccdda9e3-24f6-491b-b509-3d15a9e05818, already present as root for deletion.
15/07/08 13:56:14 INFO MemoryStore: MemoryStore cleared
15/07/08 13:56:14 INFO BlockManager: BlockManager stopped
15/07/08 13:56:14 INFO BlockManagerMaster: BlockManagerMaster stopped
15/07/08 13:56:14 INFO SparkContext: Successfully stopped SparkContext
15/07/08 13:56:14 INFO Utils: Shutdown hook called
15/07/08 13:56:14 INFO Utils: Deleting directory /tmp/spark-45a07b83-42ed-42b3b2c2-823d8d99c5af
15/07/08 13:56:14 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!  

Step 5: Checking output ( 출력 확인 )
프로그램이 성공적으로 실행되면 spark-application 디렉토리에 outfile이라는 디렉토리가 있습니다.
다음 명령은 outfile 디렉토리의 파일 목록 열기 및 점검에 사용됩니다.

$ cd outfile
$ ls
Part-00000 part-00001 _SUCCESS

part-00000 파일에서 출력을 검사하는 명령은 다음과 같습니다.

$ cat part-00000
(people,1)
(are,2)
(not,1)
(as,8)
(beautiful,2)
(they, 7)
(look,1)

part-00001 파일의 출력을 검사하는 명령은 다음과 같습니다.

$ cat part-00001
(walk, 1)
(or, 1)
(talk, 1)
(only, 1)
(love, 1)
(care, 1)
(share, 1)

다음 섹션을 통해 'spark-submit'명령에 대해 자세히 알아보십시오.

Spark-submit Syntax ( 스파크 제출 구문 )

spark-submit [options] <app jar | python file> [app arguments]

Options
아래 표는 옵션 목록을 설명합니다.
S.No
Option
Description
1
--master
2
--deploy-mode
Whether to launch the driver program locally ("client") or on one of the worker machines inside the cluster ("cluster") (Default: client).
3
--class
Your application's main class (for Java / Scala apps).
4
--name
A name of your application.
5
--jars
Comma-separated list of local jars to include on the driver and executor classpaths.
6
--packages
Comma-separated list of maven coordinates of jars to include on the driver and executor classpaths.
7
--repositories
Comma-separated list of additional remote repositories to search for the maven coordinates given with --packages.
8
--py-files
Comma-separated list of .zip, .egg, or .py files to place on the PYTHON PATH for Python apps.
9
--files
Comma-separated list of files to be placed in the working directory of each executor.
10
--conf (prop=val)
Arbitrary Spark configuration property.
11
--properties-file
Path to a file from which to load extra properties. If not specified, this will look for conf/spark-defaults.
12
--driver-memory
Memory for driver (e.g. 1000M, 2G) (Default: 512M).
13
--driver-java-options
Extra Java options to pass to the driver.
14
--driver-library-path
Extra library path entries to pass to the driver.
15
--driver-class-path
Extra class path entries to pass to the driver.
Note that jars added with --jars are automatically included in the classpath.
16
--executor-memory
Memory per executor (e.g. 1000M, 2G) (Default: 1G).
17
--proxy-user
User to impersonate when submitting the application.
18
--help, -h
Show this help message and exit.
19
--verbose, -v
Print additional debug output.
20
--version
Print the version of current Spark.
21
--driver-cores NUM
Cores for driver (Default: 1).
22
--supervise
If given, restarts the driver on failure.
23
--kill
If given, kills the driver specified.
24
--status
If given, requests the status of the driver specified.
25
--total-executor-cores
Total cores for all executors.
26
--executor-cores
Number of cores per executor. (Default : 1 in YARN mode, or all available cores on the worker in standalone mode).

반응형

'Programming' 카테고리의 다른 글

[Apache Spark] Advanced Spark Programming  (1) 2019.03.18
[Apache Spark] Core Programming  (0) 2019.03.18
[Apache Spark] Installation  (0) 2019.03.18
[Apache Spark] RDD  (0) 2019.03.18
[Apache Spark] - Home  (0) 2019.03.18