SlideShare a Scribd company logo
1 of 63
Spark Streaming
2017. 8
김민호
Spark Intro
Spark Intro
• In-memory 기반 범용 클러스터 컴퓨팅 엔진
- 하둡 맵리듀스보다 100배 빠름(공홈에서 주장)
• Unified Engine
- batch/stream, SQL 및 Machine learning, Graph processing 제공
• 다양한 언어 지원
- Java, Scala, Python, R
• 여러 클러스터 매니저를 지원하여 다양한 환경에서 구동 가능
- Standalone, YARN, mesos 등
Spark Philosophy
• Unified engine
• High-level APIs
• Integrate broadly
Spark trends
Spark Streaming
Why spark streaming?
Why Spark Streaming?
데이터를 실시간으로 바로 처리 하고 싶어요
“웹사이트를 모니터링할 수 없을까요?”
“이거 추가되거나 삭제되면 바로 반영해주세요”
“실시간 데이터로 머신러닝 모델을 학습시키고 싶어요”
“문제를 바로 알고 싶어요”
Website monitoring Fraud detection ML from streaming data
Why Spark Streaming?
• Integration with Batch Processing
같은 프레임워크에서 배치와 스트리밍을 같이 처리하고 싶어요
“배치는 MapReduce, 스트리밍은 Storm…”
“유지 보수가 너무 어려워요 ㅠㅠ”
“배치를 쉽게 스트리밍으로 바꿀수 없을까요?”
Why Spark Streaming?
• Integration with Batch Processing
같은 프레임워크에서 배치와 스트리밍을 같이 처리하고 싶어요
“배치는 MapReduce, 스트리밍은 Storm…”
“유지 보수가 너무 어려워요 ㅠㅠ”
“배치를 쉽게 스트리밍으로 바꿀수 없을까요?”
What is spark streaming?
What is Spark Streaming?
• 배치를 작게해서 스트리밍처럼 돌리자
- 스트림 데이터를 시간 간격으로 분할
- 분할된 데이터를 대상으로 배치 수행
- 각 배치는 기존의 Spark job과 동일하게 처리
Spark
Streaming
live data stream
batches of input data
Spark
Engine
processed result
RDD
Streaming Context
• Spark streaming을 사용하기 위해서 제일 먼저 생성하는 인스
턴스
- SparkContext, SparkSession과 비슷
• 어떤 주기로 배치 처리를 수행할지에 대한 정보를 함께 제공
• SparkConf나 SparkContext를 이용해 생성
Programming Model - DStream
• Discretized Stream(Dstream)
- 끊임없이 생성되는 연속된 데이터를 나타내기 위한 데이터 모델
- 일정 시간마다 데이터를 모아서 RDD를 만들어줌
- RDD로 구성된 시퀀스
Reference : zero-to-streaming-spark-and-cassandra
그림과 함께 보는 예제
Spark
Streaming
live data stream
batches of input data
Spark
Engine
processed result
그림과 함께 보는 예제
Spark
Streaming
live data stream
batches of input data
Spark
Engine
processed result
How to use?
Example – Twitter 데이터와 놀아보기
• 살펴볼 예제
- 초당 생성되는 트윗 수 세어보기
- 최근 10초동안 생성되는 트윗 중 가장 많이 사용되는 단어수를 매 초마
다 확인하기
- 지금부터 유저별 트위터 작성 수 집계하기
예제 저장소 : https://github.com/eoriented/spark-streaming-tutorial
예제 저장소
• https://github.com/eoriented/spark-streaming-tutorial
Star 버튼을 눌러주시
면 호랑이 기운이 솟아
나요!!
Tutorial - 1
• 초당 생성되는 트윗 수 세기
- Twitter API Credential 발급 받기
• https://apps.twitter.com/
• 위 홈페이지에서 Twitter API를 사용할 수 있는 토큰들을 발급 받을 수 있음
Tutorial - 1
• 초당 생성되는 트윗 수 세기
Tutorial - 2
- 최근 10초동안 많이 사용되는 단어수를 매 초마다 확인하기
• 예제를 살펴 보기 전에 Window 개념 익히기
Tutorial - 2
- 최근 10초동안 많이 사용되는 단어수를 매 초마다 확인하기
• 예제를 살펴 보기 전에 Window 개념 익히기
Window-based Transformations
• 이전에 수행된 배치의 결과를 반영해서 사용하는 경우 사용
Tutorial - 2
- 최근 10초동안 사용되는 단어수를 매 초마다 확인하기
Tutorial - 3
- 지금부터 생성되는 유저별 트위터 작성 수 집계하기
Tutorial - 3
- 지금부터 생성되는 유저별 트위터 작성 수 집계하기
• 스트리밍에서는 매번 새로운 데이터를 대상으로 집계를 수행
• 이전에 처리했던 결과를 반영하기 위해서 stateful 방식의 집계를 제공
Tutorial - 3
- 지금부터 생성되는 유저별 트위터 작성 수 집계하기
실제 업무에 적용하려면?
Data source
• 지원하는 데이터 소스
- Default data source
• Socket
• 파일 (HDFS 호환 파일 가능)
• RDD Queue
- Advanced data source (외부 연동 라이브러리)
• Kafka
• Flume
• Kinesis
• Twitter
- Receiver를 직접 구현
Data source
• Custom Receiver
- 만일 내가 원하는 Data source가 존재하지 않는다면?
• Custom Receiver로 구현
- http://spark.apache.org/docs/latest/streaming-custom-receivers.html
- onStart 메소드와 onStop 메소드를 구현
24/7
그럼 운영은?
Fault tolerance
• Check Point
- Metadata checkpoint
• 드라이버의 장애 대응
- Data checkpoint
• 최종 상태의 데이터를 빠르게 복구하기 위한 용도
- 파일 시스템
• HDFS, S3, local FS(test용) 등이 사용 가능
성능 고려사항
• 배치 / 윈도우 사이즈
- 500ms 가 적당
- 큰 배치로 시작하여 작은 사이즈로 낮춰가면서 배치 사이즈 결정 추천
• 병렬화
- 리시버 개수 늘리기
• 하나의 리시버가 받는게 아닌 여러 리시버가 받아서 처리하는게 효율적
- Repartitioning
• 입력 스트림의 파티션을 재설정하여 처리
• 메모리 튜닝
- GC 옵션 튜닝
- Spark.cleaner.ttl 옵션을 이용하여 RDD 제거 시간 조정
Structured Streaming
Streaming Example
Reference : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-spark.html
A few challenges
• Consistency
• Fault tolerance
• Out-of-order data
What is Structured Streaming?
Structured Streaming Intro
• Basic concepts
Reference : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-spark.html
Structured Streaming Intro
• Programming Model for Structured Streaming
Reference : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-spark.html
Structured Streaming Intro
• Output
- Complete Mode
- Append Mode
- Update Mode
Structured Streaming Intro
• Output – Complete Mode
Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
Structured Streaming Intro
• Output – Append Mode
Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
Structured Streaming Intro
• Output – Update Mode
Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
How to use?
Spark SQL vs Structured Streaming
Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
Spark SQL vs Structured Streaming
Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
Example
• Structured Streaming을 이용한 Wordcount 예제 3가지
- Word count
- Word count with window operations
- Word count with watermarking
Example - Wordcount
Example – Wordcount with window operation
• Window Operations on Event Time
Example – Wordcount with window operation
Example – Wordcount with watermarking
• Handling Late Data and Watermarking
Example – Wordcount with watermarking
• Handling Late Data and Watermarking
Example – Wordcount with watermarking
• Handling Late Data and Watermarking
Example – Wordcount with watermarking
Comparison with Other Engines
Reference
• Structure streaming in apache spark : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-
spark.html
• Spark streaming, 권혁진 : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
• 빅데이터 분석을 위한 스파크2 프로그래밍, 백성민, 위키북스
• Learning Spark, Matei Zaharia, Holden Karau, Andy Konwinski, Patrick Wendell, O’Reilly Media
Questions?
Thank you

More Related Content

What's hot

NiFi Best Practices for the Enterprise
NiFi Best Practices for the EnterpriseNiFi Best Practices for the Enterprise
NiFi Best Practices for the EnterpriseGregory Keys
 
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
Apache Spark Streaming in K8s with ArgoCD & Spark OperatorApache Spark Streaming in K8s with ArgoCD & Spark Operator
Apache Spark Streaming in K8s with ArgoCD & Spark OperatorDatabricks
 
Massive service basic
Massive service basicMassive service basic
Massive service basicDaeMyung Kang
 
Best practices for highly available and large scale SolrCloud
Best practices for highly available and large scale SolrCloudBest practices for highly available and large scale SolrCloud
Best practices for highly available and large scale SolrCloudAnshum Gupta
 
Presto, Zeppelin을 이용한 초간단 BI 구축 사례
Presto, Zeppelin을 이용한 초간단 BI 구축 사례Presto, Zeppelin을 이용한 초간단 BI 구축 사례
Presto, Zeppelin을 이용한 초간단 BI 구축 사례Hyoungjun Kim
 
Airflow를 이용한 데이터 Workflow 관리
Airflow를 이용한  데이터 Workflow 관리Airflow를 이용한  데이터 Workflow 관리
Airflow를 이용한 데이터 Workflow 관리YoungHeon (Roy) Kim
 
Rancher Simple User Guide
Rancher Simple User GuideRancher Simple User Guide
Rancher Simple User GuideSANG WON PARK
 
Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes
 Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes
Spark Operator—Deploy, Manage and Monitor Spark clusters on KubernetesDatabricks
 
Apache Zeppelin으로 데이터 분석하기
Apache Zeppelin으로 데이터 분석하기Apache Zeppelin으로 데이터 분석하기
Apache Zeppelin으로 데이터 분석하기SangWoo Kim
 
Introduction to Open Telemetry as Observability Library
Introduction to Open  Telemetry as Observability LibraryIntroduction to Open  Telemetry as Observability Library
Introduction to Open Telemetry as Observability LibraryTonny Adhi Sabastian
 
쿠버네티스 ( Kubernetes ) 소개 자료
쿠버네티스 ( Kubernetes ) 소개 자료쿠버네티스 ( Kubernetes ) 소개 자료
쿠버네티스 ( Kubernetes ) 소개 자료Opennaru, inc.
 
Apache Spark on K8S Best Practice and Performance in the Cloud
Apache Spark on K8S Best Practice and Performance in the CloudApache Spark on K8S Best Practice and Performance in the Cloud
Apache Spark on K8S Best Practice and Performance in the CloudDatabricks
 
Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링JANGWONSEO4
 
Demystifying observability
Demystifying observability Demystifying observability
Demystifying observability Abigail Bangser
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkSergey Petrunya
 
Google Cloud Dataflow Two Worlds Become a Much Better One
Google Cloud Dataflow Two Worlds Become a Much Better OneGoogle Cloud Dataflow Two Worlds Become a Much Better One
Google Cloud Dataflow Two Worlds Become a Much Better OneDataWorks Summit
 
Distributed tracing using open tracing & jaeger 2
Distributed tracing using open tracing & jaeger 2Distributed tracing using open tracing & jaeger 2
Distributed tracing using open tracing & jaeger 2Chandresh Pancholi
 
Tracing Microservices with Zipkin
Tracing Microservices with ZipkinTracing Microservices with Zipkin
Tracing Microservices with Zipkintakezoe
 

What's hot (20)

NiFi Best Practices for the Enterprise
NiFi Best Practices for the EnterpriseNiFi Best Practices for the Enterprise
NiFi Best Practices for the Enterprise
 
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
Apache Spark Streaming in K8s with ArgoCD & Spark OperatorApache Spark Streaming in K8s with ArgoCD & Spark Operator
Apache Spark Streaming in K8s with ArgoCD & Spark Operator
 
Massive service basic
Massive service basicMassive service basic
Massive service basic
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Best practices for highly available and large scale SolrCloud
Best practices for highly available and large scale SolrCloudBest practices for highly available and large scale SolrCloud
Best practices for highly available and large scale SolrCloud
 
Presto, Zeppelin을 이용한 초간단 BI 구축 사례
Presto, Zeppelin을 이용한 초간단 BI 구축 사례Presto, Zeppelin을 이용한 초간단 BI 구축 사례
Presto, Zeppelin을 이용한 초간단 BI 구축 사례
 
Airflow를 이용한 데이터 Workflow 관리
Airflow를 이용한  데이터 Workflow 관리Airflow를 이용한  데이터 Workflow 관리
Airflow를 이용한 데이터 Workflow 관리
 
Rancher Simple User Guide
Rancher Simple User GuideRancher Simple User Guide
Rancher Simple User Guide
 
Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes
 Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes
Spark Operator—Deploy, Manage and Monitor Spark clusters on Kubernetes
 
The basics of fluentd
The basics of fluentdThe basics of fluentd
The basics of fluentd
 
Apache Zeppelin으로 데이터 분석하기
Apache Zeppelin으로 데이터 분석하기Apache Zeppelin으로 데이터 분석하기
Apache Zeppelin으로 데이터 분석하기
 
Introduction to Open Telemetry as Observability Library
Introduction to Open  Telemetry as Observability LibraryIntroduction to Open  Telemetry as Observability Library
Introduction to Open Telemetry as Observability Library
 
쿠버네티스 ( Kubernetes ) 소개 자료
쿠버네티스 ( Kubernetes ) 소개 자료쿠버네티스 ( Kubernetes ) 소개 자료
쿠버네티스 ( Kubernetes ) 소개 자료
 
Apache Spark on K8S Best Practice and Performance in the Cloud
Apache Spark on K8S Best Practice and Performance in the CloudApache Spark on K8S Best Practice and Performance in the Cloud
Apache Spark on K8S Best Practice and Performance in the Cloud
 
Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링Apache kafka 관리와 모니터링
Apache kafka 관리와 모니터링
 
Demystifying observability
Demystifying observability Demystifying observability
Demystifying observability
 
Lessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmarkLessons for the optimizer from running the TPC-DS benchmark
Lessons for the optimizer from running the TPC-DS benchmark
 
Google Cloud Dataflow Two Worlds Become a Much Better One
Google Cloud Dataflow Two Worlds Become a Much Better OneGoogle Cloud Dataflow Two Worlds Become a Much Better One
Google Cloud Dataflow Two Worlds Become a Much Better One
 
Distributed tracing using open tracing & jaeger 2
Distributed tracing using open tracing & jaeger 2Distributed tracing using open tracing & jaeger 2
Distributed tracing using open tracing & jaeger 2
 
Tracing Microservices with Zipkin
Tracing Microservices with ZipkinTracing Microservices with Zipkin
Tracing Microservices with Zipkin
 

Similar to Spark streaming tutorial

빅데이터 기술 현황과 시장 전망(2014)
빅데이터 기술 현황과 시장 전망(2014)빅데이터 기술 현황과 시장 전망(2014)
빅데이터 기술 현황과 시장 전망(2014)Channy Yun
 
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기AWSKRUG - AWS한국사용자모임
 
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWSMatthew (정재화)
 
스타트업사례로 본 로그 데이터분석 : Tajo on AWS
스타트업사례로 본 로그 데이터분석 : Tajo on AWS스타트업사례로 본 로그 데이터분석 : Tajo on AWS
스타트업사례로 본 로그 데이터분석 : Tajo on AWSGruter
 
100% Serverless big data scale production Deep Learning System
100% Serverless big data scale production Deep Learning System100% Serverless big data scale production Deep Learning System
100% Serverless big data scale production Deep Learning Systemhoondong kim
 
서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)수보 김
 
Private PaaS with Docker, spring cloud and mesos
Private PaaS with Docker, spring cloud and mesos Private PaaS with Docker, spring cloud and mesos
Private PaaS with Docker, spring cloud and mesos uEngine Solutions
 
지금 핫한 Real-time In-memory Stream Processing 이야기
지금 핫한 Real-time In-memory Stream Processing 이야기지금 핫한 Real-time In-memory Stream Processing 이야기
지금 핫한 Real-time In-memory Stream Processing 이야기Ted Won
 
Apache Htrace overview (20160520)
Apache Htrace overview (20160520)Apache Htrace overview (20160520)
Apache Htrace overview (20160520)Steve Min
 
Python & Spark
Python & SparkPython & Spark
Python & Sparkitproman35
 
Introduction to Apache Tajo
Introduction to Apache TajoIntroduction to Apache Tajo
Introduction to Apache TajoGruter
 
Machine Learning Model Serving with Backend.AI
Machine Learning Model Serving with Backend.AIMachine Learning Model Serving with Backend.AI
Machine Learning Model Serving with Backend.AIJeongkyu Shin
 
1711 azure-live
1711 azure-live1711 azure-live
1711 azure-live세준 김
 
JMI Techtalk : Backend.AI
JMI Techtalk : Backend.AIJMI Techtalk : Backend.AI
JMI Techtalk : Backend.AILablup Inc.
 
[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제
[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제
[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제NAVER D2
 
Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...
Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...
Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...hoondong kim
 
SQL-on-Hadoop with Apache Tajo, and application case of SK Telecom
SQL-on-Hadoop with Apache Tajo,  and application case of SK TelecomSQL-on-Hadoop with Apache Tajo,  and application case of SK Telecom
SQL-on-Hadoop with Apache Tajo, and application case of SK TelecomGruter
 
spark database Service
spark database Servicespark database Service
spark database Service창언 정
 
Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
Backend.AI: 오픈소스 머신러닝 인프라 프레임워크Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
Backend.AI: 오픈소스 머신러닝 인프라 프레임워크Jeongkyu Shin
 
[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축
[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축
[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축Juhong Park
 

Similar to Spark streaming tutorial (20)

빅데이터 기술 현황과 시장 전망(2014)
빅데이터 기술 현황과 시장 전망(2014)빅데이터 기술 현황과 시장 전망(2014)
빅데이터 기술 현황과 시장 전망(2014)
 
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
Spark + S3 + R3를 이용한 데이터 분석 시스템 만들기
 
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
스타트업 사례로 본 로그 데이터 분석 : Tajo on AWS
 
스타트업사례로 본 로그 데이터분석 : Tajo on AWS
스타트업사례로 본 로그 데이터분석 : Tajo on AWS스타트업사례로 본 로그 데이터분석 : Tajo on AWS
스타트업사례로 본 로그 데이터분석 : Tajo on AWS
 
100% Serverless big data scale production Deep Learning System
100% Serverless big data scale production Deep Learning System100% Serverless big data scale production Deep Learning System
100% Serverless big data scale production Deep Learning System
 
서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)서버학개론(백엔드 서버 개발자를 위한)
서버학개론(백엔드 서버 개발자를 위한)
 
Private PaaS with Docker, spring cloud and mesos
Private PaaS with Docker, spring cloud and mesos Private PaaS with Docker, spring cloud and mesos
Private PaaS with Docker, spring cloud and mesos
 
지금 핫한 Real-time In-memory Stream Processing 이야기
지금 핫한 Real-time In-memory Stream Processing 이야기지금 핫한 Real-time In-memory Stream Processing 이야기
지금 핫한 Real-time In-memory Stream Processing 이야기
 
Apache Htrace overview (20160520)
Apache Htrace overview (20160520)Apache Htrace overview (20160520)
Apache Htrace overview (20160520)
 
Python & Spark
Python & SparkPython & Spark
Python & Spark
 
Introduction to Apache Tajo
Introduction to Apache TajoIntroduction to Apache Tajo
Introduction to Apache Tajo
 
Machine Learning Model Serving with Backend.AI
Machine Learning Model Serving with Backend.AIMachine Learning Model Serving with Backend.AI
Machine Learning Model Serving with Backend.AI
 
1711 azure-live
1711 azure-live1711 azure-live
1711 azure-live
 
JMI Techtalk : Backend.AI
JMI Techtalk : Backend.AIJMI Techtalk : Backend.AI
JMI Techtalk : Backend.AI
 
[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제
[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제
[D2 COMMUNITY] Spark User Group - 스파크를 통한 딥러닝 이론과 실제
 
Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...
Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...
Auto Scalable 한 Deep Learning Production 을 위한 AI Serving Infra 구성 및 AI DevOps...
 
SQL-on-Hadoop with Apache Tajo, and application case of SK Telecom
SQL-on-Hadoop with Apache Tajo,  and application case of SK TelecomSQL-on-Hadoop with Apache Tajo,  and application case of SK Telecom
SQL-on-Hadoop with Apache Tajo, and application case of SK Telecom
 
spark database Service
spark database Servicespark database Service
spark database Service
 
Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
Backend.AI: 오픈소스 머신러닝 인프라 프레임워크Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
Backend.AI: 오픈소스 머신러닝 인프라 프레임워크
 
[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축
[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축
[NDC 2018] Spark, Flintrock, Airflow 로 구현하는 탄력적이고 유연한 데이터 분산처리 자동화 인프라 구축
 

Spark streaming tutorial

  • 3. Spark Intro • In-memory 기반 범용 클러스터 컴퓨팅 엔진 - 하둡 맵리듀스보다 100배 빠름(공홈에서 주장) • Unified Engine - batch/stream, SQL 및 Machine learning, Graph processing 제공 • 다양한 언어 지원 - Java, Scala, Python, R • 여러 클러스터 매니저를 지원하여 다양한 환경에서 구동 가능 - Standalone, YARN, mesos 등
  • 4. Spark Philosophy • Unified engine • High-level APIs • Integrate broadly
  • 6.
  • 7.
  • 8.
  • 9.
  • 12. Why Spark Streaming? 데이터를 실시간으로 바로 처리 하고 싶어요 “웹사이트를 모니터링할 수 없을까요?” “이거 추가되거나 삭제되면 바로 반영해주세요” “실시간 데이터로 머신러닝 모델을 학습시키고 싶어요” “문제를 바로 알고 싶어요” Website monitoring Fraud detection ML from streaming data
  • 13. Why Spark Streaming? • Integration with Batch Processing 같은 프레임워크에서 배치와 스트리밍을 같이 처리하고 싶어요 “배치는 MapReduce, 스트리밍은 Storm…” “유지 보수가 너무 어려워요 ㅠㅠ” “배치를 쉽게 스트리밍으로 바꿀수 없을까요?”
  • 14. Why Spark Streaming? • Integration with Batch Processing 같은 프레임워크에서 배치와 스트리밍을 같이 처리하고 싶어요 “배치는 MapReduce, 스트리밍은 Storm…” “유지 보수가 너무 어려워요 ㅠㅠ” “배치를 쉽게 스트리밍으로 바꿀수 없을까요?”
  • 15. What is spark streaming?
  • 16. What is Spark Streaming? • 배치를 작게해서 스트리밍처럼 돌리자 - 스트림 데이터를 시간 간격으로 분할 - 분할된 데이터를 대상으로 배치 수행 - 각 배치는 기존의 Spark job과 동일하게 처리 Spark Streaming live data stream batches of input data Spark Engine processed result RDD
  • 17. Streaming Context • Spark streaming을 사용하기 위해서 제일 먼저 생성하는 인스 턴스 - SparkContext, SparkSession과 비슷 • 어떤 주기로 배치 처리를 수행할지에 대한 정보를 함께 제공 • SparkConf나 SparkContext를 이용해 생성
  • 18. Programming Model - DStream • Discretized Stream(Dstream) - 끊임없이 생성되는 연속된 데이터를 나타내기 위한 데이터 모델 - 일정 시간마다 데이터를 모아서 RDD를 만들어줌 - RDD로 구성된 시퀀스 Reference : zero-to-streaming-spark-and-cassandra
  • 19. 그림과 함께 보는 예제 Spark Streaming live data stream batches of input data Spark Engine processed result
  • 20. 그림과 함께 보는 예제 Spark Streaming live data stream batches of input data Spark Engine processed result
  • 22. Example – Twitter 데이터와 놀아보기 • 살펴볼 예제 - 초당 생성되는 트윗 수 세어보기 - 최근 10초동안 생성되는 트윗 중 가장 많이 사용되는 단어수를 매 초마 다 확인하기 - 지금부터 유저별 트위터 작성 수 집계하기 예제 저장소 : https://github.com/eoriented/spark-streaming-tutorial
  • 23. 예제 저장소 • https://github.com/eoriented/spark-streaming-tutorial Star 버튼을 눌러주시 면 호랑이 기운이 솟아 나요!!
  • 24. Tutorial - 1 • 초당 생성되는 트윗 수 세기 - Twitter API Credential 발급 받기 • https://apps.twitter.com/ • 위 홈페이지에서 Twitter API를 사용할 수 있는 토큰들을 발급 받을 수 있음
  • 25. Tutorial - 1 • 초당 생성되는 트윗 수 세기
  • 26. Tutorial - 2 - 최근 10초동안 많이 사용되는 단어수를 매 초마다 확인하기 • 예제를 살펴 보기 전에 Window 개념 익히기
  • 27. Tutorial - 2 - 최근 10초동안 많이 사용되는 단어수를 매 초마다 확인하기 • 예제를 살펴 보기 전에 Window 개념 익히기
  • 28. Window-based Transformations • 이전에 수행된 배치의 결과를 반영해서 사용하는 경우 사용
  • 29. Tutorial - 2 - 최근 10초동안 사용되는 단어수를 매 초마다 확인하기
  • 30. Tutorial - 3 - 지금부터 생성되는 유저별 트위터 작성 수 집계하기
  • 31. Tutorial - 3 - 지금부터 생성되는 유저별 트위터 작성 수 집계하기 • 스트리밍에서는 매번 새로운 데이터를 대상으로 집계를 수행 • 이전에 처리했던 결과를 반영하기 위해서 stateful 방식의 집계를 제공
  • 32. Tutorial - 3 - 지금부터 생성되는 유저별 트위터 작성 수 집계하기
  • 34. Data source • 지원하는 데이터 소스 - Default data source • Socket • 파일 (HDFS 호환 파일 가능) • RDD Queue - Advanced data source (외부 연동 라이브러리) • Kafka • Flume • Kinesis • Twitter - Receiver를 직접 구현
  • 35. Data source • Custom Receiver - 만일 내가 원하는 Data source가 존재하지 않는다면? • Custom Receiver로 구현 - http://spark.apache.org/docs/latest/streaming-custom-receivers.html - onStart 메소드와 onStop 메소드를 구현
  • 37. Fault tolerance • Check Point - Metadata checkpoint • 드라이버의 장애 대응 - Data checkpoint • 최종 상태의 데이터를 빠르게 복구하기 위한 용도 - 파일 시스템 • HDFS, S3, local FS(test용) 등이 사용 가능
  • 38. 성능 고려사항 • 배치 / 윈도우 사이즈 - 500ms 가 적당 - 큰 배치로 시작하여 작은 사이즈로 낮춰가면서 배치 사이즈 결정 추천 • 병렬화 - 리시버 개수 늘리기 • 하나의 리시버가 받는게 아닌 여러 리시버가 받아서 처리하는게 효율적 - Repartitioning • 입력 스트림의 파티션을 재설정하여 처리 • 메모리 튜닝 - GC 옵션 튜닝 - Spark.cleaner.ttl 옵션을 이용하여 RDD 제거 시간 조정
  • 40. Streaming Example Reference : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-spark.html
  • 41. A few challenges • Consistency • Fault tolerance • Out-of-order data
  • 42. What is Structured Streaming?
  • 43. Structured Streaming Intro • Basic concepts Reference : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-spark.html
  • 44. Structured Streaming Intro • Programming Model for Structured Streaming Reference : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache-spark.html
  • 45. Structured Streaming Intro • Output - Complete Mode - Append Mode - Update Mode
  • 46. Structured Streaming Intro • Output – Complete Mode Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
  • 47. Structured Streaming Intro • Output – Append Mode Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
  • 48. Structured Streaming Intro • Output – Update Mode Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
  • 50. Spark SQL vs Structured Streaming Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
  • 51. Spark SQL vs Structured Streaming Reference : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1
  • 52. Example • Structured Streaming을 이용한 Wordcount 예제 3가지 - Word count - Word count with window operations - Word count with watermarking
  • 54. Example – Wordcount with window operation • Window Operations on Event Time
  • 55. Example – Wordcount with window operation
  • 56. Example – Wordcount with watermarking • Handling Late Data and Watermarking
  • 57. Example – Wordcount with watermarking • Handling Late Data and Watermarking
  • 58. Example – Wordcount with watermarking • Handling Late Data and Watermarking
  • 59. Example – Wordcount with watermarking
  • 61. Reference • Structure streaming in apache spark : https://databricks.com/blog/2016/07/28/structured-streaming-in-apache- spark.html • Spark streaming, 권혁진 : https://www.slideshare.net/SangbaeLim/spark-bootcamp2017inseoul-finalpt20170626distv1 • 빅데이터 분석을 위한 스파크2 프로그래밍, 백성민, 위키북스 • Learning Spark, Matei Zaharia, Holden Karau, Andy Konwinski, Patrick Wendell, O’Reilly Media

Editor's Notes

  1. 언어 선택은 자유지만 만약 어떤 언어도 상관하지 않는 경우에는 scala를 추천 - 자바보다 API가 간결하고, 파이썬 보다 더 좋은 성능을 낸다.(Spark는 scala로 만들어져 있고, 새로운 기능은 스칼라부터 적용)
  2. 왜 만듦?
  3. 왜 만들었냐?
  4. 무엇을 만들었을까?
  5. 무엇을 만들었나?
  6. 용어 익히기
  7. 빠르게 보는 Spark Streaming 어떻게 사용하는가
  8. 두번째 예제를 살펴 보기 전에 윈도우 사이즈와 슬라이드 인터벌의 경우 배치 크기의 배수로 지정
  9. 스트럭처 스트리밍은 간단하게 소개만 해드리겠음
  10. 기존 맵리듀스 패턴을 이용하여 스트리밍을 처리하는 방식의 예 - 사용자가 앱을 열때 open 이벤트를 보내고, 닫을 때 close 이벤트를 보내는 예제
  11. 사용자가 앱을 열때 open 이벤트를 보내고, 닫을 때 close 이벤트를 보내는 예제 Consistency open을 처리하는 reducer와 close를 담당하는 리듀서가 있을 때 open을 처리하는 리듀서가 close를 담당하는 리듀서보다 느린 경우 mysql에서는 open 보다 close가 더 많아질 수도 있어서 데이터의 일관성이 깨질 수 있음 Fault tolerance Mapper나 리듀서가 죽는 경우는? Out-of-order data 여러 출처의 데이터가 순서가 다른 경우 문제가 될 수 있음
  12. 입력 데이터의 스트림을 입력테이블로 간주해서 처리. 스트림에 도착하는 모든 데이터는 입력 테이블에 추가되는 새로운 row와 같이 처리
  13. 결과를 Result Table에 업데이트 한다. 결과 테이블이 업데이트 될때마다 변경된 결과와 행을 외부 싱크에 기록해야 함
  14. 아웃풋은 외부 스토리지에 쓰여지는 것으로 정의됨
  15. Result 테이블에 전부 업데이트를 하고 쓰여짐
  16. 결과를 Result Table에 업데이트 한다. 결과 테이블이 업데이트 될때마다 변경된 결과와 행을 외부 싱크에 기록해야 함
  17. 늦게 들어오는 데이터를 어떻게 처리할 것인가? 한참 후에(하루, 일주일) 들어오는 데이터를 처리하기 위해서 기존 데이터를 계속 유지할 수 없음 한참 지난 후에 도달하는 데이터를 적절히 처리하기 위한 방법으로 워터마크 도입 이벤트의 유효기간을 설정하여 처리하는 방식입니다.
  18. 해당 트리거가 발생하기 전에 인입된 모든 이벤트중에 가장 마지막에 발생된 이벤트 발생시각에서 미리 지정해둔 유효기간을 뺀 것으로 결정