SlideShare una empresa de Scribd logo
1 de 15
Dữ liệu lớn và các bước tiếp cận:
Apache Spark
Ông Xuân Hồng
Nội dung
● Tổng quan hệ thống Big Data
● RDD cơ bản
● Data Frame cơ bản
● Demo
● Kinh nghiệm
● Tìm hiểu thêm
Tổng quan hệ thống Big Data
Message queue Processing Storage Management
● Amazon
Kinesis
● SQS
● Apache Kafka
● Apache
Spark
● Apache Storm
● Apache Flink
● Hadoop
● AWS S3,
Google
storage
● NoSQL
● Jenkins
● Git
● Docker
● Ansible
● Travis
● RDD: Resilient Distributed Dataset.
● Immutable: không thay đổi được, chỉ có thể tạo ra RDD mới.
● Lazy evaluated: tính toán để đó, chừng nào có Action mới thực thi.
● Distributed: phân tán trên các cluster/workers.
RDD cơ bản
RDD cơ bản
● Master/Driver
○ Chuyển program thành
các tasks cho các
workers.
○ Scheduling tasks để các
workers hoạt động đồng
bộ với nhau.
● n-Cluster/Executors
○ Hoàn thành các tasks và
trả kết quả về Driver.
○ Cache dữ liệu khi được
yêu cầu.
● SparkContext dùng để tạo
RDDs.
RDD cơ bản
Transformations Actions
● map()
● flatMap()
● filter()
● distinct()
● sample()
● collect()
● count()
● countByValue()
● take()
● top()
● takeOrdered()
Các thao tác transformations chỉ được thực thi khi lệnh Actions được gọi.
Ví dụ: hàm action collect() sẽ trigger hàm transformations map() thực hiện tính toán của
mình.
Data Frame cơ bản
● Kế thừa từ RDDs.
● Tối ưu hoá hiệu suất tính toán nhờ Spark-SQL Catalyst optimizer.
● Hỗ trợ thao tác ETL dễ dàng hơn nhờ SQL-like.
● Học tập từ Python/Pandas và R Dataframe mô phỏng dữ liệu dạng bảng.
Data Frame cơ bản
Data Frame cơ bản
Demo
Installation
● pip
● pip install virtualenv
● pip install pandas
● cd ~
● mkdir virtualenv
● cd virtualenv
● virtualenv topdevlibs
● source topdevlibs/bin/activate
● pip install jupyter
● brew install apache-spark
● create pyspark profile
○ export PATH=$PATH:/usr/local/Cellar/apache-spark/2.2.0/bin
○ export PYSPARK_DRIVER_PYTHON=jupyter
○ export PYSPARK_DRIVER_PYTHON_OPTS='notebook' pyspark
● pyspark
Demo
Demo
Notebooks
● RDD cơ bản
● Dataframe cơ bản
● More about Spark
● Nên dùng Notebook để dễ code và kiểm tra hiệu suất.
● Nên dùng Schema để load đúng định dạng dữ liệu.
● Binary (parquet, gzip) > Text (csv, json), File > Database.
● Tự tạo dữ liệu Big Data bằng Mockaroo.
● Nên sử dụng cache khi bảng dữ liệu được sử dụng nhiều lần tiếp đó.
● Nên xoá cache trước khi khởi tạo cache mới để tránh tràn bộ nhớ.
● Đối với bảng dữ liệu lớn nên lưu bảng tạm ra đĩa thay vì cache.
● Code SparkSQL sáng sủa hơn Dataframe built-in function.
● Upgrade lên version 2.0 khi có thể để tối ưu tính toán và quản lý bộ nhớ.
● Học thông qua:
○ Thực hành
○ Cheat sheet
○ Side project
Kinh nghiệm
Tìm hiểu thêm
● Thiết lập driver/workers với Zookeeper, Mesos, Marathon, Chronos.
● Configuration cho Spark
● Cách deploy bằng Docker.
● Databricks community.
● Load dữ liệu từ các source khác (MongoDB, MySQL, PostgreSQL,
S3, JDBC, Cassandra …)
● Làm việc với AWS S3, Google Cloud Storage.
● Python vs Scala vs R.
● Spark Dataframe vs Pandas Dataframe.
● Cache vs Persist.
● Cài notebook cho Spark Scala.
● Cấu hình hệ thống notebook cho từng yêu cầu hệ thống khác nhau
(spark-small, spark-medium, spark-large, spark-extra).

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Dữ liệu lớn và các bước tiếp cận: Apache Spark

  • 1. Dữ liệu lớn và các bước tiếp cận: Apache Spark Ông Xuân Hồng
  • 2. Nội dung ● Tổng quan hệ thống Big Data ● RDD cơ bản ● Data Frame cơ bản ● Demo ● Kinh nghiệm ● Tìm hiểu thêm
  • 3. Tổng quan hệ thống Big Data Message queue Processing Storage Management ● Amazon Kinesis ● SQS ● Apache Kafka ● Apache Spark ● Apache Storm ● Apache Flink ● Hadoop ● AWS S3, Google storage ● NoSQL ● Jenkins ● Git ● Docker ● Ansible ● Travis
  • 4. ● RDD: Resilient Distributed Dataset. ● Immutable: không thay đổi được, chỉ có thể tạo ra RDD mới. ● Lazy evaluated: tính toán để đó, chừng nào có Action mới thực thi. ● Distributed: phân tán trên các cluster/workers. RDD cơ bản
  • 5. RDD cơ bản ● Master/Driver ○ Chuyển program thành các tasks cho các workers. ○ Scheduling tasks để các workers hoạt động đồng bộ với nhau. ● n-Cluster/Executors ○ Hoàn thành các tasks và trả kết quả về Driver. ○ Cache dữ liệu khi được yêu cầu. ● SparkContext dùng để tạo RDDs.
  • 6.
  • 7. RDD cơ bản Transformations Actions ● map() ● flatMap() ● filter() ● distinct() ● sample() ● collect() ● count() ● countByValue() ● take() ● top() ● takeOrdered() Các thao tác transformations chỉ được thực thi khi lệnh Actions được gọi. Ví dụ: hàm action collect() sẽ trigger hàm transformations map() thực hiện tính toán của mình.
  • 8. Data Frame cơ bản ● Kế thừa từ RDDs. ● Tối ưu hoá hiệu suất tính toán nhờ Spark-SQL Catalyst optimizer. ● Hỗ trợ thao tác ETL dễ dàng hơn nhờ SQL-like. ● Học tập từ Python/Pandas và R Dataframe mô phỏng dữ liệu dạng bảng.
  • 10. Data Frame cơ bản
  • 11. Demo Installation ● pip ● pip install virtualenv ● pip install pandas ● cd ~ ● mkdir virtualenv ● cd virtualenv ● virtualenv topdevlibs ● source topdevlibs/bin/activate ● pip install jupyter ● brew install apache-spark ● create pyspark profile ○ export PATH=$PATH:/usr/local/Cellar/apache-spark/2.2.0/bin ○ export PYSPARK_DRIVER_PYTHON=jupyter ○ export PYSPARK_DRIVER_PYTHON_OPTS='notebook' pyspark ● pyspark
  • 12. Demo
  • 13. Demo Notebooks ● RDD cơ bản ● Dataframe cơ bản ● More about Spark
  • 14. ● Nên dùng Notebook để dễ code và kiểm tra hiệu suất. ● Nên dùng Schema để load đúng định dạng dữ liệu. ● Binary (parquet, gzip) > Text (csv, json), File > Database. ● Tự tạo dữ liệu Big Data bằng Mockaroo. ● Nên sử dụng cache khi bảng dữ liệu được sử dụng nhiều lần tiếp đó. ● Nên xoá cache trước khi khởi tạo cache mới để tránh tràn bộ nhớ. ● Đối với bảng dữ liệu lớn nên lưu bảng tạm ra đĩa thay vì cache. ● Code SparkSQL sáng sủa hơn Dataframe built-in function. ● Upgrade lên version 2.0 khi có thể để tối ưu tính toán và quản lý bộ nhớ. ● Học thông qua: ○ Thực hành ○ Cheat sheet ○ Side project Kinh nghiệm
  • 15. Tìm hiểu thêm ● Thiết lập driver/workers với Zookeeper, Mesos, Marathon, Chronos. ● Configuration cho Spark ● Cách deploy bằng Docker. ● Databricks community. ● Load dữ liệu từ các source khác (MongoDB, MySQL, PostgreSQL, S3, JDBC, Cassandra …) ● Làm việc với AWS S3, Google Cloud Storage. ● Python vs Scala vs R. ● Spark Dataframe vs Pandas Dataframe. ● Cache vs Persist. ● Cài notebook cho Spark Scala. ● Cấu hình hệ thống notebook cho từng yêu cầu hệ thống khác nhau (spark-small, spark-medium, spark-large, spark-extra).