SlideShare a Scribd company logo
1 of 12
TƯ DUY CACHING
TRONG LẬP TRÌNH WEB
NỘI DUNG
• Tư duy caching là gì?
• Ứng dụng của caching
• Vấn đề về caching
CACHE LÀ GÌ?
• Bộ nhớ đệm
• Cơ chế lưu trữ và truy cập tốc độ cao
 Tăng tốc xử lý
 Tăng tốc hệ thống
 Hệ thống đạt gần như “realtime”
TƯ DUY CACHING LÀ GÌ?
• Thay quá trình xử lý tốn thời gian bằng kết quả đã có
• Sử dụng bộ nhớ tốc độ cao hơn để tăng tốc hệ thống
ỨNG DỤNG 1: QUẢN LÝ TÀI NGUYÊN TĨNH
• Tải các tài nguyên mất thời gian
• Nội dung các tài nguyên ít thay đổi
 Tại sao không lưu lại để lần sau dùng?
 Caching tài nguyên vào vùng nhớ đệm của trình duyệt
ỨNG DỤNG 2: TÁI SỬ DỤNG KẾT QUẢ
• Một xử lý tốn thời gian: ∆𝒕
• Một request cần 𝑛 xử lý giống nhau
 Cần thời gian: 𝐧∆𝒕
• Nếu lưu lại kết quả cho lần sau
 Cần thời gian: ∆𝒕
ỨNG DỤNG 3: LIVE DATABASE
• Tốc độ bộ truy cập bộ nhớ:
L1 > L2 > L3 > RAM > HDD
• Database thường được lưu trên HDD
 Chậm
 Tại sao không lưu trên RAM hay trên Cache L3, L2, L1 ???
 Live Database
VẤN ĐỀ 1: TỈ LỆ CACHE HIT
𝒏 , 𝒎 : Số lần tìm thấy và không tìm thấy trong cache
𝑻 𝟏, 𝑻 𝟐: Thời gian thực hiện khi thấy và không thấy cache
 Thời gian trung bình:
𝑻 𝒕𝒃 =
𝒏𝑻 𝟏 + 𝒎𝑻 𝟐
𝒏 + 𝒎
=
𝒏
𝒏 + 𝒎
𝑻 𝟏 + 𝟏 −
𝒏
𝒏 + 𝒎
𝑻 𝟐
 Do 𝑻 𝟏 ≪ 𝑻 𝟐 nên để 𝑻 𝒕𝒃 ≪ 𝑻 𝟐 thì
𝜶 =
𝒏
𝒏 + 𝒎
≈ 𝟏
 Làm thế nào để dự đoán tỉ lệ cache hit?
VẤN ĐỀ 2: ĐỒNG BỘ DỮ LIỆU
• Làm thế nào để biết dữ liệu thay đổi?
• Cập nhật cache khi nào?
 Ngay sau khi dữ liệu thay đổi
 Khi cần đến dữ liệu
VẤN ĐỀ 3: DUNG LƯỢNG BỘ NHỚ
• Bộ nhớ HDD 1TG, RAM 32GB, L3 16MB, L2 2M, L1 512KB
• Truy cập là duyệt địa chỉ nhớ
 Dung lượng càng lớn thì chàng chậm
• Bộ nhớ có hạn, cái gì cũng muốn lưu, vậy phải làm sao?
 Xử lý cục bộ (lazy load, …)
 Chọn lọc và giải phóng dữ liệu
TỔNG KẾT
• Bạn đã hiểu tư duy caching là như thế nào?
• Ứng dụng khác của caching
• Vấn đề quan trọng nhất bây giờ với caching
THANKYOU !

More Related Content

Featured

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
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Featured (20)

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...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

[Rikkeisoft] Tư duy caching trong lập trình web

  • 1. TƯ DUY CACHING TRONG LẬP TRÌNH WEB
  • 2. NỘI DUNG • Tư duy caching là gì? • Ứng dụng của caching • Vấn đề về caching
  • 3. CACHE LÀ GÌ? • Bộ nhớ đệm • Cơ chế lưu trữ và truy cập tốc độ cao  Tăng tốc xử lý  Tăng tốc hệ thống  Hệ thống đạt gần như “realtime”
  • 4. TƯ DUY CACHING LÀ GÌ? • Thay quá trình xử lý tốn thời gian bằng kết quả đã có • Sử dụng bộ nhớ tốc độ cao hơn để tăng tốc hệ thống
  • 5. ỨNG DỤNG 1: QUẢN LÝ TÀI NGUYÊN TĨNH • Tải các tài nguyên mất thời gian • Nội dung các tài nguyên ít thay đổi  Tại sao không lưu lại để lần sau dùng?  Caching tài nguyên vào vùng nhớ đệm của trình duyệt
  • 6. ỨNG DỤNG 2: TÁI SỬ DỤNG KẾT QUẢ • Một xử lý tốn thời gian: ∆𝒕 • Một request cần 𝑛 xử lý giống nhau  Cần thời gian: 𝐧∆𝒕 • Nếu lưu lại kết quả cho lần sau  Cần thời gian: ∆𝒕
  • 7. ỨNG DỤNG 3: LIVE DATABASE • Tốc độ bộ truy cập bộ nhớ: L1 > L2 > L3 > RAM > HDD • Database thường được lưu trên HDD  Chậm  Tại sao không lưu trên RAM hay trên Cache L3, L2, L1 ???  Live Database
  • 8. VẤN ĐỀ 1: TỈ LỆ CACHE HIT 𝒏 , 𝒎 : Số lần tìm thấy và không tìm thấy trong cache 𝑻 𝟏, 𝑻 𝟐: Thời gian thực hiện khi thấy và không thấy cache  Thời gian trung bình: 𝑻 𝒕𝒃 = 𝒏𝑻 𝟏 + 𝒎𝑻 𝟐 𝒏 + 𝒎 = 𝒏 𝒏 + 𝒎 𝑻 𝟏 + 𝟏 − 𝒏 𝒏 + 𝒎 𝑻 𝟐  Do 𝑻 𝟏 ≪ 𝑻 𝟐 nên để 𝑻 𝒕𝒃 ≪ 𝑻 𝟐 thì 𝜶 = 𝒏 𝒏 + 𝒎 ≈ 𝟏  Làm thế nào để dự đoán tỉ lệ cache hit?
  • 9. VẤN ĐỀ 2: ĐỒNG BỘ DỮ LIỆU • Làm thế nào để biết dữ liệu thay đổi? • Cập nhật cache khi nào?  Ngay sau khi dữ liệu thay đổi  Khi cần đến dữ liệu
  • 10. VẤN ĐỀ 3: DUNG LƯỢNG BỘ NHỚ • Bộ nhớ HDD 1TG, RAM 32GB, L3 16MB, L2 2M, L1 512KB • Truy cập là duyệt địa chỉ nhớ  Dung lượng càng lớn thì chàng chậm • Bộ nhớ có hạn, cái gì cũng muốn lưu, vậy phải làm sao?  Xử lý cục bộ (lazy load, …)  Chọn lọc và giải phóng dữ liệu
  • 11. TỔNG KẾT • Bạn đã hiểu tư duy caching là như thế nào? • Ứng dụng khác của caching • Vấn đề quan trọng nhất bây giờ với caching